Provide tosca function capability to list/map of complex type fields in composition... 47/135347/4
authorimamSidero <imam.hussain@est.tech>
Fri, 7 Jul 2023 15:16:49 +0000 (16:16 +0100)
committerMichael Morris <michael.morris@est.tech>
Wed, 19 Jul 2023 13:29:38 +0000 (13:29 +0000)
Tosca function capability is provided to list/map entries of complex type fields in composition view

Issue-ID: SDC-4562
Signed-off-by: Imam hussain <imam.hussain@est.tech>
Change-Id: I38355f5ab399e1504ad433037d0d547fe07e9bfa

catalog-ui/src/app/directives/property-types/data-type-fields-structure/data-type-fields-structure.html
catalog-ui/src/app/directives/property-types/data-type-fields-structure/data-type-fields-structure.ts
catalog-ui/src/app/directives/property-types/type-list/type-list-directive.html
catalog-ui/src/app/directives/property-types/type-map/type-map-directive.html
catalog-ui/src/app/ng2/pages/composition/panel/panel-tabs/properties-tab/properties-tab.component.ts
catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts
catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts

index afbd520..242c586 100644 (file)
@@ -31,7 +31,7 @@
         </div>
         <!--<div class="property-value">-->
         <div class="inner-structure tosca-box tosca-parent">
-            <div class="tosca-box" data-ng-if="complexToscapath == null">
+            <div class="tosca-box">
                 <form class="temp-form" data-ng-if="isService">
                     <input type="radio" name="hasToscaFunction-{{fieldsPrefixName}}" data-ng-checked="verifyTosca(property.name) == false" data-ng-click="onEnableTosca(false,property.name)"/> 
                     Value
@@ -45,6 +45,7 @@
                                 [allow-clear]="false"
                                 [composition-map]="true"
                                 [composition-map-key]="property.name"
+                                [complex-list-key]="complexToscapath"
                                 (on-valid-function)="onGetToscaFunction($event,property.name)"
                 >
                 </tosca-function>
index 37ca36a..0849776 100644 (file)
@@ -110,20 +110,6 @@ export class DataTypeFieldsStructureDirective implements ng.IDirective {
         scope.$watchCollection('[typeName,fieldsPrefixName]', (newData: any): void => {
             this.rerender(scope);
         });
-        let childProp = this.PropertiesUtils.convertAddPropertyBAToPropertyFE(scope.parentProperty);
-        scope.subpropertyMap = new Map<string,PropertyDeclareAPIModel>();
-        scope.showToscaFunction = new Map<string,boolean>();
-        childProp.flattenedChildren.forEach(prop => {
-            scope.showToscaFunction.set(prop.name,false);
-            if (scope.parentProperty.subPropertyToscaFunctions != null) {
-                scope.parentProperty.subPropertyToscaFunctions.forEach(SubPropertyToscaFunction => {
-                    if (SubPropertyToscaFunction.subPropertyPath.toString() == prop.name) {
-                        scope.showToscaFunction.set(prop.name,true);
-                    }
-                });
-            }
-            scope.subpropertyMap.set(prop.name,new PropertyDeclareAPIModel(childProp, prop));
-        });
         scope.expandAndCollapse = (): void => {
             if (!scope.expanded) {
                 this.initDataOnScope(scope, $attr);
@@ -183,20 +169,20 @@ export class DataTypeFieldsStructureDirective implements ng.IDirective {
         }
 
         scope.getToscaPathValue = (propertyName: string) : Array<string> => {
-            const parentObj : PropertyDeclareAPIModel = scope.subpropertyMap.get(propertyName);
-            if (parentObj.input instanceof DerivedFEProperty) {
-                return parentObj.input.toscaPath;
-            }
-            return [propertyName];
+            let toscaPath = [propertyName];
+            if (scope.complexToscapath != null) {
+                toscaPath = [scope.complexToscapath,propertyName];
+             }
+            return toscaPath;
         }
 
         scope.onGetToscaFunction = (toscaGetFunction: ToscaGetFunction, key:string): void => {
-            let toscaPath = key;
+            let toscaPath = scope.getToscaPathValue(key);
             scope.valueObjRef[key] = "";
             if (scope.parentProperty.subPropertyToscaFunctions != null) {
                 let toscaFlag : boolean = true
                 scope.parentProperty.subPropertyToscaFunctions.forEach(SubPropertyToscaFunction => {
-                    if (SubPropertyToscaFunction.subPropertyPath.toString() == toscaPath) {
+                    if (SubPropertyToscaFunction.subPropertyPath.toString() == toscaPath.toString()) {
                         SubPropertyToscaFunction.toscaFunction = toscaGetFunction;
                         toscaFlag = false;
                         return;
@@ -205,13 +191,13 @@ export class DataTypeFieldsStructureDirective implements ng.IDirective {
                 if (toscaFlag) {
                     let subPropertyToscaFunction = new SubPropertyToscaFunction();
                     subPropertyToscaFunction.toscaFunction = toscaGetFunction;
-                    subPropertyToscaFunction.subPropertyPath = [toscaPath];
+                    subPropertyToscaFunction.subPropertyPath = toscaPath;
                     scope.parentProperty.subPropertyToscaFunctions.push(subPropertyToscaFunction);
                 }
             } else {
                 let subPropertyToscaFunction = new SubPropertyToscaFunction();
                 subPropertyToscaFunction.toscaFunction = toscaGetFunction;
-                subPropertyToscaFunction.subPropertyPath = [toscaPath];
+                subPropertyToscaFunction.subPropertyPath = toscaPath;
                 scope.parentProperty.subPropertyToscaFunctions = [subPropertyToscaFunction];
             }
         }
@@ -249,6 +235,37 @@ export class DataTypeFieldsStructureDirective implements ng.IDirective {
             scope.valueObjRef = {};
         }
 
+        let childProp = this.PropertiesUtils.convertAddPropertyBAToPropertyFE(scope.parentProperty);
+        scope.subpropertyMap = new Map<string,PropertyDeclareAPIModel>();
+        scope.showToscaFunction = new Map<string,boolean>();
+        if (childProp.flattenedChildren.length > 0) {
+            childProp.flattenedChildren.forEach(prop => {
+                scope.showToscaFunction.set(prop.name,false);
+                if (scope.parentProperty.subPropertyToscaFunctions != null) {
+                    scope.parentProperty.subPropertyToscaFunctions.forEach(SubPropertyToscaFunction => {
+                        let toscaPath = scope.getToscaPathValue(prop.name);
+                        if (SubPropertyToscaFunction.subPropertyPath.toString() == toscaPath.toString()) {
+                            scope.showToscaFunction.set(prop.name,true);
+                        }
+                    });
+                }
+                scope.subpropertyMap.set(prop.name,new PropertyDeclareAPIModel(childProp, prop));
+            });
+        } else {
+            scope.dataTypeProperties.forEach(prop => {
+                scope.showToscaFunction.set(prop.name,false);
+                if (scope.parentProperty.subPropertyToscaFunctions != null) {
+                    scope.parentProperty.subPropertyToscaFunctions.forEach(SubPropertyToscaFunction => {
+                        let toscaPath = scope.getToscaPathValue(prop.name);
+                        if (SubPropertyToscaFunction.subPropertyPath.toString() == toscaPath.toString()) {
+                            scope.showToscaFunction.set(prop.name,true);
+                        }
+                    });
+                }
+                scope.subpropertyMap.set(prop.name,new PropertyDeclareAPIModel(childProp, prop));
+            });
+        }
+
         _.forEach(scope.currentTypeDefaultValue, (value, key) => {
             if (angular.isUndefined(scope.valueObjRef[key])) {
                 if (typeof scope.currentTypeDefaultValue[key] == 'object') {
index 109c9a9..e7623b3 100644 (file)
                             type-name="schemaProperty.type"
                             parent-form-obj="parentFormObj"
                             parent-property="parentProperty"
+                            component-instance-map="componentInstanceMap"
                             fields-prefix-name="fieldsPrefixName+''+$index"
                             types="types"
+                            is-service="isService"
+                            complex-toscapath="$index"
                             read-only="readOnly"></fields-structure>
         </div>
         <div data-ng-if="!isSchemaTypeDataType">
index fad6838..97e186e 100644 (file)
             <fields-structure value-obj-ref="valueObjRef[mapKeysStatic[$index]]"
                               type-name="schemaProperty.type"
                               parent-form-obj="parentFormObj"
+                              parent-property="parentProperty"
+                              component-instance-map="componentInstanceMap"
                               fields-prefix-name="'mapValue'+fieldsPrefixName+''+$index"
+                              is-service="isService"
+                              complex-toscapath="mapKeys[$index]"
                               types="types"
                               read-only="readOnly"
             ></fields-structure>
index d25daf2..ec804f3 100644 (file)
@@ -12,6 +12,7 @@ import {
     InputsGroup,
     InputModel
 } from 'app/models';
+import {DataTypesService} from "app/services";
 import {ToscaGetFunctionType} from "app/models/tosca-get-function-type";
 import { CompositionService } from 'app/ng2/pages/composition/composition.service';
 import { WorkspaceService } from 'app/ng2/pages/workspace/workspace.service';
@@ -52,6 +53,7 @@ export class PropertiesTabComponent implements OnInit {
 
     constructor(private store: Store,
                 private workspaceService: WorkspaceService,
+                private DataTypesService:DataTypesService,
                 private compositionService: CompositionService,
                 private modalsHandler: ModalsHandler,
                 private topologyTemplateService: TopologyTemplateService,
@@ -63,6 +65,7 @@ export class PropertiesTabComponent implements OnInit {
 
     ngOnInit() {
         this.metadata = this.workspaceService.metadata;
+        this.DataTypesService.loadDataTypesCache(this.workspaceService.metadata.model);
         this.isComponentInstanceSelected = this.componentType === SelectedComponentType.COMPONENT_INSTANCE;
         this.getComponentInstancesPropertiesAndAttributes();
     }
index 2929080..2bfbab7 100644 (file)
@@ -52,6 +52,7 @@ export class ToscaFunctionComponent implements OnInit, OnChanges {
     @Input() allowClear: boolean = true;
     @Input() compositionMap: boolean = false;
     @Input() compositionMapKey: string = "";
+    @Input() complexListKey: string = null;
     @Output() onValidFunction: EventEmitter<ToscaGetFunction> = new EventEmitter<ToscaGetFunction>();
     @Output() onValidityChange: EventEmitter<ToscaFunctionValidationEvent> = new EventEmitter<ToscaFunctionValidationEvent>();
 
@@ -108,7 +109,15 @@ export class ToscaFunctionComponent implements OnInit, OnChanges {
     private initToscaFunction(): void {
         if (this.compositionMap && this.property.subPropertyToscaFunctions) {
             let keyToFind = [this.compositionMapKey];
-            let subPropertyToscaFunction = this.property.subPropertyToscaFunctions.find(subPropertyToscaFunction => this.areEqual(subPropertyToscaFunction.subPropertyPath, keyToFind));
+            if (this.complexListKey != null) {
+                keyToFind = [this.complexListKey,this.compositionMapKey];
+            }       
+            let subPropertyToscaFunction;
+            this.property.subPropertyToscaFunctions.forEach(subToscaFunction => {
+                if (subToscaFunction.subPropertyPath.toString() == keyToFind.toString()) {
+                    subPropertyToscaFunction = subToscaFunction;
+                }
+            });
 
             if (subPropertyToscaFunction){
                 this.toscaFunction = subPropertyToscaFunction.toscaFunction;
index 1fe4677..5f5c2b6 100644 (file)
@@ -329,7 +329,7 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
            if (this.isSubProperty()){
             if ((this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty)
                 || this.compositionMap) {
-                if(this.isComplexType(this.property.schemaType) && !this.compositionMap){
+                if(this.isComplexType(this.property.schemaType)){
                     let mapChildProp : DerivedFEProperty = (<DerivedFEProperty> (<PropertyDeclareAPIModel> this.property).input);
                     let propertySchemaType = mapChildProp.type;
                     if (this.property.type == PROPERTY_TYPES.MAP || propertySchemaType == PROPERTY_TYPES.MAP) {
@@ -487,7 +487,7 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges {
             if ((this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty) || this.compositionMap) {
                 let childObject : DerivedFEProperty = (<DerivedFEProperty>(<PropertyDeclareAPIModel> this.property).input);
                 let childSchemaType = (this.property != null && this.property.schemaType != null) ? this.property.schemaType : childObject.type;
-                if(this.isComplexType(childSchemaType) && !this.compositionMap){
+                if(this.isComplexType(childSchemaType)){
                     if (childObject.type == PROPERTY_TYPES.MAP && childObject.isChildOfListOrMap) {
                         return validPropertyType === PROPERTY_TYPES.STRING;
                     }