From 4d97d5fac309ce0d66938e5ccd0349e2660d4e23 Mon Sep 17 00:00:00 2001 From: Michael Lando Date: Sat, 17 Jun 2017 22:40:44 +0300 Subject: [sdc] update code of sdc Change-Id: If9f37c80b659cb67b34d18e6c019defecca58b9a Signed-off-by: Michael Lando --- .../properties-inputs/derived-fe-property.ts | 1 + .../models/properties-inputs/property-fe-model.ts | 29 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'catalog-ui/src/app/models') diff --git a/catalog-ui/src/app/models/properties-inputs/derived-fe-property.ts b/catalog-ui/src/app/models/properties-inputs/derived-fe-property.ts index f7117e456c..2178319e0b 100644 --- a/catalog-ui/src/app/models/properties-inputs/derived-fe-property.ts +++ b/catalog-ui/src/app/models/properties-inputs/derived-fe-property.ts @@ -12,6 +12,7 @@ export class DerivedFEProperty extends PropertyBEModel { isDeclared: boolean; isSelected: boolean; isDisabled: boolean; + hidden: boolean; isChildOfListOrMap: boolean; canBeDeclared: boolean; mapKey: string; diff --git a/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts b/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts index 564611c344..cfbe6d64c7 100644 --- a/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts +++ b/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts @@ -78,4 +78,33 @@ export class PropertyFEModel extends PropertyBEModel { // this.flattenedChildren.filter(prop => prop.parentName == item.parentName).map(prop => prop.propertiesName).indexOf(item.propertiesName) // } + /* Updates parent valueObj when a child prop's value has changed */ + public childPropUpdated = (childProp: DerivedFEProperty): void => { + let parentNames = this.getParentNamesArray(childProp.propertiesName, []); + if (parentNames.length) { + _.set(this.valueObj, parentNames.join('.'), childProp.valueObj); + } + }; + + /* Returns array of individual parents for given prop path, with list/map UUIDs replaced with index/mapkey */ + private getParentNamesArray = (parentPropName: string, parentNames?: Array): Array => { + if (parentPropName.indexOf("#") == -1) { return parentNames; } //finished recursing parents. return + + let parentProp: DerivedFEProperty = this.flattenedChildren.find(prop => prop.propertiesName === parentPropName); + let nameToInsert: string = parentProp.name; + + if (parentProp.isChildOfListOrMap) { + if (parentProp.derivedDataType == DerivedPropertyType.MAP) { + nameToInsert = parentProp.mapKey; + } else { //LIST + let siblingProps = this.flattenedChildren.filter(prop => prop.parentName == parentProp.parentName).map(prop => prop.propertiesName); + nameToInsert = siblingProps.indexOf(parentProp.propertiesName).toString(); + } + } + + parentNames.splice(0, 0, nameToInsert); //add prop name to array + return this.getParentNamesArray(parentProp.parentName, parentNames); //continue recursing + } + + } -- cgit 1.2.3-korg