Custom tosca functions with valid_values and in_range operators not showing properly
[sdc.git] / catalog-ui / src / app / ng2 / pages / properties-assignment / tosca-function / tosca-function.component.ts
index 2929080..412e29a 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;
@@ -158,9 +167,9 @@ export class ToscaFunctionComponent implements OnInit, OnChanges {
         }
 
         this.toscaFunctionForm.setValue(this.inToscaFunction ? this.inToscaFunction : this.property.toscaFunction);
-        let type = this.property.toscaFunction.type;
+        let type = this.property.toscaFunction.type ? this.property.toscaFunction.type : this.toscaFunctionForm.value.type;
         if (type == ToscaFunctionType.CUSTOM) {
-            let name = (this.property.toscaFunction as ToscaCustomFunction).name;
+            let name = (this.toscaFunctionForm.value as ToscaCustomFunction).name;
             let customToscaFunc = this.customToscaFunctions.find(custToscFunc => _.isEqual(custToscFunc.name, name))
             if (customToscaFunc) {
                 this.toscaFunctionTypeForm.setValue(name);
@@ -272,6 +281,7 @@ export class ToscaFunctionComponent implements OnInit, OnChanges {
         } else {
             this.toscaFunctionForm.setValue(undefined);
         }
+        this.emitValidityChange();
     }
 
     onCustomFunctionValidityChange(validationEvent: ToscaCustomFunctionValidationEvent): void {
@@ -298,6 +308,7 @@ export class ToscaFunctionComponent implements OnInit, OnChanges {
         } else {
             this.toscaFunctionForm.setValue(undefined);
         }
+        this.emitValidityChange();
     }
 
     onFunctionTypeChange(): void {