Allow multiple entry for map/list when tosca function is selected
[sdc.git] / catalog-ui / src / app / ng2 / pages / properties-assignment / properties-assignment.page.component.ts
index 09fd888..c828fab 100644 (file)
@@ -37,15 +37,17 @@ import {
     PolicyInstance,
     PropertyBEModel,
     PropertyFEModel,
-    PropertyInputDetail,
-    SimpleFlatProperty
+    Service,
+    SimpleFlatProperty,
+    PropertyDeclareAPIModel,
+    PropertiesGroup
 } from "app/models";
 import {ResourceType} from "app/utils";
 import {ComponentServiceNg2} from "../../services/component-services/component.service";
 import {TopologyTemplateService} from "../../services/component-services/topology-template.service";
 import {ComponentInstanceServiceNg2} from "../../services/component-instance-services/component-instance.service"
 import {KeysPipe} from 'app/ng2/pipes/keys.pipe';
-import {EVENTS, PROPERTY_TYPES, WorkspaceMode} from "../../../utils/constants";
+import {EVENTS, PROPERTY_TYPES, WorkspaceMode, PROPERTY_DATA} from "../../../utils/constants";
 import {EventListenerService} from "app/services/event-listener-service"
 import {HierarchyDisplayOptions} from "../../components/logic/hierarchy-navigtion/hierarchy-display-options";
 import {FilterPropertiesAssignmentComponent} from "../../components/logic/filter-properties-assignment/filter-properties-assignment.component";
@@ -61,13 +63,17 @@ import {UnsavedChangesComponent} from "app/ng2/components/ui/forms/unsaved-chang
 import {PropertyCreatorComponent} from "./property-creator/property-creator.component";
 import {ModalService} from "../../services/modal.service";
 import {DeclareListComponent} from "./declare-list/declare-list.component";
-import {InputListComponent} from "./input-list/input-list.component";
+import {ToscaFunctionComponent, ToscaFunctionValidationEvent} from "./tosca-function/tosca-function.component";
 import {CapabilitiesGroup, Capability} from "../../../models/capability";
 import {ToscaPresentationData} from "../../../models/tosca-presentation";
 import {Observable} from "rxjs";
-import {ToscaGetFunctionType} from "../../../models/tosca-get-function-type.enum";
 import {TranslateService} from "../../shared/translator/translate.service";
-import {Model} from '../../../models/model';
+import {ToscaFunction} from "../../../models/tosca-function";
+import {SubPropertyToscaFunction} from "../../../models/sub-property-tosca-function";
+import {DeclareInputComponent} from "./declare-input/declare-input.component";
+import {ElementService} from "../../services/element.service";
+import {CustomToscaFunction} from "../../../models/default-custom-functions";
+import {ToscaFunctionType} from "../../../models/tosca-function-type.enum";
 
 const SERVICE_SELF_TITLE = "SELF";
 @Component({
@@ -78,7 +84,9 @@ export class PropertiesAssignmentComponent {
     title = "Properties & Inputs";
 
     component: ComponentData;
-    componentInstanceNamesMap: Map<string, InstanceFeDetails> = new Map<string, InstanceFeDetails>();//instanceUniqueId, {name, iconClass}
+    componentInstanceNamesMap: { [key: string]: InstanceFeDetails } = {}; //key is the instance uniqueId
+    componentInstanceMap: Map<string, InstanceFeDetails> = new Map<string, InstanceFeDetails>(); //key is the instance uniqueId
+    customToscaFunctions: Array<CustomToscaFunction> = [];
 
     propertiesNavigationData = [];
     instancesNavigationData = [];
@@ -94,6 +102,8 @@ export class PropertiesAssignmentComponent {
     selectedInstanceData: ComponentInstance | GroupInstance | PolicyInstance = null;
     checkedPropertiesCount: number = 0;
     checkedChildPropertiesCount: number = 0;
+    enableToscaFunction: boolean = false;
+    checkedToscaCount: number = 0;
 
     hierarchyPropertiesDisplayOptions: HierarchyDisplayOptions = new HierarchyDisplayOptions('path', 'name', 'childrens');
     hierarchyInstancesDisplayOptions: HierarchyDisplayOptions = new HierarchyDisplayOptions('uniqueId', 'name', 'archived', null, 'iconClass');
@@ -102,7 +112,6 @@ export class PropertiesAssignmentComponent {
     currentMainTab: Tab;
     isInputsTabSelected: boolean;
     isPropertiesTabSelected: boolean;
-    isInputValueSelected: boolean = false;
     isPoliciesTabSelected: boolean;
     isReadonly: boolean;
     resourceIsReadonly: boolean;
@@ -118,8 +127,9 @@ export class PropertiesAssignmentComponent {
     serviceBePropertiesMap: InstanceBePropertiesMap;
     serviceBeCapabilitiesPropertiesMap: InstanceBePropertiesMap;
     selectedInstance_FlattenCapabilitiesList: Capability[];
-    propertyType: string;
-    btnSelectInputText: string;
+    componentInstancePropertyMap : PropertiesGroup;
+    defaultInputName: string;
+    doNotExtendBaseType: boolean;
 
     @ViewChild('hierarchyNavTabs') hierarchyNavTabs: Tabs;
     @ViewChild('propertyInputTabs') propertyInputTabs: Tabs;
@@ -135,20 +145,21 @@ export class PropertiesAssignmentComponent {
                 @Inject("$stateParams") _stateParams,
                 @Inject("$scope") private $scope: ng.IScope,
                 @Inject("$state") private $state: ng.ui.IStateService,
-                @Inject("Notification") private Notification: any,
+                @Inject("Notification") private notification: any,
                 private componentModeService: ComponentModeService,
-                private EventListenerService: EventListenerService,
+                private eventListenerService: EventListenerService,
                 private ModalServiceSdcUI: SdcUiServices.ModalService,
-                private ModalService: ModalService,
+                private modalService: ModalService,
                 private keysPipe: KeysPipe,
                 private topologyTemplateService: TopologyTemplateService,
-                private translateService: TranslateService) {
+                private translateService: TranslateService,
+                private service: ElementService) {
 
         this.instanceFePropertiesMap = new InstanceFePropertiesMap();
         /* This is the way you can access the component data, please do not use any data except metadata, all other data should be received from the new api calls on the first time
         than if the data is already exist, no need to call the api again - Ask orit if you have any questions*/
         this.component = _stateParams.component;
-        this.EventListenerService.registerObserverCallback(EVENTS.ON_LIFECYCLE_CHANGE, this.onCheckout);
+        this.eventListenerService.registerObserverCallback(EVENTS.ON_LIFECYCLE_CHANGE, this.onCheckout);
         this.updateViewMode();
         this.changedData = [];
         this.updateHasChangedData();
@@ -156,8 +167,7 @@ export class PropertiesAssignmentComponent {
     }
 
     ngOnInit() {
-        console.log("==>" + this.constructor.name + ": ngOnInit");
-        this.btnSelectInputText = this.translateService.translate('SELECT_INPUT_LABEL');
+        console.debug("==>" + this.constructor.name + ": ngOnInit");
         this.loadingInputs = true;
         this.loadingPolicies = true;
         this.loadingInstances = true;
@@ -170,10 +180,18 @@ export class PropertiesAssignmentComponent {
                 this.inputsUtils.resetInputDefaultValue(newInput, input.defaultValue);
                 this.inputs.push(newInput); //only push items that were declared via SDC
             });
+            this.componentInstancePropertyMap = response.componentInstancesProperties;
             this.loadingInputs = false;
 
         }, error => {
         }); //ignore error
+
+        this.topologyTemplateService.getDefaultCustomFunction().toPromise().then((data) => {
+            for (let customFunction of data) {
+                this.customToscaFunctions.push(new CustomToscaFunction(customFunction));
+            }
+        });
+
         this.componentServiceNg2
         .getComponentResourcePropertiesData(this.component)
         .subscribe(response => {
@@ -183,6 +201,16 @@ export class PropertiesAssignmentComponent {
             this.instances.push(...response.groupInstances);
             this.instances.push(...response.policies);
 
+            if (response.componentInstances) {
+                response.componentInstances.forEach(instance => {
+                    this.componentInstanceMap.set(instance.uniqueId, <InstanceFeDetails>{
+                        name: instance.name,
+                        iconClass: instance.iconClass,
+                        originArchived: instance.originArchived
+                    });
+                });
+            }
+
             _.forEach(response.policies, (policy: any) => {
                 const newPolicy: InputFEModel = new InputFEModel(policy);
                 this.inputsUtils.resetInputDefaultValue(newPolicy, policy.defaultValue);
@@ -211,7 +239,19 @@ export class PropertiesAssignmentComponent {
         }, error => {
             this.loadingInstances = false;
         }); //ignore error
+        let modelName = this.component.model ? this.component.model : null;
+        const categoryName= this.component.categories[0].name;
+        if (this.component.categories[0].name != null && this.component.model != null) {
+            this.service.getCategoryBaseTypes(categoryName, modelName).subscribe((response: ListBaseTypesResponse) => {
+                this.doNotExtendBaseType = response.doNotExtendBaseType;
+                this.loadingProperties = false;
 
+            }, error => {
+                //ignore error
+            }, () => {
+                this.loadingProperties = false;
+            });
+        }
         this.stateChangeStartUnregister = this.$scope.$on('$stateChangeStart', (event, toState, toParams) => {
             // stop if has changed properties
             if (this.hasChangedData) {
@@ -224,10 +264,10 @@ export class PropertiesAssignmentComponent {
         });
 
       this.loadDataTypesByComponentModel(this.component.model);
-    };
+    }
 
-    ngOnDestroy() {
-        this.EventListenerService.unRegisterObserver(EVENTS.ON_LIFECYCLE_CHANGE);
+    ngOnDestroy(){
+        this.eventListenerService.unRegisterObserver(EVENTS.ON_LIFECYCLE_CHANGE);
         this.stateChangeStartUnregister();
     }
 
@@ -250,6 +290,31 @@ export class PropertiesAssignmentComponent {
         return this.selectedInstanceData && this.selectedInstanceData.uniqueId == this.component.uniqueId;
     }
 
+    showAddProperties = (): boolean => {
+        if (this.component.isService() && !(<Service>this.component).isSubstituteCandidate()) {
+            return false;
+        } else if (this.hideAddProperties()) {
+            return false;
+        }
+        return this.isSelf();
+
+    }
+
+    hideAddProperties = (): boolean => {
+        if (this.component.isService() && this.doNotExtendBaseType && this.isSelf) {
+            return true;
+        }
+            return false;
+
+    }
+
+    disablePropertyValue = () : boolean => {
+        if (this.component.isService() && this.doNotExtendBaseType && this.isSelf()){
+            return true;
+        }
+        return false;
+    }
+
     getServiceProperties() {
         this.loadingProperties = true;
         this.topologyTemplateService
@@ -342,13 +407,15 @@ export class PropertiesAssignmentComponent {
         //clear selected property from the navigation
         this.selectedFlatProperty = new SimpleFlatProperty();
         this.propertiesNavigationData = [];
+        this.checkedToscaCount = 0;
+        this.enableToscaFunction = false;
     };
 
     /**
      * Entry point handling response from server
      */
     processInstancePropertiesResponse = (instanceBePropertiesMap: InstanceBePropertiesMap, originTypeIsVF: boolean) => {
-        this.instanceFePropertiesMap = this.propertiesUtils.convertPropertiesMapToFEAndCreateChildren(instanceBePropertiesMap, originTypeIsVF, this.inputs); //create flattened children, disable declared props, and init values
+        this.instanceFePropertiesMap = this.propertiesUtils.convertPropertiesMapToFEAndCreateChildren(instanceBePropertiesMap, originTypeIsVF, this.inputs, this.component.model); //create flattened children, disable declared props, and init values
         this.checkedPropertiesCount = 0;
         this.checkedChildPropertiesCount = 0;
     };
@@ -428,7 +495,7 @@ export class PropertiesAssignmentComponent {
      * Handle select node in navigation area, and select the row in table
      */
     onPropertySelectedUpdate = ($event) => {
-        console.log("==>" + this.constructor.name + ": onPropertySelectedUpdate");
+        console.debug("==>" + this.constructor.name + ": onPropertySelectedUpdate");
         this.selectedFlatProperty = $event;
         let parentProperty: PropertyFEModel = this.propertiesService.getParentPropertyFEModelFromPath(this.instanceFePropertiesMap[this.selectedFlatProperty.instanceName], this.selectedFlatProperty.path);
         parentProperty.expandedChildPropertyId = this.selectedFlatProperty.path;
@@ -438,7 +505,7 @@ export class PropertiesAssignmentComponent {
      * When user select row in table, this will prepare the hirarchy object for the tree.
      */
     selectPropertyRow = (propertyRowSelectedEvent: PropertyRowSelectedEvent) => {
-        console.log("==>" + this.constructor.name + ": selectPropertyRow " + propertyRowSelectedEvent.propertyModel.name);
+        console.debug("==>" + this.constructor.name + ": selectPropertyRow " + propertyRowSelectedEvent.propertyModel.name);
         let property = propertyRowSelectedEvent.propertyModel;
         let instanceName = propertyRowSelectedEvent.instanceName;
         this.propertyStructureHeader = null;
@@ -485,7 +552,7 @@ export class PropertiesAssignmentComponent {
             return;
         }
 
-        console.log("==>" + this.constructor.name + ": tabChanged " + event);
+        console.debug("==>" + this.constructor.name + ": tabChanged " + event);
         this.currentMainTab = this.propertyInputTabs.tabs.find((tab) => tab.title === event.title);
         this.isPropertiesTabSelected = this.currentMainTab.title === "Properties";
         this.isInputsTabSelected = this.currentMainTab.title === "Inputs";
@@ -494,99 +561,238 @@ export class PropertiesAssignmentComponent {
         this.searchQuery = '';
     };
 
-    /**Select Properties value from defined input values**/
-    selectInput = (): void => {
-        let instancesIds = this.keysPipe.transform(this.instanceFePropertiesMap, []);
-        angular.forEach(instancesIds, (instanceId: string): void => {
-            let selectedInstanceData: any = this.instances.find(instance => instance.uniqueId == instanceId
-                && instance instanceof ComponentInstance);
-            if (selectedInstanceData) {
-                let checkedProperties: PropertyBEModel[] = this.propertiesService.getCheckedProperties(this.instanceFePropertiesMap[instanceId]);
-                angular.forEach(checkedProperties, (property: PropertyBEModel) => {
-                    this.propertiesService.setCheckedPropertyType(property.type);
-                    if (property.toscaGetFunctionType != null) {
-                        this.loadingProperties = true;
-                        property.getInputValues = null;
-                        property.value = null;
-                        property.toscaGetFunctionType = null;
-                        this.updateInstancePropertiesWithInput(checkedProperties, selectedInstanceData);
-                    } else {
-                        let modalTitle = 'Select value from Input';
-                        const modal = this.ModalService.createCustomModal(new ModalModel(
-                            'sm',
-                            modalTitle,
-                            null,
-                            [
-                                new ButtonModel('Save', 'blue',
-                                    () => {
-                                        this.loadingProperties = true;
-                                        let selectInputValue: InputFEModel = modal.instance.dynamicContent.instance.selectInputValue;
-                                        property.getInputValues = [];
-                                        const propertyInputDetail = new PropertyInputDetail();
-                                        propertyInputDetail.inputId = selectInputValue.uniqueId;
-                                        propertyInputDetail.inputName = selectInputValue.name;
-                                        propertyInputDetail.inputType = selectInputValue.type;
-                                        property.getInputValues.push(propertyInputDetail);
-                                        property.value = selectInputValue.name.indexOf("->") !== -1
-                                            ? '{"get_input":[' + selectInputValue.name.replace("->", ", ") + ']}'
-                                            : '{"get_input":"' + selectInputValue.name+ '"}' ;
-                                        property.toscaGetFunctionType = ToscaGetFunctionType.GET_INPUT;
-                                        this.updateInstancePropertiesWithInput(checkedProperties, selectedInstanceData);
-                                        modal.instance.close();
-                                    }
-                                ),
-                                new ButtonModel('Cancel', 'outline grey', () => {
-                                    modal.instance.close();
-                                }),
-                            ],
-                            null /* type */
-                        )); //modal
-                        this.ModalService.addDynamicContentToModal(modal, InputListComponent);
-                        modal.instance.open();
+    /**
+     * Select Tosca function value from defined values
+     */
+    selectToscaFunctionAndValues = (): void => {
+        const selectedInstanceData: ComponentInstance | GroupInstance | PolicyInstance = this.getSelectedInstance();
+        if (!selectedInstanceData) {
+            return;
+        }
+        this.openToscaGetFunctionModal();
+    }
+
+    private getSelectedInstance(): ComponentInstance | GroupInstance | PolicyInstance {
+        const instancesIds = this.keysPipe.transform(this.instanceFePropertiesMap, []);
+        const instanceId: string = instancesIds[0];
+        return <ComponentInstance | GroupInstance | PolicyInstance> this.instances.find(instance => 
+            instance.uniqueId == instanceId && (instance instanceof ComponentInstance || instance instanceof GroupInstance || instance instanceof PolicyInstance));
+    }
+
+    private buildCheckedInstanceProperty(): PropertyBEModel {
+        return this.buildCheckedInstanceProperties()[0];
+    }
+
+    private buildCheckedInstanceProperties(): PropertyBEModel[] {
+        const instancesIds = this.keysPipe.transform(this.instanceFePropertiesMap, []);
+        const instanceId: string = instancesIds[0];
+        return this.propertiesService.getCheckedProperties(this.instanceFePropertiesMap[instanceId]);
+    }
+
+    private openToscaGetFunctionModal() {
+        const modalTitle = this.translateService.translate('TOSCA_FUNCTION_MODAL_TITLE');
+        const modalButtons = [];
+        let disableSaveButtonFlag = true;
+        const modal = this.modalService.createCustomModal(new ModalModel(
+            'sm',
+            modalTitle,
+            null,
+            modalButtons,
+            null /* type */
+        ));
+        modalButtons.push(new ButtonModel(this.translateService.translate('MODAL_SAVE'), 'blue',
+            () => {
+                const toscaGetFunction: ToscaFunction = modal.instance.dynamicContent.instance.toscaFunctionForm.value;
+                if (toscaGetFunction) {
+                    this.updateCheckedInstancePropertyFunctionValue(toscaGetFunction);
+                } else {
+                    this.clearCheckedInstancePropertyValue();
+                }
+                this.modalService.closeCurrentModal();
+            },
+            (): boolean => { return disableSaveButtonFlag }
+        ));
+        const checkedInstanceProperty = this.buildCheckedInstanceProperty();
+        modalButtons.push(new ButtonModel(this.translateService.translate('MODAL_CANCEL'), 'outline grey', () => {
+            this.modalService.closeCurrentModal();
+        }));
+
+
+        this.modalService.addDynamicContentToModalAndBindInputs(modal, ToscaFunctionComponent, {
+            'property': checkedInstanceProperty,
+            'componentInstanceMap': this.componentInstanceMap,
+            'customToscaFunctions': this.customToscaFunctions
+        });
+        modal.instance.dynamicContent.instance.onValidityChange.subscribe((validationEvent: ToscaFunctionValidationEvent) => {
+            disableSaveButtonFlag = !validationEvent.isValid;
+        });
+        modal.instance.open();
+    }
+
+    private clearCheckedInstancePropertyValue() {
+        const checkedInstanceProperty: PropertyBEModel = this.buildCheckedInstanceProperty();
+        const currentValue : any = checkedInstanceProperty.value;
+        checkedInstanceProperty.getInputValues = null;
+        checkedInstanceProperty.value = null;
+        checkedInstanceProperty.toscaFunction = null;
+        if (checkedInstanceProperty instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel>checkedInstanceProperty).propertiesName){
+            const propertiesNameArray = (<PropertyDeclareAPIModel>checkedInstanceProperty).propertiesName;
+            const parts = propertiesNameArray.split("#");
+            let currentKey = (<DerivedFEProperty>checkedInstanceProperty.input).toscaPath;
+            if (propertiesNameArray.length > 1){
+                const index = checkedInstanceProperty.subPropertyToscaFunctions.findIndex(existingSubPropertyToscaFunction => this.areEqual(existingSubPropertyToscaFunction.subPropertyPath, currentKey.length > 0 ? currentKey : parts.slice(1)));
+                checkedInstanceProperty.subPropertyToscaFunctions.splice(index, 1);
+            }
+            if (this.enableToscaFunction) {
+                this.processSubtoscaFunction(checkedInstanceProperty,null);
+                return;
+            }
+        }
+        if (this.selectedInstanceData instanceof ComponentInstance) {
+            var toRemove = this.changedData.filter(obj => {
+                return obj.name == checkedInstanceProperty.name && obj.type == checkedInstanceProperty.type && obj.value == null;
+            });
+            const index: number = this.changedData.indexOf(toRemove[0]);
+            if (index !== -1) {
+                this.changedData.splice(index, 1);
+            }
+            this.updateInstanceProperty(checkedInstanceProperty);
+        } else if (this.selectedInstanceData instanceof GroupInstance) {
+            this.updateGroupInstanceProperty(checkedInstanceProperty);
+        } else if (this.selectedInstanceData instanceof PolicyInstance) {
+            this.updatePolicyInstanceProperty(checkedInstanceProperty);
+        }
+    }
+
+    private processSubtoscaFunction(checkedProperty : PropertyDeclareAPIModel, toscaFunction: ToscaFunction) {
+        const instancesIds = this.keysPipe.transform(this.instanceFePropertiesMap, []);
+        const instanceId: string = instancesIds[0];
+        this.instanceFePropertiesMap[instanceId].forEach(prop => {
+            if (prop.flattenedChildren) {
+                prop.flattenedChildren.forEach((child) => {
+                    if (child.isSelected && !child.isDeclared && !child.isDisabled) {
+                        prop.subPropertyToscaFunctions = checkedProperty.subPropertyToscaFunctions;
+                        if (toscaFunction) {
+                            child.value = toscaFunction.buildValueString();
+                            child.valueObj = toscaFunction.buildValueObject();
+                            child.toscaFunction = toscaFunction;
+                            this.hasChangedData = true;
+                            if (this.changedData.length == 0) {
+                                this.changedData.push(prop);
+                            }
+                        } else {
+                            child.valueObj = null;
+                            child.toscaFunction = null;
+                        }
+                        child.isSelected = false;
+                        this.togggleToscaBtn(false);                                
                     }
                 });
             }
         });
-    };
+    }
+
+    private updateCheckedInstancePropertyFunctionValue(toscaFunction: ToscaFunction) {
+        const checkedProperty: PropertyBEModel = this.buildCheckedInstanceProperty();
+        if (checkedProperty instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel>checkedProperty).propertiesName){
+            const propertiesName = (<PropertyDeclareAPIModel>checkedProperty).propertiesName;
+            const parts = propertiesName.split("#");
+            let currentKey = (<DerivedFEProperty>checkedProperty.input).toscaPath;
+            if (checkedProperty.subPropertyToscaFunctions == null){
+                checkedProperty.subPropertyToscaFunctions = [];
+            }
+            let subPropertyToscaFunction = checkedProperty.subPropertyToscaFunctions.find(existingSubPropertyToscaFunction => this.areEqual(existingSubPropertyToscaFunction.subPropertyPath, currentKey.length > 0 ? currentKey : parts.slice(1)));
+            if (!subPropertyToscaFunction){
+                 subPropertyToscaFunction = new SubPropertyToscaFunction();
+                 checkedProperty.subPropertyToscaFunctions.push(subPropertyToscaFunction);
+            }
+            subPropertyToscaFunction.toscaFunction = toscaFunction;
+            subPropertyToscaFunction.subPropertyPath = currentKey.length > 0 ? currentKey : parts.slice(1);
+            if (this.enableToscaFunction) {
+                this.processSubtoscaFunction(checkedProperty,toscaFunction);
+                return;
+            }
+        } else {
+            checkedProperty.subPropertyToscaFunctions = null;
+            checkedProperty.toscaFunction = toscaFunction;
+        }
+        if (this.selectedInstanceData instanceof ComponentInstance) {
+            this.updateInstanceProperty(checkedProperty);
+        } else if (this.selectedInstanceData instanceof GroupInstance) {
+            this.updateGroupInstanceProperty(checkedProperty);
+        } else if (this.selectedInstanceData instanceof PolicyInstance) {
+            this.updatePolicyInstanceProperty(checkedProperty);
+        }
+    }
+
+    private isComplexSchemaType(propertyType: string): boolean {
+        return PROPERTY_DATA.SIMPLE_TYPES.indexOf(propertyType) === -1;
+    }
+
+    private isListOrMap(propertyType: string): boolean {
+        return PROPERTY_TYPES.MAP === propertyType || PROPERTY_TYPES.LIST === propertyType;
+    }
+
+    private areEqual(array1: string[], array2: string[]): boolean {
+        return array1.length === array2.length && array1.every(function(value, index) { return value === array2[index]})
+    }
+
+    updateInstanceProperty(instanceProperty: PropertyBEModel) {
+        this.loadingProperties = true;
+        this.enableToscaFunction = false;
+        this.checkedToscaCount = 0;
 
-    updateInstancePropertiesWithInput(checkedProperties: PropertyBEModel[], selectedInstanceData: any) {
         this.componentInstanceServiceNg2.updateInstanceProperties(this.component.componentType, this.component.uniqueId,
-            this.selectedInstanceData.uniqueId, checkedProperties)
+            this.selectedInstanceData.uniqueId, [instanceProperty])
         .subscribe(() => {
-            this.changeSelectedInstance(selectedInstanceData);
+            this.changeSelectedInstance(this.getSelectedInstance());
         }, (error) => {
-            this.Notification.error({
-                message: 'Failed to select/deselect get_input call: ' + error,
-                title: 'Failure'
-            });
+            this.loadingProperties = false;
+            console.error(error);
         }, () => {
             this.loadingProperties = false;
-            this.btnSelectInputText = this.translateService.translate('SELECT_INPUT_LABEL');
         });
     }
 
-    selectInputBtnLabel = () => {
-        let instancesIds = this.keysPipe.transform(this.instanceFePropertiesMap, []);
-        angular.forEach(instancesIds, (instanceId: string): void => {
-            let checkedProperties: PropertyBEModel[] = this.propertiesService.getCheckedProperties(this.instanceFePropertiesMap[instanceId]);
-            angular.forEach(checkedProperties, (property: PropertyBEModel) => {
-                if(this.checkedPropertiesCount == 1) {
-                    if (property.toscaGetFunctionType == null) {
-                        this.btnSelectInputText = this.translateService.translate('SELECT_INPUT_LABEL');
-                    } else {
-                        this.btnSelectInputText = this.translateService.translate('DESELECT_INPUT_LABEL');
-                    }
-                } else {
-                    this.btnSelectInputText = this.translateService.translate('SELECT_INPUT_LABEL');
-                }
-            });
+    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);
+        }, () => {
+            this.loadingProperties = false;
+        });
+    }
+
+    updatePolicyInstanceProperty(instanceProperty: PropertyBEModel) {
+        this.loadingProperties = true;
+        this.componentInstanceServiceNg2.updateComponentPolicyInstanceProperties(this.component.componentType, this.component.uniqueId,
+            this.selectedInstanceData.uniqueId, [instanceProperty])
+        .subscribe(() => {
+            this.changeSelectedInstance(this.getSelectedInstance());
+        }, (error) => {
+            this.loadingProperties = false;
+            console.error(error);
+        }, () => {
+            this.loadingProperties = false;
         });
     }
 
+    declareInput = (): void => {
+        if (this.checkedPropertiesCount == 1) {
+            this.openAddInputNameAndDeclareInputModal();
+        } else if (this.checkedPropertiesCount > 1) {
+            this.declareInputFromProperties();
+        }
+    }
 
     /*** DECLARE PROPERTIES/INPUTS ***/
-    declareProperties = (): void => {
-        console.log("==>" + this.constructor.name + ": declareProperties");
+    declareInputFromProperties = (inputName?: string): void => {
+        console.debug("==>" + this.constructor.name + ": declareProperties");
 
         let selectedComponentInstancesProperties: InstanceBePropertiesMap = new InstanceBePropertiesMap();
         let selectedGroupInstancesProperties: InstanceBePropertiesMap = new InstanceBePropertiesMap();
@@ -600,6 +806,9 @@ export class PropertiesAssignmentComponent {
                 if (!this.isInput(selectedInstanceData.originType)) {
                     // convert Property FE model -> Property BE model, extract only checked
                     selectedComponentInstancesProperties[instanceId] = this.propertiesService.getCheckedProperties(this.instanceFePropertiesMap[instanceId]);
+                    if (inputName) {
+                        selectedComponentInstancesProperties[instanceId][0].inputName = inputName;
+                    }
                 } else {
                     selectedComponentInstancesInputs[instanceId] = this.propertiesService.getCheckedProperties(this.instanceFePropertiesMap[instanceId]);
                 }
@@ -641,6 +850,8 @@ export class PropertiesAssignmentComponent {
         this.topologyTemplateService
             .createInput(this.component, inputsToCreate, this.isSelf())
             .subscribe((response) => {
+                this.selectInstanceRow(SERVICE_SELF_TITLE);
+                this.onInstanceSelectedUpdate(this.instances[0]);
                 this.setInputTabIndication(response.length);
                 this.checkedPropertiesCount = 0;
                 this.checkedChildPropertiesCount = 0;
@@ -656,9 +867,64 @@ export class PropertiesAssignmentComponent {
             }, error => {}); //ignore error
     };
 
-    declareListProperties = (): void => {
-        console.log('declareListProperties() - enter');
+    generateDefaultInputName = (): string => {
+        let defaultInputName: string;
+        let instancesIds = this.keysPipe.transform(this.instanceFePropertiesMap, []);
+        angular.forEach(instancesIds, (instanceId: string) => {
+            let selectedProperty: PropertyBEModel = new PropertyBEModel(this.propertiesService.getCheckedProperties(this.instanceFePropertiesMap[instanceId])[0]);
+            let selectedInstanceData: any = this.instances.find(instance => instance.uniqueId == instanceId);
+            defaultInputName = this.generateInputName(selectedInstanceData.invariantName, selectedProperty.name);
+        });
+        return defaultInputName;
+    }
 
+    private generateInputName = (componentName: string, propertyName: string): string => {
+        let inputName: string;
+        if (propertyName) {
+            if (propertyName.includes("::")) {
+                propertyName = propertyName.replace(/::/g, "_");
+            }
+            if (componentName) {
+                inputName = componentName + "_" + propertyName;
+            } else {
+                inputName = propertyName;
+            }
+        }
+        return inputName;
+    }
+
+    private openAddInputNameAndDeclareInputModal = (): void => {
+        const modalTitle = this.translateService.translate('ADD_INPUT_NAME_TO_DECLARE');
+        const modalButtons = [];
+        const modal = this.modalService.createCustomModal(new ModalModel(
+            'sm',
+            modalTitle,
+            null,
+            modalButtons,
+            null /* type */
+        ));
+        modalButtons.push(new ButtonModel(this.translateService.translate('MODAL_SAVE'), 'blue',
+            () => {
+                const inputName: string = modal.instance.dynamicContent.instance.inputNameForm.value;
+                if (inputName) {
+                    this.declareInputFromProperties(inputName);
+                } else {
+                    this.notification.warning({
+                        message: 'Failed to set input name',
+                        title: 'Warning'
+                    });
+                }
+                this.modalService.closeCurrentModal();
+            }
+        ));
+        modalButtons.push(new ButtonModel(this.translateService.translate('MODAL_CANCEL'), 'outline grey', () => {
+            this.modalService.closeCurrentModal();
+        }));
+        this.modalService.addDynamicContentToModal(modal, DeclareInputComponent, {defaultInputName: this.generateDefaultInputName()});
+        modal.instance.open();
+    }
+
+    declareListProperties = (): void => {
         // get selected properties
         let selectedComponentInstancesProperties: InstanceBePropertiesMap = new InstanceBePropertiesMap();
         let selectedGroupInstancesProperties: InstanceBePropertiesMap = new InstanceBePropertiesMap();
@@ -669,7 +935,6 @@ export class PropertiesAssignmentComponent {
         let insId :string;
 
         angular.forEach(instancesIds, (instanceId: string): void => {
-            console.log("instanceId="+instanceId);
             insId = instanceId;
             let selectedInstanceData: any = this.instances.find(instance => instance.uniqueId == instanceId);
             let checkedProperties: PropertyBEModel[] = this.propertiesService.getCheckedProperties(this.instanceFePropertiesMap[instanceId]);
@@ -695,7 +960,7 @@ export class PropertiesAssignmentComponent {
         let inputsToCreate: InstancePropertiesAPIMap = new InstancePropertiesAPIMap(selectedComponentInstancesInputs, selectedComponentInstancesProperties, selectedGroupInstancesProperties, selectedPolicyInstancesProperties);
 
         let modalTitle = 'Declare Properties as List Input';
-        const modal = this.ModalService.createCustomModal(new ModalModel(
+        const modal = this.modalService.createCustomModal(new ModalModel(
             'sm', /* size */
             modalTitle, /* title */
             null, /* content */
@@ -738,7 +1003,6 @@ export class PropertiesAssignmentComponent {
                             componentInstInputsMap: content.inputsToCreate,
                             listInput: reglistInput
                         };
-                        console.log("save button clicked. input=", input);
 
                         this.topologyTemplateService
                         .createListInput(this.component, input, this.isSelf())
@@ -769,9 +1033,8 @@ export class PropertiesAssignmentComponent {
             null /* type */
         ));
         // 3rd arg is passed to DeclareListComponent instance
-        this.ModalService.addDynamicContentToModal(modal, DeclareListComponent, {properties: inputsToCreate, propertyNameList: propertyNameList});
+        this.modalService.addDynamicContentToModal(modal, DeclareListComponent, {properties: inputsToCreate, propertyNameList: propertyNameList});
         modal.instance.open();
-        console.log('declareListProperties() - leave');
     };
 
      /*** DECLARE PROPERTIES/POLICIES ***/
@@ -865,11 +1128,9 @@ export class PropertiesAssignmentComponent {
                                 const changedProp = <PropertyFEModel>this.changedData.shift();
                                 this.propertiesUtils.resetPropertyValue(changedProp, resInput.value);
                             });
-                            console.log('updated instance inputs:', response);
                         };
                     } else {
                         if (this.isSelf()) {
-                            console.log("changedProperties", changedProperties);
                             request = this.topologyTemplateService.updateServiceProperties(this.component.uniqueId,  _.map(changedProperties, cp => {
                                 delete cp.constraints;
                                 return cp;
@@ -885,7 +1146,6 @@ export class PropertiesAssignmentComponent {
                                 this.propertiesUtils.resetPropertyValue(changedProp, resProp.value);
                             });
                             resolve(response);
-                            console.log("updated instance properties: ", response);
                         };
                     }
                 } else if (this.selectedInstanceData instanceof GroupInstance) {
@@ -898,7 +1158,6 @@ export class PropertiesAssignmentComponent {
                             this.propertiesUtils.resetPropertyValue(changedProp, resProp.value);
                         });
                         resolve(response);
-                        console.log("updated group instance properties: ", response);
                     };
                 } else if (this.selectedInstanceData instanceof PolicyInstance) {
                     request = this.componentInstanceServiceNg2
@@ -910,7 +1169,6 @@ export class PropertiesAssignmentComponent {
                             this.propertiesUtils.resetPropertyValue(changedProp, resProp.value);
                         });
                         resolve(response);
-                        console.log("updated policy instance properties: ", response);
                     };
                 }
             } else if (this.isInputsTabSelected) {
@@ -931,7 +1189,6 @@ export class PropertiesAssignmentComponent {
                         changedInput.required = resInput.required;
                         changedInput.requiredOrig = resInput.required;
                     });
-                    console.log("updated the component inputs and got this response: ", response);
                 }
             }
 
@@ -996,9 +1253,9 @@ export class PropertiesAssignmentComponent {
         if (curHasChangedData !== this.hasChangedData) {
             this.hasChangedData = curHasChangedData;
             if(this.hasChangedData) {
-                this.EventListenerService.notifyObservers(EVENTS.ON_WORKSPACE_UNSAVED_CHANGES, this.hasChangedData, this.showUnsavedChangesAlert);
+                this.eventListenerService.notifyObservers(EVENTS.ON_WORKSPACE_UNSAVED_CHANGES, this.hasChangedData, this.showUnsavedChangesAlert);
             } else {
-                this.EventListenerService.notifyObservers(EVENTS.ON_WORKSPACE_UNSAVED_CHANGES, false);
+                this.eventListenerService.notifyObservers(EVENTS.ON_WORKSPACE_UNSAVED_CHANGES, false);
             }
         } 
         return this.hasChangedData;
@@ -1007,14 +1264,14 @@ export class PropertiesAssignmentComponent {
     doSaveChangedData = (onSuccessFunction?:Function, onError?:Function):void => {
         this.saveChangedData().then(
             () => {
-                this.Notification.success({
+                this.notification.success({
                     message: 'Successfully saved changes',
                     title: 'Saved'
                 });
                 if(onSuccessFunction) onSuccessFunction();
             },
             () => {
-                this.Notification.error({
+                this.notification.error({
                     message: 'Failed to save changes!',
                     title: 'Failure'
                 });
@@ -1066,14 +1323,24 @@ export class PropertiesAssignmentComponent {
     //used for declare button, to keep count of newly checked properties (and ignore declared properties)
     updateCheckedPropertyCount = (increment: boolean): void => {
         this.checkedPropertiesCount += (increment) ? 1 : -1;
-        console.log("CheckedProperties count is now.... " + this.checkedPropertiesCount);
-        this.selectInputBtnLabel();
+        this.checkedToscaCount = 0;
+        this.enableToscaFunction = false;
+        console.debug("CheckedProperties count is now.... " + this.checkedPropertiesCount);
     };
 
     updateCheckedChildPropertyCount = (increment: boolean): void => {
         this.checkedChildPropertiesCount += (increment) ? 1 : -1;
     };
 
+    togggleToscaBtn = (toscaFlag: boolean) : void => {
+        this.checkedToscaCount += toscaFlag ? 1 : -1;
+        if(this.checkedToscaCount == 1){
+            this.enableToscaFunction = true;
+        }else{
+            this.enableToscaFunction = false;
+        }
+    };
+
     setInputTabIndication = (numInputs: number): void => {
         this.propertyInputTabs.setTabIndication('Inputs', numInputs);
     };
@@ -1092,7 +1359,7 @@ export class PropertiesAssignmentComponent {
         //reset any unsaved changes to the input before deleting it
         this.resetUnsavedChangesForInput(input);
 
-        console.log("==>" + this.constructor.name + ": deleteInput");
+        console.debug("==>" + this.constructor.name + ": deleteInput");
         let inputToDelete = new InputBEModel(input);
 
         this.componentServiceNg2
@@ -1125,7 +1392,6 @@ export class PropertiesAssignmentComponent {
             .deletePolicy(this.component, policy)
             .subscribe((response) => {
                 this.policies = this.policies.filter(policy => policy.uniqueId !== response.uniqueId);
-                //Reload the whole instance for now - TODO: CHANGE THIS after the BE starts returning properties within the response, use commented code below instead!
                 this.changeSelectedInstance(this.selectedInstanceData);
                 this.loadingPolicies = false;
             });
@@ -1151,7 +1417,7 @@ export class PropertiesAssignmentComponent {
     addProperty = (model: string) => {
         this.loadDataTypesByComponentModel(model)
         let modalTitle = 'Add Property';
-        let modal = this.ModalService.createCustomModal(new ModalModel(
+        let modal = this.modalService.createCustomModal(new ModalModel(
             'sm',
             modalTitle,
             null,
@@ -1167,7 +1433,7 @@ export class PropertiesAssignmentComponent {
                             modal.instance.close();
                         }, (error) => {
                             modal.instance.dynamicContent.instance.isLoading = false;
-                            this.Notification.error({
+                            this.notification.error({
                                 message: 'Failed to add property:' + error,
                                 title: 'Failure'
                             });
@@ -1180,13 +1446,13 @@ export class PropertiesAssignmentComponent {
             null
         ));
         modal.instance.open();
-        this.ModalService.addDynamicContentToModal(modal, PropertyCreatorComponent, {});
+        this.modalService.addDynamicContentToModal(modal, PropertyCreatorComponent, {});
     }
 
     /*** addInput ***/
     addInput = () => {
         let modalTitle = 'Add Input';
-        let modal = this.ModalService.createCustomModal(new ModalModel(
+        let modal = this.modalService.createCustomModal(new ModalModel(
             'sm',
             modalTitle,
             null,
@@ -1202,7 +1468,7 @@ export class PropertiesAssignmentComponent {
                             modal.instance.close();
                         }, (error) => {
                             modal.instance.dynamicContent.instance.isLoading = false;
-                            this.Notification.error({
+                            this.notification.error({
                                 message: 'Failed to add input:' + error,
                                 title: 'Failure'
                             });
@@ -1214,7 +1480,7 @@ export class PropertiesAssignmentComponent {
             ],
             null
         ));
-        this.ModalService.addDynamicContentToModal(modal, PropertyCreatorComponent, {});
+        this.modalService.addDynamicContentToModal(modal, PropertyCreatorComponent, {});
         modal.instance.open();
     }