From 2c30bf8b461108e687d874acad3b444fc732ef4c Mon Sep 17 00:00:00 2001 From: imamSidero Date: Wed, 8 Feb 2023 14:40:35 +0000 Subject: Provide tosca function to list of map values Providing the capability to add tosca function for list of map values Issue-ID: SDC-4379 Signed-off-by: Imam hussain Change-Id: Iec404ec27431eb2b5e085d3f9474e61fadab8d45 --- .../dynamic-property.component.html | 2 +- .../dynamic-property/dynamic-property.component.ts | 52 +++++++++++++++------- .../properties-assignment.page.component.ts | 10 ++++- .../tosca-function/tosca-function.component.ts | 5 ++- .../tosca-get-function.component.ts | 7 ++- 5 files changed, 55 insertions(+), 21 deletions(-) (limited to 'catalog-ui/src/app/ng2') diff --git a/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.html b/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.html index a5c2b60ee3..e19986416f 100644 --- a/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.html +++ b/catalog-ui/src/app/ng2/components/logic/properties-table/dynamic-property/dynamic-property.component.html @@ -44,7 +44,7 @@
- + { let mapKeyValue = this.property instanceof DerivedFEProperty ? this.property.mapKey : ""; + let parentToscaFunction = null; if (this.property.type == PROPERTY_TYPES.LIST && mapKeyValue === "") { - if (this.property.schemaType != PROPERTY_TYPES.MAP) { - if (this.property.value != null) { - const valueJson = JSON.parse(this.property.value); - if (this.property instanceof PropertyFEModel && this.property.expandedChildPropertyId != null) { - let indexNumber = Number(Object.keys(valueJson).sort().reverse()[0]) + 1; - mapKeyValue = indexNumber.toString(); - }else{ - mapKeyValue = Object.keys(valueJson).sort().reverse()[0]; - } - }else { - mapKeyValue = "0"; + if (this.property.value != null) { + const valueJson = JSON.parse(this.property.value); + if (this.property instanceof PropertyFEModel && this.property.expandedChildPropertyId != null) { + let indexNumber = Number(Object.keys(valueJson).sort().reverse()[0]) + 1; + mapKeyValue = indexNumber.toString(); + }else{ + mapKeyValue = Object.keys(valueJson).sort().reverse()[0]; } + }else { + mapKeyValue = "0"; } } + if (this.property.type == PROPERTY_TYPES.MAP && this.property instanceof DerivedFEProperty && this.property.mapInlist) { + parentToscaFunction = this.property.toscaFunction; + this.property.toscaFunction = null; + } let newProps: Array = this.propertiesUtils.createListOrMapChildren(this.property, mapKeyValue, null); this.propertiesUtils.assignFlattenedChildrenValues(this.property.valueObj, [newProps[0]], this.property.propertiesName); @@ -177,6 +180,7 @@ export class DynamicPropertyComponent { } else { this.addChildPropsToParent.emit(newProps); } + this.property.toscaFunction = parentToscaFunction; } addChildProps = (newProps: Array, childPropName: string) => { @@ -221,9 +225,20 @@ export class DynamicPropertyComponent { deleteListOrMapItem = (item: DerivedFEProperty) => { if (this.property instanceof PropertyFEModel) { + const childMapKey = item.mapKey; this.removeValueFromParent(item); this.property.flattenedChildren.splice(this.property.getIndexOfChild(item.propertiesName), this.property.getCountOfChildren(item.propertiesName)); this.expandChildById(item.propertiesName); + if (this.property.type == PROPERTY_TYPES.LIST && this.property.schemaType == PROPERTY_TYPES.MAP && childMapKey != null) { + let valueObject = JSON.parse(this.property.value); + let innerObject = valueObject[item.parentMapKey]; + delete innerObject[childMapKey]; + this.property.valueObj = valueObject; + this.property.value = JSON.stringify(valueObject); + this.property.flattenedChildren[0].valueObj = valueObject; + this.property.flattenedChildren[0].value = JSON.stringify(valueObject); + this.property.flattenedChildren[0].valueObjIsChanged = true; + } } } @@ -234,12 +249,19 @@ export class DynamicPropertyComponent { if (!itemParent) { return; } - const oldKey = item.getActualMapKey(); + let oldKey = item.getActualMapKey(); + let keyIndex : number = 0; + if(item.parentMapKey != null && oldKey != null) { + keyIndex = 1; + } + if(item.parentMapKey != null && oldKey == null) { + oldKey = item.parentMapKey; + } if (this.property.subPropertyToscaFunctions !== null) { let tempSubToscaFunction: SubPropertyToscaFunction[] = []; - this.property.subPropertyToscaFunctions.forEach((item : SubPropertyToscaFunction, index) => { - if(item.subPropertyPath[0] != oldKey){ - tempSubToscaFunction.push(item); + this.property.subPropertyToscaFunctions.forEach((subToscaItem : SubPropertyToscaFunction) => { + if(subToscaItem.subPropertyPath[keyIndex] != oldKey){ + tempSubToscaFunction.push(subToscaItem); } }); this.property.subPropertyToscaFunctions = tempSubToscaFunction; diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts index e66de41f09..7fef3532a3 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts @@ -592,8 +592,11 @@ export class PropertiesAssignmentComponent { const parts = propertiesNameArray.split("#"); let currentKey = []; if (this.isListOrMap(checkedInstanceProperty.type)) { + if (checkedInstanceProperty.schemaType == PROPERTY_TYPES.MAP) { + currentKey.push((checkedInstanceProperty.input).parentMapKey); + } currentKey.push((checkedInstanceProperty.input).mapKey); - if (this.isComplexSchemaType(checkedInstanceProperty.schemaType)) { + if (checkedInstanceProperty.schemaType != PROPERTY_TYPES.MAP && this.isComplexSchemaType(checkedInstanceProperty.schemaType)) { currentKey.push(parts.reverse()[0]); } } @@ -636,8 +639,11 @@ export class PropertiesAssignmentComponent { const parts = propertiesName.split("#"); let currentKey = []; if (this.isListOrMap(checkedProperty.type)) { + if (checkedProperty.schemaType == PROPERTY_TYPES.MAP) { + currentKey.push((checkedProperty.input).parentMapKey); + } currentKey.push((checkedProperty.input).mapKey); - if (this.isComplexSchemaType(checkedProperty.schemaType)) { + if (checkedProperty.schemaType != PROPERTY_TYPES.MAP && this.isComplexSchemaType(checkedProperty.schemaType)) { currentKey.push(parts.reverse()[0]); } } diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts index f697eed027..9ea0c8f214 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts @@ -116,8 +116,11 @@ export class ToscaFunctionComponent implements OnInit, OnChanges { if (propertiesPath.length > 1){ let keyToFind = []; if (this.property.type == PROPERTY_TYPES.MAP || this.property.type == PROPERTY_TYPES.LIST) { + if (this.property.type == PROPERTY_TYPES.LIST && this.property.schemaType == PROPERTY_TYPES.MAP) { + keyToFind.push((this.property.input).parentMapKey); + } keyToFind.push((this.property.input).mapKey); - if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.property.schemaType) === -1) { + if (this.property.schemaType != PROPERTY_TYPES.MAP && PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.property.schemaType) === -1) { keyToFind.push(propertiesPath.reverse()[0]); } } diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts index 9fdc8c19aa..b0146cc1cf 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts @@ -267,7 +267,8 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges { if ((this.typeHasSchema(this.property.type) && this.property instanceof PropertyDeclareAPIModel && ( this.property).input instanceof DerivedFEProperty) || this.compositionMap) { if(this.isComplexType(this.property.schemaType) && !this.compositionMap){ - return ( this.property).input.type; + let propertySchemaType = ( this.property).input.type; + return propertySchemaType == PROPERTY_TYPES.MAP ? PROPERTY_TYPES.STRING : propertySchemaType; }else{ return this.property.schema.property.type; } @@ -379,7 +380,9 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges { if (this.typeHasSchema(this.property.type)) { if ((this.property instanceof PropertyDeclareAPIModel && ( this.property).input instanceof DerivedFEProperty) || this.compositionMap) { if(this.isComplexType(this.property.schemaType) && !this.compositionMap){ - return property.type === ( this.property).input.type; + let propertySchemaType = ( this.property).input.type; + propertySchemaType = propertySchemaType == PROPERTY_TYPES.MAP ? PROPERTY_TYPES.STRING : propertySchemaType; + return property.type === propertySchemaType; }else{ return property.type === this.property.schema.property.type; } -- cgit 1.2.3-korg