summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts
diff options
context:
space:
mode:
authorimamSidero <imam.hussain@est.tech>2022-12-21 17:51:43 +0000
committerimamSidero <imam.hussain@est.tech>2023-01-03 15:03:15 +0000
commitdb3e2ef238fa29e06cec3cb3f5b11fb407b161ce (patch)
tree1dbca1372aa87c881a4ed93a8788e3eff0d38e9d /catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts
parent5b1a92cea1fb437c236a77468f3e8e351e25a990 (diff)
Provide tosca function to custom datatypes of list and map
Providing the capability to add tosca function as the custom datatypes of list and map Issue-ID: SDC-4311 Signed-off-by: Imam hussain <imam.hussain@est.tech> Change-Id: I7ec8943d8008440b091fc4eaa2aba49cdadcda8d
Diffstat (limited to 'catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts')
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts52
1 files changed, 37 insertions, 15 deletions
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 2bf1b1076b..a3477792cf 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
@@ -46,7 +46,7 @@ import {ComponentServiceNg2} from "../../services/component-services/component.s
import {TopologyTemplateService} from "../../services/component-services/topology-template.service";
import {ComponentInstanceServiceNg2} from "../../services/component-instance-services/component-instance.service"
import {KeysPipe} from 'app/ng2/pipes/keys.pipe';
-import {EVENTS, PROPERTY_TYPES, WorkspaceMode} from "../../../utils/constants";
+import {EVENTS, PROPERTY_TYPES, WorkspaceMode, PROPERTY_DATA} from "../../../utils/constants";
import {EventListenerService} from "app/services/event-listener-service"
import {HierarchyDisplayOptions} from "../../components/logic/hierarchy-navigtion/hierarchy-display-options";
import {FilterPropertiesAssignmentComponent} from "../../components/logic/filter-properties-assignment/filter-properties-assignment.component";
@@ -587,21 +587,29 @@ export class PropertiesAssignmentComponent {
if (checkedInstanceProperty instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel>checkedInstanceProperty).propertiesName){
const propertiesNameArray = (<PropertyDeclareAPIModel>checkedInstanceProperty).propertiesName;
const parts = propertiesNameArray.split("#");
- const currentKey = (checkedInstanceProperty.type == PROPERTY_TYPES.MAP || checkedInstanceProperty.type == PROPERTY_TYPES.LIST) ? (<DerivedFEProperty>checkedInstanceProperty.input).mapKey : null;
+ let currentKey = [];
+ if (this.isListOrMap(checkedInstanceProperty.type)) {
+ currentKey.push((<DerivedFEProperty>checkedInstanceProperty.input).mapKey);
+ if (this.isComplexSchemaType(checkedInstanceProperty.schemaType)) {
+ currentKey.push(parts.reverse()[0]);
+ }
+ }
if (propertiesNameArray.length > 1){
- const index = checkedInstanceProperty.subPropertyToscaFunctions.findIndex(existingSubPropertyToscaFunction => this.areEqual(existingSubPropertyToscaFunction.subPropertyPath, currentKey != null ? [currentKey] : parts.slice(1)));
+ const index = checkedInstanceProperty.subPropertyToscaFunctions.findIndex(existingSubPropertyToscaFunction => this.areEqual(existingSubPropertyToscaFunction.subPropertyPath, currentKey.length > 0 ? currentKey : parts.slice(1)));
checkedInstanceProperty.subPropertyToscaFunctions.splice(index, 1);
}
- if(currentValue !== null && currentKey !== null){
+ if(currentValue !== null && currentKey.length > 0){
let valueJson = JSON.parse(currentValue);
- let tempValue = valueJson[currentKey];
- delete valueJson[currentKey];
- if (checkedInstanceProperty.type == PROPERTY_TYPES.LIST) {
- let listValue = [];
- valueJson.forEach(item => {
- if (item != null && item != '' && item != tempValue) {
- listValue.push(item);
- }
+ if(currentKey.length >1){
+ let innerObj = valueJson[currentKey[0]];
+ delete innerObj[currentKey[1]];
+ valueJson[currentKey[0]] = innerObj;
+ }else{
+ delete valueJson[currentKey[0]];
+ }
+ if (checkedInstanceProperty.type == PROPERTY_TYPES.LIST && currentKey.length == 1) {
+ let listValue = valueJson.filter(function (item) {
+ return item != null && item != '';
});
checkedInstanceProperty.value = JSON.stringify(listValue);
} else {
@@ -623,17 +631,23 @@ export class PropertiesAssignmentComponent {
if (checkedProperty instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel>checkedProperty).propertiesName){
const propertiesName = (<PropertyDeclareAPIModel>checkedProperty).propertiesName;
const parts = propertiesName.split("#");
- const currentKey = (checkedProperty.type == PROPERTY_TYPES.MAP || checkedProperty.type == PROPERTY_TYPES.LIST) ? (<DerivedFEProperty>checkedProperty.input).mapKey : null;
+ let currentKey = [];
+ if (this.isListOrMap(checkedProperty.type)) {
+ currentKey.push((<DerivedFEProperty>checkedProperty.input).mapKey);
+ if (this.isComplexSchemaType(checkedProperty.schemaType)) {
+ currentKey.push(parts.reverse()[0]);
+ }
+ }
if (checkedProperty.subPropertyToscaFunctions == null){
checkedProperty.subPropertyToscaFunctions = [];
}
- let subPropertyToscaFunction = checkedProperty.subPropertyToscaFunctions.find(existingSubPropertyToscaFunction => this.areEqual(existingSubPropertyToscaFunction.subPropertyPath, currentKey != null ? [currentKey] : parts.slice(1)));
+ let subPropertyToscaFunction = checkedProperty.subPropertyToscaFunctions.find(existingSubPropertyToscaFunction => this.areEqual(existingSubPropertyToscaFunction.subPropertyPath, currentKey.length > 0 ? currentKey : parts.slice(1)));
if (!subPropertyToscaFunction){
subPropertyToscaFunction = new SubPropertyToscaFunction();
checkedProperty.subPropertyToscaFunctions.push(subPropertyToscaFunction);
}
subPropertyToscaFunction.toscaFunction = toscaFunction;
- subPropertyToscaFunction.subPropertyPath = currentKey != null ? [currentKey] : parts.slice(1);
+ subPropertyToscaFunction.subPropertyPath = currentKey.length > 0 ? currentKey : parts.slice(1);
} else {
checkedProperty.subPropertyToscaFunctions = null;
@@ -648,6 +662,14 @@ export class PropertiesAssignmentComponent {
}
}
+ private isComplexSchemaType(propertyType: string): boolean {
+ return PROPERTY_DATA.SIMPLE_TYPES.indexOf(propertyType) === -1;
+ }
+
+ private isListOrMap(propertyType: string): boolean {
+ return PROPERTY_TYPES.MAP === propertyType || PROPERTY_TYPES.LIST === propertyType;
+ }
+
private areEqual(array1: string[], array2: string[]): boolean {
return array1.length === array2.length && array1.every(function(value, index) { return value === array2[index]})
}