Fix Interface Operation mandatory fields 65/129665/3
authorJvD_Ericsson <jeff.van.dam@est.tech>
Wed, 22 Jun 2022 14:38:43 +0000 (15:38 +0100)
committerMichael Morris <michael.morris@est.tech>
Thu, 23 Jun 2022 12:16:03 +0000 (12:16 +0000)
and remove unnecessary methods

Issue-ID: SDC-4061
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Change-Id: I91da5127592563cfab33b00c410f5380f088f6d6

catalog-ui/src/app/ng2/pages/composition/interface-operatons/interface-operations.component.ts
catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/interface-operation-handler.component.ts
catalog-ui/src/app/ng2/pages/interface-definition/interface-definition.page.component.ts

index 2a0dcd2..1dc02a5 100644 (file)
@@ -214,8 +214,21 @@ 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) {
+            let toscaArtifactTypeSelected = this.modalInstance.instance.dynamicContent.instance.toscaArtifactTypeSelected;
+            let isToscaArtifactType:boolean = !(typeof toscaArtifactTypeSelected == 'undefined' || _.isEmpty(toscaArtifactTypeSelected));
+            disable = !isToscaArtifactType;
+            return disable;
+        }
+        disable = false;
+        return disable;
     }
 
     onSelectInterfaceOperation(interfaceModel: UIInterfaceModel, operation: InterfaceOperationModel) {
@@ -226,7 +239,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);
@@ -242,7 +255,7 @@ export class InterfaceOperationsComponent {
                 toscaArtifactTypes: this.toscaArtifactTypes,
                 selectedInterface: interfaceModel ? interfaceModel : new UIInterfaceModel(),
                 selectedInterfaceOperation: operation ? operation : new InterfaceOperationModel(),
-                validityChangedCallback: this.enableOrDisableSaveButton,
+                validityChangedCallback: this.disableSaveButton,
                 isViewOnly: this.isViewOnly,
                 isEdit: true,
                 modelName: this.componentMetaData.model
index 6bfb09d..216dc32 100644 (file)
@@ -18,7 +18,7 @@
 *  SPDX-License-Identifier: Apache-2.0
 *  ============LICENSE_END=========================================================
 */
-import {Component, EventEmitter, Input, Output, ViewChild} from '@angular/core';
+import {Component, EventEmitter, Output, ViewChild} from '@angular/core';
 import {UIInterfaceModel} from "../interface-operations.component";
 import {InputOperationParameter, InterfaceOperationModel, IOperationParamsList} from "../../../../../models/interfaceOperation";
 import {TranslateService} from "../../../../shared/translator/translate.service";
@@ -65,7 +65,6 @@ export class InterfaceOperationHandlerComponent {
     inputs: Array<InputOperationParameter> = [];
     properties: Array<PropertyParamRowComponent> = [];
     isLoading: boolean = false;
-    readonly: boolean;
     isViewOnly: boolean;
     isEdit: boolean;
     interfaceTypes: Array<DropdownValue> = [];
@@ -75,21 +74,15 @@ export class InterfaceOperationHandlerComponent {
     interfaceOperationOptions: Array<DropDownOption> = [];
     selectedInterfaceOperation: DropDownOption = undefined;
     modelName: string;
-
     toscaArtifactTypeSelected: string;
     toscaArtifactTypeProperties: Array<PropertyBEModel> = [];
     artifactTypeProperties: Array<InputOperationParameter> = [];
-
     toscaArtifactTypes: Array<DropdownValue> = [];
-
     enableAddArtifactImplementation: boolean;
-
     propertyValueValid: boolean = true;
     inputTypeOptions: any[];
 
     constructor(private dataTypeService: DataTypeService, private componentServiceNg2: ComponentServiceNg2) {
-
-
     }
 
     ngOnInit() {
@@ -102,7 +95,6 @@ export class InterfaceOperationHandlerComponent {
         this.modelName = this.input.modelName;
         this.initInputs();
         this.removeImplementationQuote();
-        this.validityChanged();
         this.loadInterfaceOperationImplementation();
 
         this.dataTypeMap$ = new Observable<Map<string, DataTypeModel>>(subscriber => {
@@ -125,7 +117,6 @@ export class InterfaceOperationHandlerComponent {
 
         this.inputs = Array.from(this.operationToUpdate.inputs.listToscaDataDefinition);
         this.removeImplementationQuote();
-        this.validityChanged();
         this.loadInterfaceOperationImplementation();
         this.loadInterfaceType();
     }
@@ -208,7 +199,6 @@ export class InterfaceOperationHandlerComponent {
             this.getArtifactTypesSelected();
         }
         this.enableAddArtifactImplementation = event;
-        this.validateRequiredField();
     }
 
     onSelectToscaArtifactType(type: IDropDownOption) {
@@ -225,7 +215,6 @@ export class InterfaceOperationHandlerComponent {
             this.operationToUpdate.implementation = artifact;
             this.getArtifactTypesSelected();
         }
-        this.validateRequiredField();
     }
 
     onArtifactVersionChange(value: string | undefined) {
@@ -234,20 +223,16 @@ export class InterfaceOperationHandlerComponent {
 
     onAddInput(inputOperationParameter: InputOperationParameter) {
         this.addInput(inputOperationParameter);
-        this.validityChanged();
     }
 
     propertyValueValidation = (propertyValue): void => {
         this.onPropertyValueChange(propertyValue);
         this.propertyValueValid = propertyValue.isValid;
-        this.readonly = !this.propertyValueValid;
-        this.validateRequiredField();
     }
 
     onRemoveInput = (inputParam: InputOperationParameter): void => {
         let index = this.inputs.indexOf(inputParam);
         this.inputs.splice(index, 1);
-        this.validityChanged();
     }
 
     private removeImplementationQuote(): void {
@@ -265,14 +250,6 @@ export class InterfaceOperationHandlerComponent {
         }
     }
 
-    validityChanged = () => {
-        let validState = this.checkFormValidForSubmit();
-        this.input.validityChangedCallback(validState);
-        if (validState) {
-            this.readonly = false;
-        }
-    }
-
     private getArtifactTypesSelected() {
         if (this.operationToUpdate.implementation && this.operationToUpdate.implementation.artifactType) {
             this.artifactName =
@@ -284,33 +261,6 @@ export class InterfaceOperationHandlerComponent {
             this.artifactTypeProperties = this.convertArtifactsPropertiesToInput();
             this.enableAddArtifactImplementation = true;
         }
-        this.validateRequiredField();
-    }
-
-    validateRequiredField = () => {
-        this.readonly = true;
-        const isRequiredFieldSelected = this.isRequiredFieldsSelected();
-        this.input.validityChangedCallback(isRequiredFieldSelected);
-        if (isRequiredFieldSelected && this.propertyValueValid) {
-            this.readonly = false;
-        }
-    }
-
-    private isRequiredFieldsSelected() {
-        return this.toscaArtifactTypeSelected && this.artifactName;
-    }
-
-    private checkFormValidForSubmit = (): boolean => {
-        return this.operationToUpdate.name && this.artifactName && this.isParamsValid();
-    }
-
-    private isParamsValid = (): boolean => {
-        const isInputValid = (input) => input.name && input.inputId && input.type;
-        const isValid = this.inputs.every(isInputValid);
-        if (!isValid) {
-            this.readonly = true;
-        }
-        return isValid;
     }
 
     toDropDownOption(val: string) {
index eab8b18..b3f8dfc 100644 (file)
@@ -217,11 +217,26 @@ export class InterfaceDefinitionComponent {
     }
 
     private disableSaveButton = (): boolean => {
-        return this.readonly ||
-            (this.isEnableAddArtifactImplementation()
-                && (!this.modalInstance.instance.dynamicContent.toscaArtifactTypeSelected ||
-                    !this.modalInstance.instance.dynamicContent.artifactName)
-            );
+        let disable:boolean = true;
+        if(this.readonly) {
+            return disable;
+        }
+    
+        let selectedInterfaceOperation = this.modalInstance.instance.dynamicContent.instance.selectedInterfaceOperation;
+        let isInterfaceOperation:boolean = !(typeof selectedInterfaceOperation == 'undefined' || _.isEmpty(selectedInterfaceOperation));
+        let selectedInterfaceType = this.modalInstance.instance.dynamicContent.instance.selectedInterfaceType;
+        let isInterfaceType:boolean = !(typeof selectedInterfaceType == 'undefined' || _.isEmpty(selectedInterfaceType));
+        let bothSet: boolean = isInterfaceOperation && isInterfaceType;
+    
+        let enableAddArtifactImplementation = this.modalInstance.instance.dynamicContent.instance.enableAddArtifactImplementation;
+        if(enableAddArtifactImplementation) {
+            let toscaArtifactTypeSelected = this.modalInstance.instance.dynamicContent.instance.toscaArtifactTypeSelected;
+            let isToscaArtifactType:boolean = !(typeof toscaArtifactTypeSelected == 'undefined' || _.isEmpty(toscaArtifactTypeSelected));
+            disable = !bothSet || !isToscaArtifactType;
+            return disable;
+        }
+        disable = !bothSet;
+        return disable;
     }
 
     onSelectInterfaceOperation(interfaceModel: UIInterfaceModel, operation: InterfaceOperationModel) {