Support tosca functions for group instances 79/129879/2
authorMichaelMorris <michael.morris@est.tech>
Tue, 19 Jul 2022 12:28:40 +0000 (13:28 +0100)
committerMichaelMorris <michael.morris@est.tech>
Tue, 19 Jul 2022 12:31:51 +0000 (13:31 +0100)
Issue-ID: SDC-4090
Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech>
Change-Id: I91650050fed57a4243df157034cb68ecd8421413
Signed-off-by: MichaelMorris <michael.morris@est.tech>
catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts

index 2ae5ce8..6474b15 100644 (file)
@@ -511,17 +511,17 @@ export class PropertiesAssignmentComponent {
      * Select Tosca function value from defined values
      */
     selectToscaFunctionAndValues = (): void => {
-        const selectedInstanceData: ComponentInstance = this.getSelectedComponentInstance();
+        const selectedInstanceData: ComponentInstance | GroupInstance = this.getSelectedInstance();
         if (!selectedInstanceData) {
             return;
         }
         this.openToscaGetFunctionModal();
     }
 
-    private getSelectedComponentInstance(): ComponentInstance {
+    private getSelectedInstance(): ComponentInstance | GroupInstance {
         const instancesIds = this.keysPipe.transform(this.instanceFePropertiesMap, []);
         const instanceId: string = instancesIds[0];
-        return <ComponentInstance> this.instances.find(instance => instance.uniqueId == instanceId && instance instanceof ComponentInstance);
+        return <ComponentInstance | GroupInstance> this.instances.find(instance => instance.uniqueId == instanceId && instance instanceof ComponentInstance || instance instanceof GroupInstance);
     }
 
     private buildCheckedInstanceProperty(): PropertyBEModel {
@@ -578,13 +578,21 @@ export class PropertiesAssignmentComponent {
         checkedInstanceProperty.getInputValues = null;
         checkedInstanceProperty.value = null;
         checkedInstanceProperty.toscaFunction = null;
-        this.updateInstanceProperty(checkedInstanceProperty);
+        if (this.selectedInstanceData instanceof ComponentInstance) {
+            this.updateInstanceProperty(checkedInstanceProperty);
+        } else if (this.selectedInstanceData instanceof GroupInstance) {
+            this.updateGroupInstanceProperty(checkedInstanceProperty);
+        }
     }
 
     private updateCheckedInstancePropertyFunctionValue(toscaFunction: ToscaFunction) {
         const checkedProperty: PropertyBEModel = this.buildCheckedInstanceProperty();
         checkedProperty.toscaFunction = toscaFunction;
-        this.updateInstanceProperty(checkedProperty);
+        if (this.selectedInstanceData instanceof ComponentInstance) {
+            this.updateInstanceProperty(checkedProperty);
+        } else if (this.selectedInstanceData instanceof GroupInstance) {
+            this.updateGroupInstanceProperty(checkedProperty);
+        }
     }
 
     updateInstanceProperty(instanceProperty: PropertyBEModel) {
@@ -592,7 +600,21 @@ export class PropertiesAssignmentComponent {
         this.componentInstanceServiceNg2.updateInstanceProperties(this.component.componentType, this.component.uniqueId,
             this.selectedInstanceData.uniqueId, [instanceProperty])
         .subscribe(() => {
-            this.changeSelectedInstance(this.getSelectedComponentInstance());
+            this.changeSelectedInstance(this.getSelectedInstance());
+        }, (error) => {
+            this.loadingProperties = false;
+            console.error(error);
+        }, () => {
+            this.loadingProperties = false;
+        });
+    }
+
+    updateGroupInstanceProperty(instanceProperty: PropertyBEModel) {
+        this.loadingProperties = true;
+        this.componentInstanceServiceNg2.updateComponentGroupInstanceProperties(this.component.componentType, this.component.uniqueId,
+            this.selectedInstanceData.uniqueId, [instanceProperty])
+        .subscribe(() => {
+            this.changeSelectedInstance(this.getSelectedInstance());
         }, (error) => {
             this.loadingProperties = false;
             console.error(error);