Provide timeout field in interface operation implementation
[sdc.git] / catalog-ui / src / app / ng2 / pages / composition / interface-operatons / interface-operations.component.ts
index 2a0dcd2..04210ae 100644 (file)
@@ -25,11 +25,12 @@ import {
 } from '../../../services/component-services/topology-template.service';
 import {TranslateService} from "../../../shared/translator/translate.service";
 import {ModalService} from 'app/ng2/services/modal.service';
+import {CompositionService} from "app/ng2/pages/composition/composition.service";
 import {ModalComponent} from 'app/ng2/components/ui/modal/modal.component';
 import {Component as TopologyTemplate} from "../../../../models/components/component";
 import {PluginsService} from "app/ng2/services/plugins.service";
 import {SelectedComponentType} from "../common/store/graph.actions";
-
+import {InstanceFeDetails} from "../../../../models/instance-fe-details";
 import {WorkspaceService} from "../../workspace/workspace.service";
 import {
     ComponentInterfaceDefinitionModel,
@@ -139,6 +140,8 @@ export class InterfaceOperationsComponent {
 
     deploymentArtifactsFilePath: Array<DropdownValue> = [];
     toscaArtifactTypes: Array<DropdownValue> = [];
+    componentInstanceMap: Map<string, InstanceFeDetails> = new Map<string, InstanceFeDetails>();
+    validImplementationProps: boolean = true;
 
     @Input() component: ComponentInstance;
     @Input() isViewOnly: boolean;
@@ -153,6 +156,7 @@ export class InterfaceOperationsComponent {
         private topologyTemplateService: TopologyTemplateService,
         private toscaArtifactService: ToscaArtifactService,
         private modalServiceNg2: ModalService,
+        private compositionService: CompositionService,
         private workspaceService: WorkspaceService,
         @Inject("Notification") private Notification: any,
     ) {
@@ -214,8 +218,22 @@ export class InterfaceOperationsComponent {
         ).length === 0;
     }
 
-    private enableOrDisableSaveButton = (isValid): boolean => {
-        return isValid;
+    private disableSaveButton = (): boolean => {
+        let disable:boolean = true;
+        if(this.isViewOnly) {
+            return disable;
+        }
+
+        let enableAddArtifactImplementation = this.modalInstance.instance.dynamicContent.instance.enableAddArtifactImplementation;
+        if(enableAddArtifactImplementation) {
+            const validImplementationProps = this.modalInstance.instance.dynamicContent.instance.validImplementationProps;
+            const toscaArtifactTypeSelected = this.modalInstance.instance.dynamicContent.instance.toscaArtifactTypeSelected;
+            const isToscaArtifactType:boolean = !(typeof toscaArtifactTypeSelected == 'undefined' || _.isEmpty(toscaArtifactTypeSelected));
+            disable = !isToscaArtifactType || !validImplementationProps;
+            return disable;
+        }
+        disable = false;
+        return disable;
     }
 
     onSelectInterfaceOperation(interfaceModel: UIInterfaceModel, operation: InterfaceOperationModel) {
@@ -226,7 +244,7 @@ export class InterfaceOperationsComponent {
             buttonList.push(closeButton);
         } else {
             const saveButton: ButtonModel = new ButtonModel(this.modalTranslation.SAVE_BUTTON, 'blue', () =>
-                this.updateInterfaceOperation(), this.enableOrDisableSaveButton);
+                this.updateInterfaceOperation(), this.disableSaveButton);
             const cancelButton: ButtonModel = new ButtonModel(this.modalTranslation.CANCEL_BUTTON, 'outline white', this.cancelAndCloseModal);
             buttonList.push(saveButton);
             buttonList.push(cancelButton);
@@ -234,16 +252,27 @@ export class InterfaceOperationsComponent {
         const modalModel: ModalModel = new ModalModel('l', this.modalTranslation.EDIT_TITLE, '', buttonList, 'custom');
         this.modalInstance = this.modalServiceNg2.createCustomModal(modalModel);
 
+        const componentInstances = this.compositionService.getComponentInstances()
+        if (componentInstances) {
+            componentInstances.forEach(value => {
+                this.componentInstanceMap.set(value.uniqueId, <InstanceFeDetails>{
+                    name: value.name
+                });
+            });
+        }
+
         this.modalServiceNg2.addDynamicContentToModal(
             this.modalInstance,
             InterfaceOperationHandlerComponent,
             {
                 deploymentArtifactsFilePath: this.deploymentArtifactsFilePath,
+                componentInstanceMap: this.componentInstanceMap,
                 toscaArtifactTypes: this.toscaArtifactTypes,
                 selectedInterface: interfaceModel ? interfaceModel : new UIInterfaceModel(),
                 selectedInterfaceOperation: operation ? operation : new InterfaceOperationModel(),
-                validityChangedCallback: this.enableOrDisableSaveButton,
+                validityChangedCallback: this.disableSaveButton,
                 isViewOnly: this.isViewOnly,
+                validImplementationProps: this.validImplementationProps,
                 isEdit: true,
                 modelName: this.componentMetaData.model
             }
@@ -260,12 +289,19 @@ export class InterfaceOperationsComponent {
         this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = true;
         const interfaceOperationHandlerComponentInstance: InterfaceOperationHandlerComponent = this.modalInstance.instance.dynamicContent.instance;
         const operationUpdated: InterfaceOperationModel = interfaceOperationHandlerComponentInstance.operationToUpdate;
+        let timeout = null;
+        if (operationUpdated.implementation && operationUpdated.implementation.timeout != null) {
+            timeout = operationUpdated.implementation.timeout;
+        }
         const isArtifactChecked = interfaceOperationHandlerComponentInstance.enableAddArtifactImplementation;
         if (!isArtifactChecked) {
             let artifactName = interfaceOperationHandlerComponentInstance.artifactName;
             artifactName = artifactName === undefined ? '' : artifactName;
             operationUpdated.implementation = new ArtifactModel({'artifactName': artifactName, 'artifactVersion': ''} as ArtifactModel);
         }
+        if (timeout != null) {
+            operationUpdated.implementation.timeout = timeout;
+        }
         this.topologyTemplateService.updateComponentInstanceInterfaceOperation(
             this.componentMetaData.uniqueId,
             this.componentMetaData.componentType,