Fix interface name and operation not being disabled on edit
[sdc.git] / catalog-ui / src / app / ng2 / pages / composition / interface-operatons / interface-operations.component.ts
index c17c130..2a0dcd2 100644 (file)
@@ -93,12 +93,12 @@ class ModalTranslation {
     CLOSE_BUTTON: string;
     SAVE_BUTTON: string;
 
-    constructor(private TranslateService: TranslateService) {
-        this.TranslateService.languageChangedObservable.subscribe(lang => {
-            this.EDIT_TITLE = this.TranslateService.translate('INTERFACE_EDIT_TITLE');
-            this.CANCEL_BUTTON = this.TranslateService.translate("INTERFACE_CANCEL_BUTTON");
-            this.CLOSE_BUTTON = this.TranslateService.translate("INTERFACE_CLOSE_BUTTON");
-            this.SAVE_BUTTON = this.TranslateService.translate("INTERFACE_SAVE_BUTTON");
+    constructor(private translateService: TranslateService) {
+        this.translateService.languageChangedObservable.subscribe(lang => {
+            this.EDIT_TITLE = this.translateService.translate('INTERFACE_EDIT_TITLE');
+            this.CANCEL_BUTTON = this.translateService.translate("INTERFACE_CANCEL_BUTTON");
+            this.CLOSE_BUTTON = this.translateService.translate("INTERFACE_CLOSE_BUTTON");
+            this.SAVE_BUTTON = this.translateService.translate("INTERFACE_SAVE_BUTTON");
         });
     }
 }
@@ -148,15 +148,15 @@ export class InterfaceOperationsComponent {
 
 
     constructor(
-        private TranslateService: TranslateService,
-        private PluginsService: PluginsService,
+        private translateService: TranslateService,
+        private pluginsService: PluginsService,
         private topologyTemplateService: TopologyTemplateService,
         private toscaArtifactService: ToscaArtifactService,
         private modalServiceNg2: ModalService,
         private workspaceService: WorkspaceService,
         @Inject("Notification") private Notification: any,
     ) {
-        this.modalTranslation = new ModalTranslation(TranslateService);
+        this.modalTranslation = new ModalTranslation(translateService);
     }
 
     ngOnInit(): void {
@@ -214,8 +214,8 @@ export class InterfaceOperationsComponent {
         ).length === 0;
     }
 
-    private enableOrDisableSaveButton = (): boolean => {
-        return this.isViewOnly;
+    private enableOrDisableSaveButton = (isValid): boolean => {
+        return isValid;
     }
 
     onSelectInterfaceOperation(interfaceModel: UIInterfaceModel, operation: InterfaceOperationModel) {
@@ -243,7 +243,9 @@ export class InterfaceOperationsComponent {
                 selectedInterface: interfaceModel ? interfaceModel : new UIInterfaceModel(),
                 selectedInterfaceOperation: operation ? operation : new InterfaceOperationModel(),
                 validityChangedCallback: this.enableOrDisableSaveButton,
-                isViewOnly: this.isViewOnly
+                isViewOnly: this.isViewOnly,
+                isEdit: true,
+                modelName: this.componentMetaData.model
             }
         );
         this.modalInstance.instance.open();
@@ -255,14 +257,14 @@ export class InterfaceOperationsComponent {
     }
 
     private updateInterfaceOperation() {
-        this.isLoading = true;
+        this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = true;
         const interfaceOperationHandlerComponentInstance: InterfaceOperationHandlerComponent = this.modalInstance.instance.dynamicContent.instance;
         const operationUpdated: InterfaceOperationModel = interfaceOperationHandlerComponentInstance.operationToUpdate;
         const isArtifactChecked = interfaceOperationHandlerComponentInstance.enableAddArtifactImplementation;
         if (!isArtifactChecked) {
             let artifactName = interfaceOperationHandlerComponentInstance.artifactName;
             artifactName = artifactName === undefined ? '' : artifactName;
-            operationUpdated.implementation = new ArtifactModel({'artifactName': artifactName} as ArtifactModel);
+            operationUpdated.implementation = new ArtifactModel({'artifactName': artifactName, 'artifactVersion': ''} as ArtifactModel);
         }
         this.topologyTemplateService.updateComponentInstanceInterfaceOperation(
             this.componentMetaData.uniqueId,
@@ -272,9 +274,12 @@ export class InterfaceOperationsComponent {
         .subscribe((updatedComponentInstance: ComponentInstance) => {
             this.componentInstanceSelected = new ComponentInstance(updatedComponentInstance);
             this.initComponentInstanceInterfaceOperations();
+            this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = false;
+            this.modalServiceNg2.closeCurrentModal();
+        }, () => {
+            this.modalServiceNg2.currentModal.instance.dynamicContent.instance.isLoading = false;
+            this.modalServiceNg2.closeCurrentModal();
         });
-        this.modalServiceNg2.closeCurrentModal();
-        this.isLoading = false;
     }
 
     loadDeployedArtifacts() {