Support a custom yaml value in tosca function
[sdc.git] / catalog-ui / src / app / ng2 / pages / properties-assignment / services / properties.utils.ts
index 011be41..8e9be8b 100644 (file)
@@ -38,21 +38,26 @@ export class PropertiesUtils {
      * 3. Initialize valueObj (which also creates any new list/map flattened children as needed)
      * Returns InstanceFePropertiesMap
      */
-    public convertPropertiesMapToFEAndCreateChildren = (instancePropertiesMap:InstanceBePropertiesMap, isVF:boolean, inputs?:Array<InputFEModel>): InstanceFePropertiesMap => {
+    public convertPropertiesMapToFEAndCreateChildren = (instancePropertiesMap:InstanceBePropertiesMap, isVF:boolean, inputs?:Array<InputFEModel>, model?:string): InstanceFePropertiesMap => {
         let instanceFePropertiesMap:InstanceFePropertiesMap = new InstanceFePropertiesMap();
         angular.forEach(instancePropertiesMap, (properties:Array<PropertyBEModel>, instanceId:string) => {
             let propertyFeArray: Array<PropertyFEModel> = [];
             _.forEach(properties, (property: PropertyBEModel) => {
-
-                if (this.dataTypeService.getDataTypeByTypeName(property.type)) { // if type not exist in data types remove property from list
+       
+                if (this.dataTypeService.getDataTypeByModelAndTypeName(model, property.type)) { // if type not exist in data types remove property from list
 
                     let newFEProp: PropertyFEModel = new PropertyFEModel(property); //Convert property to FE
-
-                    this.initValueObjectRef(newFEProp); //initialize valueObj.
+                    if (!newFEProp.parentUniqueId) {
+                        newFEProp.parentUniqueId = instanceId;
+                    }
+                    this.initValueObjectRef(newFEProp); //initialize valueObj AND creates flattened children
                     propertyFeArray.push(newFEProp);
                     newFEProp.updateExpandedChildPropertyId(newFEProp.name); //display only the first level of children
                     this.dataTypeService.checkForCustomBehavior(newFEProp);
 
+                    if (newFEProp.isToscaFunction()) {
+                        return;
+                    }
                     //if this prop (or any children) are declared, set isDeclared and disable checkbox on parents/children
                     if (newFEProp.getInputValues && newFEProp.getInputValues.length) {
                         newFEProp.getInputValues.forEach(propInputDetail => {
@@ -79,8 +84,8 @@ export class PropertiesUtils {
         return instanceFePropertiesMap;
     }
 
-    public convertAddPropertyBAToPropertyFE = (property: PropertyBEModel):PropertyFEModel => {
-        let newFEProp: PropertyFEModel = new PropertyFEModel(property); //Convert property to FE
+    public convertAddPropertyBAToPropertyFE = (property: PropertyBEModel): PropertyFEModel => {
+        const newFEProp: PropertyFEModel = new PropertyFEModel(property); //Convert property to FE
         this.initValueObjectRef(newFEProp);
         newFEProp.updateExpandedChildPropertyId(newFEProp.name); //display only the first level of children
         this.dataTypeService.checkForCustomBehavior(newFEProp);
@@ -108,7 +113,7 @@ export class PropertiesUtils {
         let tempProps: Array<DerivedFEProperty> = [];
         let dataTypeObj: DataTypeModel = this.dataTypeService.getDataTypeByTypeName(type);
         this.dataTypeService.getDerivedDataTypeProperties(dataTypeObj, tempProps, parentName);
-        return tempProps;
+        return _.sortBy(tempProps, ['propertiesName']);
     }
 
     /* Sets the valueObj of parent property and its children.
@@ -126,7 +131,14 @@ export class PropertiesUtils {
             if (property.derivedDataType == DerivedPropertyType.LIST || property.derivedDataType == DerivedPropertyType.MAP) {
                 property.flattenedChildren = [];
                 Object.keys(property.valueObj).forEach((key) => {
-                    property.flattenedChildren.push(...this.createListOrMapChildren(property, key, property.valueObj[key]))
+                    property.flattenedChildren.push(...this.createListOrMapChildren(property, key, property.valueObj[key]));
+                    const lastCreatedChild = property.flattenedChildren.slice(-1)[0];
+                    if (property.schemaType == PROPERTY_TYPES.MAP && property.valueObj[key]){
+                        const nestedValue:object = property.valueObj[key];
+                        Object.keys(nestedValue).forEach((keyNested) => {
+                            property.flattenedChildren.push(...this.createListOrMapChildren(lastCreatedChild, keyNested, nestedValue[keyNested]));
+                        });
+                    };
                 });
             } else if (property.derivedDataType === DerivedPropertyType.COMPLEX) {
                 property.flattenedChildren = this.createFlattenedChildren(property.type, property.name);