diff options
author | MichaelMorris <michael.morris@est.tech> | 2020-11-27 17:26:46 +0000 |
---|---|---|
committer | Vasyl Razinkov <vasyl.razinkov@est.tech> | 2020-12-15 14:24:59 +0000 |
commit | 08fee6aa89ec2a0fd021c969af78ba422f86949f (patch) | |
tree | ffdb1001016bde3fdf265ad95db8f2ea21a564da /catalog-ui/src/app/models/properties-inputs/input-fe-model.ts | |
parent | 3f816f6fdeb32061c77ab9799e18f2cb41ce8ea7 (diff) |
Add metadata to topology inputs1.8.0
Change-Id: If57e16003532d59552fa0b5cacc69a792e5b877a
Issue-ID: SDC-3399
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Diffstat (limited to 'catalog-ui/src/app/models/properties-inputs/input-fe-model.ts')
-rw-r--r-- | catalog-ui/src/app/models/properties-inputs/input-fe-model.ts | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts b/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts index 85c514bcbc..909f712a4e 100644 --- a/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts +++ b/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts @@ -24,6 +24,8 @@ import {PropertyFEModel} from "../../models"; import {PROPERTY_DATA} from "../../utils/constants"; import {InputBEModel} from "./input-be-model"; import {DerivedPropertyType} from "./property-be-model"; +import { Metadata } from "app/models/metadata"; +import { MetadataEntry } from "app/models/metadataEntry"; export class InputFEModel extends InputBEModel { isSimpleType: boolean; @@ -35,6 +37,10 @@ export class InputFEModel extends InputBEModel { defaultValueObjIsChanged:boolean; derivedDataType: DerivedPropertyType; requiredOrig: boolean; + metadataOrig: Metadata; + metadataIsValid:boolean; + metadataEntries: MetadataEntry[] = []; + metadataMapKeyError: string; constructor(input?: InputBEModel) { super(input); @@ -50,6 +56,14 @@ export class InputFEModel extends InputBEModel { this.updateDefaultValueObjOrig(); this.requiredOrig = this.required; + this.metadataOrig = _.cloneDeep(input.metadata); + this.metadataIsValid = true; + + if (input.metadata){ + for (let key of Object.keys(input.metadata)){ + this.metadataEntries.push(new MetadataEntry(key, input.metadata[key])); + } + } } } @@ -84,7 +98,66 @@ export class InputFEModel extends InputBEModel { return this.required !== this.requiredOrig; } + public updateMetadataKey(metadataEntry: MetadataEntry, newKey){ + if (!newKey){ + this.metadataIsValid = false; + this.metadataMapKeyError = 'Key cannot be empty.'; + metadataEntry.key = newKey; + return; + } else if (metadataEntry.metaDataMapKey != newKey && this.metadata[newKey]){ + this.metadataIsValid = false; + this.metadataMapKeyError = 'This key already exists!!.'; + metadataEntry.key = newKey; + return; + } + this.metadataIsValid = true; + this.metadataMapKeyError = null; + + if(metadataEntry.metaDataMapKey != newKey){ + this.metadata[newKey] = _.cloneDeep(this.metadata[metadataEntry.metaDataMapKey]); + delete this.metadata[metadataEntry.metaDataMapKey]; + metadataEntry.metaDataMapKey = newKey; + } + metadataEntry.key = newKey; + } + + public updateMetadataValue(metadataEntry: MetadataEntry, value: string){ + metadataEntry.value = value; + this.metadata[metadataEntry.key] = value; + } + + public addMetadataEntry(metadataEntry: MetadataEntry){ + this.metadataEntries.push(metadataEntry); + if (!this.metadata){ + this.metadata = new Metadata; + } + this.metadata[metadataEntry.key] = metadataEntry.value; + } + + public deleteMetadataEntry(metadataEntry: MetadataEntry){ + let metadataEntryIndex = this.metadataEntries.findIndex(item => item.key === metadataEntry.key); + if (metadataEntryIndex != -1){ + this.metadataEntries.splice(metadataEntryIndex, 1); + } + delete this.metadata[metadataEntry.key]; + } + + public resetMetadata = (): void => { + this.metadata = _.cloneDeep(this.metadataOrig); + this.metadataIsValid = true; + + this.metadataEntries = []; + for (let key of Object.keys(this.metadata)){ + this.metadataEntries.push(new MetadataEntry(key, this.metadata[key])); + } + } + + hasMetadataChanged(): boolean { + return !_.isEqual(this.metadata, this.metadataOrig); + } + hasChanged(): boolean { - return this.hasDefaultValueChanged() || this.hasRequiredChanged(); + return this.hasDefaultValueChanged() || this.hasRequiredChanged() || this.hasMetadataChanged(); } + }
\ No newline at end of file |