dc9c82d8aadde0177707c8445d18923f223f60ba
[sdc.git] / catalog-ui / src / app / view-models / forms / property-forms / component-property-form / property-form-view-model.ts
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 'use strict';
22 import * as _ from "lodash";
23 import {FormState, PROPERTY_DATA, PROPERTY_TYPES, PROPERTY_VALUE_CONSTRAINTS, ValidationUtils} from "app/utils";
24 import {DataTypesService} from "app/services";
25 import {DataTypesMap, PropertyModel, InputBEModel, Component, InputFEModel} from "app/models";
26 import {ComponentInstance} from "../../../../models/componentsInstances/componentInstance";
27 import {ComponentInstanceServiceNg2} from "app/ng2/services/component-instance-services/component-instance.service";
28 import {ComponentServiceNg2} from "app/ng2/services/component-services/component.service";
29 import {SdcUiCommon, SdcUiComponents, SdcUiServices} from "onap-ui-angular";
30 import {CompositionService} from "app/ng2/pages/composition/composition.service";
31 import {WorkspaceService} from "app/ng2/pages/workspace/workspace.service";
32 import {Observable} from "rxjs";
33 import {TopologyTemplateService} from "app/ng2/services/component-services/topology-template.service";
34 import {InstanceFeDetails} from "../../../../models/instance-fe-details";
35 import {ToscaGetFunction} from "../../../../models/tosca-get-function";
36 import {ToscaFunctionValidationEvent} from "../../../../ng2/pages/properties-assignment/tosca-function/tosca-function.component";
37
38 export interface IEditPropertyModel {
39     property:PropertyModel;
40     types:Array<string>;
41     simpleTypes:Array<string>;
42     hasGetFunctionValue: boolean;
43     isGetFunctionValid: boolean;
44 }
45
46 interface IPropertyFormViewModelScope extends ng.IScope {
47     forms:any;
48     editForm:ng.IFormController;
49     footerButtons:Array<any>;
50     isNew:boolean;
51     nameMaxLength:number;
52     isLoading:boolean;
53     componentMetadata: { isService: boolean, isVfc: boolean }
54     validationPattern:RegExp;
55     propertyNameValidationPattern:RegExp;
56     commentValidationPattern:RegExp;
57     editPropertyModel: IEditPropertyModel;
58     componentInstanceMap: Map<string, InstanceFeDetails>;
59     modalInstanceProperty:ng.ui.bootstrap.IModalServiceInstance;
60     currentPropertyIndex:number;
61     isLastProperty:boolean;
62     myValue:any;
63     nonPrimitiveTypes:Array<string>;
64     dataTypes:DataTypesMap;
65     isTypeDataType:boolean;
66     maxLength:number;
67     isViewOnly:boolean;
68     isPropertyValueOwner:boolean;
69     isVnfConfiguration:boolean;
70     constraints:string[];
71     modelNameFilter:string;
72     isGetFunctionValueType: boolean;
73     invalidMandatoryFields: boolean;
74
75     validateJson(json:string):boolean;
76     save(doNotCloseModal?:boolean):void;
77     getValidationPattern(type:string):RegExp;
78     validateIntRange(value:string):boolean;
79     close():void;
80     onSchemaTypeChange():void;
81     onTypeChange(resetSchema:boolean):void;
82     showSchema():boolean;
83     delete(property:PropertyModel):void;
84     getPrev():void;
85     getNext():void;
86     isSimpleType(typeName:string):boolean;
87     getDefaultValue():any;
88     onValueTypeChange(): void;
89 }
90
91 export class PropertyFormViewModel {
92
93     static '$inject' = [
94         '$scope',
95         'Sdc.Services.DataTypesService',
96         '$uibModalInstance',
97         'property',
98         'ValidationPattern',
99         'PropertyNameValidationPattern',
100         'CommentValidationPattern',
101         'ValidationUtils',
102         'component',
103         '$filter',
104         'ModalServiceSdcUI',
105         'filteredProperties',
106         '$timeout',
107         'isViewOnly',
108         'isPropertyValueOwner',
109         'propertyOwnerType',
110         'propertyOwnerId',
111         'ComponentInstanceServiceNg2',
112         'ComponentServiceNg2',
113         'TopologyTemplateService',
114         'CompositionService',
115         'workspaceService',
116         'inputProperty'
117     ];
118
119     private formState:FormState;
120
121     constructor(private $scope:IPropertyFormViewModelScope,
122                 private DataTypesService:DataTypesService,
123                 private $uibModalInstance:ng.ui.bootstrap.IModalServiceInstance,
124                 private property:PropertyModel,
125                 private ValidationPattern:RegExp,
126                 private PropertyNameValidationPattern:RegExp,
127                 private CommentValidationPattern:RegExp,
128                 private ValidationUtils:ValidationUtils,
129                 private component:Component,
130                 private $filter:ng.IFilterService,
131                 private modalService:SdcUiServices.ModalService,
132                 private filteredProperties:Array<PropertyModel>,
133                 private $timeout:ng.ITimeoutService,
134                 private isViewOnly:boolean,
135                 private isPropertyValueOwner:boolean,
136                 private propertyOwnerType:string,
137                 private propertyOwnerId:string,
138                 private ComponentInstanceServiceNg2: ComponentInstanceServiceNg2,
139                 private ComponentServiceNg2: ComponentServiceNg2,
140                 private topologyTemplateService: TopologyTemplateService,
141                 private compositionService: CompositionService,
142                 private workspaceService: WorkspaceService,
143                 private inputProperty : InputFEModel) {
144
145         this.formState = angular.isDefined(property.name) ? FormState.UPDATE : FormState.CREATE;
146         this.initScope();
147     }
148
149     private initResource = ():void => {
150         this.$scope.editPropertyModel.property = new PropertyModel(this.property);
151         this.$scope.editPropertyModel.property.type = this.property.type ? this.property.type : null;
152         this.$scope.editPropertyModel.property.value = this.property.value ? this.property.value : this.property.defaultValue;
153         this.$scope.constraints = this.property.constraints && this.property.constraints[0] ? this.property.constraints[0]["validValues"] : null;
154         this.initToscaGetFunction();
155         this.setMaxLength();
156     };
157
158     private initToscaGetFunction() {
159         this.$scope.editPropertyModel.hasGetFunctionValue = this.$scope.editPropertyModel.property.isToscaFunction();
160         this.$scope.editPropertyModel.isGetFunctionValid = true;
161     }
162
163     private isDataTypeForPropertyType = (property:PropertyModel):boolean=> {
164         property.simpleType = "";
165         if (property.type && PROPERTY_DATA.TYPES.indexOf(property.type) > -1) {
166             return false;
167         }
168         let simpleType = this.getTypeForDataTypeDerivedFromSimple(property.type);
169         if (simpleType) {
170             property.simpleType = simpleType;
171             return false;
172         }
173         return true;
174     };
175
176     private getTypeForDataTypeDerivedFromSimple = (dataTypeName:string):string => {
177         if (!this.$scope.dataTypes[dataTypeName]) {
178             return 'string';
179         }
180         if (this.$scope.dataTypes[dataTypeName].derivedFromName == "tosca.datatypes.Root" || this.$scope.dataTypes[dataTypeName].properties) {
181             return null;
182         }
183         if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.$scope.dataTypes[dataTypeName].derivedFromName) > -1) {
184             return this.$scope.dataTypes[dataTypeName].derivedFromName
185         }
186         return this.getTypeForDataTypeDerivedFromSimple(this.$scope.dataTypes[dataTypeName].derivedFromName);
187     };
188
189     private initForNotSimpleType = ():void => {
190         const property = this.$scope.editPropertyModel.property;
191         this.$scope.isTypeDataType = this.DataTypesService.isDataTypeForPropertyType(this.$scope.editPropertyModel.property);
192         if (property.isToscaFunction()) {
193             this.initValueForGetFunction();
194             return;
195         }
196
197         if (this.isComplexType(property.type)) {
198             if (property.value || property.defaultValue) {
199                 this.$scope.myValue = JSON.parse(property.value || property.defaultValue);
200             } else {
201                 this.initEmptyComplexValue(property.type);
202             }
203         }
204     };
205
206     private initValueForGetFunction(): void {
207         const property = this.$scope.editPropertyModel.property;
208         if (property.defaultValue) {
209             this.$scope.myValue = JSON.parse(property.defaultValue);
210             return;
211         }
212         if (this.isComplexType(property.type)) {
213             this.initEmptyComplexValue(property.type);
214             return;
215         }
216
217         this.$scope.myValue = undefined;
218     }
219
220     private initComponentInstanceMap() {
221         this.$scope.componentInstanceMap = new Map<string, InstanceFeDetails>();
222         if (this.compositionService.componentInstances) {
223             this.compositionService.componentInstances.forEach(value => {
224                 this.$scope.componentInstanceMap.set(value.uniqueId, <InstanceFeDetails>{
225                     name: value.name
226                 });
227             });
228         }
229     }
230
231     private initEmptyComplexValue(type: string): any {
232         switch (type) {
233             case PROPERTY_TYPES.MAP:
234                 this.$scope.myValue = {'': null};
235                 break;
236             case PROPERTY_TYPES.LIST:
237                 this.$scope.myValue = [];
238                 break;
239             default:
240                 this.$scope.myValue = {};
241         }
242     }
243
244     private isComplexType(type: string): boolean {
245         if (!type) {
246             return false;
247         }
248         return PROPERTY_DATA.SIMPLE_TYPES.indexOf(type) == -1;
249     }
250
251     private setMaxLength = ():void => {
252         switch (this.$scope.editPropertyModel.property.type) {
253             case PROPERTY_TYPES.MAP:
254             case PROPERTY_TYPES.LIST:
255                 this.$scope.maxLength = this.$scope.editPropertyModel.property.schema.property.type == PROPERTY_TYPES.JSON ?
256                     PROPERTY_VALUE_CONSTRAINTS.JSON_MAX_LENGTH :
257                     PROPERTY_VALUE_CONSTRAINTS.MAX_LENGTH;
258                 break;
259             case PROPERTY_TYPES.JSON:
260                 this.$scope.maxLength = PROPERTY_VALUE_CONSTRAINTS.JSON_MAX_LENGTH;
261                 break;
262             default:
263                 this.$scope.maxLength =PROPERTY_VALUE_CONSTRAINTS.MAX_LENGTH;
264         }
265     };
266
267
268     private initScope = ():void => {
269
270         //scope properties
271         this.$scope.isViewOnly = this.isViewOnly;
272         this.$scope.isLoading = true;
273         this.$scope.forms = {};
274         this.$scope.validationPattern = this.ValidationPattern;
275         this.$scope.propertyNameValidationPattern = this.PropertyNameValidationPattern;
276         this.$scope.commentValidationPattern = this.CommentValidationPattern;
277         this.$scope.nameMaxLength = PROPERTY_VALUE_CONSTRAINTS.NAME_MAX_LENGTH;
278         this.$scope.isNew = (this.formState === FormState.CREATE);
279         this.$scope.componentMetadata = {
280             isService: this.workspaceService.metadata.isService(),
281             isVfc: this.workspaceService.metadata.isVfc()
282         }
283         this.$scope.modalInstanceProperty = this.$uibModalInstance;
284         this.$scope.currentPropertyIndex = _.findIndex(this.filteredProperties, i=> i.name == this.property.name);
285         this.$scope.isLastProperty = this.$scope.currentPropertyIndex == (this.filteredProperties.length - 1);
286         const property = new PropertyModel(this.property);
287         this.$scope.editPropertyModel = {
288             'property': property,
289             types: PROPERTY_DATA.TYPES,
290             simpleTypes: PROPERTY_DATA.SIMPLE_TYPES,
291             hasGetFunctionValue: property.isToscaFunction(),
292             isGetFunctionValid: true,
293         };
294         this.$scope.isPropertyValueOwner = this.isPropertyValueOwner;
295         this.$scope.propertyOwnerType = this.propertyOwnerType;
296         this.$scope.modelNameFilter = this.workspaceService.metadata.model;
297         //check if property of VnfConfiguration
298         this.$scope.isVnfConfiguration = false;
299         if(this.propertyOwnerType == "component" && angular.isArray(this.compositionService.componentInstances)) {
300             const componentPropertyOwner:ComponentInstance = this.compositionService.componentInstances.find((ci:ComponentInstance) => {
301                 return ci.uniqueId === this.property.resourceInstanceUniqueId;
302             });
303             if (componentPropertyOwner && componentPropertyOwner.componentName === 'vnfConfiguration') {
304                 this.$scope.isVnfConfiguration = true;
305             }
306         }
307         this.initResource();
308         this.initForNotSimpleType();
309         this.initComponentInstanceMap();
310
311         this.$scope.validateJson = (json:string):boolean => {
312             if (!json) {
313                 return true;
314             }
315             return this.ValidationUtils.validateJson(json);
316         };
317
318         this.DataTypesService.fetchDataTypesByModel(this.workspaceService.metadata.model).then(response => {
319             this.$scope.dataTypes = response.data as DataTypesMap;
320
321             this.$scope.nonPrimitiveTypes = _.filter(Object.keys(this.$scope.dataTypes), (type:string)=> {
322                 return this.$scope.editPropertyModel.types.indexOf(type) == -1;
323             });
324             this.$scope.isLoading = false;
325         });
326
327         //scope methods
328         this.$scope.save = (doNotCloseModal?:boolean):void => {
329             let property:PropertyModel = this.$scope.editPropertyModel.property;
330             this.$scope.isLoading = true;
331             if (property.propertyView){
332                 if (property.constraints.length == 0) {
333                     return;
334                 }
335                 let input : InputBEModel = this.inputProperty;
336                 input.constraints = property.constraints;
337                 this.ComponentServiceNg2.updateComponentInputs(this.component, [input]).subscribe(
338                     (response) => {
339                         console.debug("Input property updated");
340                         this.$uibModalInstance.close();
341                     },
342                     (error) => {
343                         console.debug("Failed to update input property");
344                         this.$uibModalInstance.close();
345                     }
346                 );
347                 return;
348             }
349             this.$scope.editPropertyModel.property.description = this.ValidationUtils.stripAndSanitize(this.$scope.editPropertyModel.property.description);
350             //if read only - or no changes made - just closes the modal
351             //need to check for property.value changes manually to detect if map properties deleted
352             if ((this.$scope.editPropertyModel.property.readonly && !this.$scope.isPropertyValueOwner)
353                 || (!this.$scope.forms.editForm.$dirty && angular.equals(JSON.stringify(this.$scope.myValue), this.$scope.editPropertyModel.property.value))) {
354                 this.$uibModalInstance.close();
355                 return;
356             }
357
358             this.$scope.isLoading = true;
359
360             let onPropertyFailure = (response):void => {
361                 console.error('Failed to update property', response);
362                 this.$scope.isLoading = false;
363             };
364
365             let onPropertySuccess = (propertyFromBE:PropertyModel):void => {
366                 this.$scope.isLoading = false;
367                 this.filteredProperties[this.$scope.currentPropertyIndex] = propertyFromBE;
368                 if (!doNotCloseModal) {
369                     this.$uibModalInstance.close(propertyFromBE);
370                 } else {
371                     this.$scope.forms.editForm.$setPristine();
372                     this.$scope.editPropertyModel.property = new PropertyModel();
373                 }
374             };
375
376             //Not clean, but doing this as a temporary fix until we update the property right panel modals
377             if (this.propertyOwnerType === "group"){
378                 this.ComponentInstanceServiceNg2.updateComponentGroupInstanceProperties(this.workspaceService.metadata.componentType, this.workspaceService.metadata.uniqueId, this.propertyOwnerId, [property])
379                     .subscribe((propertiesFromBE) => { onPropertySuccess(<PropertyModel>propertiesFromBE[0])}, error => onPropertyFailure(error));
380             } else if (this.propertyOwnerType === "policy"){
381                 if (!this.$scope.editPropertyModel.property.simpleType &&
382                     !this.$scope.isSimpleType(this.$scope.editPropertyModel.property.type) &&
383                     !_.isNil(this.$scope.myValue)) {
384                     property.value = JSON.stringify(this.$scope.myValue);
385                 }
386                 this.ComponentInstanceServiceNg2.updateComponentPolicyInstanceProperties(this.workspaceService.metadata.componentType, this.workspaceService.metadata.uniqueId, this.propertyOwnerId, [property])
387                     .subscribe((propertiesFromBE) => { onPropertySuccess(<PropertyModel>propertiesFromBE[0])}, error => onPropertyFailure(error));
388             } else {
389                 //in case we have uniqueId we call update method
390                 if (this.$scope.isPropertyValueOwner) {
391                     if (!this.$scope.editPropertyModel.property.simpleType && !this.$scope.isSimpleType(property.type)) {
392                         property.value = JSON.stringify(this.$scope.myValue);
393                     }
394                     this.updateInstanceProperties(property.resourceInstanceUniqueId, [property]).subscribe((propertiesFromBE) => onPropertySuccess(propertiesFromBE[0]),
395                         error => onPropertyFailure(error));
396                 } else {
397                     if (!this.$scope.editPropertyModel.property.simpleType && !this.$scope.isSimpleType(property.type)) {
398                         property.defaultValue = JSON.stringify(this.$scope.myValue);
399                         property.value = JSON.stringify(this.$scope.myValue);
400                     } else {
401                         this.$scope.editPropertyModel.property.defaultValue = this.$scope.editPropertyModel.property.value;
402                     }
403                     this.addOrUpdateProperty(property).subscribe(onPropertySuccess, error => onPropertyFailure(error));
404                 }
405             }
406         };
407
408         this.$scope.getPrev = ():void=> {
409             this.property = this.filteredProperties[--this.$scope.currentPropertyIndex];
410             this.initResource();
411             this.initForNotSimpleType();
412             this.$scope.isLastProperty = false;
413         };
414
415         this.$scope.getNext = ():void=> {
416             this.property = this.filteredProperties[++this.$scope.currentPropertyIndex];
417             this.initResource();
418             this.initForNotSimpleType();
419             this.$scope.isLastProperty = this.$scope.currentPropertyIndex == (this.filteredProperties.length - 1);
420         };
421
422         this.$scope.isSimpleType = (typeName:string):boolean=> {
423             return typeName && this.$scope.editPropertyModel.simpleTypes.indexOf(typeName) != -1;
424         };
425
426         this.$scope.showSchema = ():boolean => {
427             return [PROPERTY_TYPES.LIST, PROPERTY_TYPES.MAP].indexOf(this.$scope.editPropertyModel.property.type) > -1;
428         };
429
430         this.$scope.getValidationPattern = (type:string):RegExp => {
431             return this.ValidationUtils.getValidationPattern(type);
432         };
433
434         this.$scope.validateIntRange = (value:string):boolean => {
435             return !value || this.ValidationUtils.validateIntRange(value);
436         };
437
438         this.$scope.close = ():void => {
439             this.$uibModalInstance.close();
440         };
441
442         // Add the done button at the footer.
443         this.$scope.footerButtons = [
444             {'name': 'Save', 'css': 'blue', 'callback': this.$scope.save},
445             {'name': 'Cancel', 'css': 'grey', 'callback': this.$scope.close}
446         ];
447
448         this.$scope.$watch("forms.editForm.$invalid", (newVal) => {
449             if (this.$scope.editPropertyModel.hasGetFunctionValue) {
450                 this.$scope.invalidMandatoryFields = !newVal || !this.$scope.editPropertyModel.property.toscaFunction || this.isViewOnly;
451                 this.$scope.footerButtons[0].disabled = this.$scope.invalidMandatoryFields;
452             } else {
453                 this.$scope.invalidMandatoryFields = !newVal || this.isViewOnly;
454                 this.$scope.footerButtons[0].disabled = this.$scope.invalidMandatoryFields;
455             }
456         });
457
458         this.$scope.$watch("forms.editForm.$valid", (newVal) => {
459             if (this.$scope.editPropertyModel.hasGetFunctionValue) {
460                 this.$scope.invalidMandatoryFields = !newVal || !this.$scope.editPropertyModel.property.toscaFunction || this.isViewOnly;
461                 this.$scope.footerButtons[0].disabled = this.$scope.invalidMandatoryFields;
462             } else {
463                 this.$scope.invalidMandatoryFields = !newVal || this.isViewOnly;
464                 this.$scope.footerButtons[0].disabled = this.$scope.invalidMandatoryFields;
465             }
466         });
467
468         this.$scope.getDefaultValue = ():any => {
469             return this.$scope.isPropertyValueOwner ? this.$scope.editPropertyModel.property.defaultValue : null;
470         };
471
472         this.$scope.onTypeChange = ():void => {
473             this.$scope.editPropertyModel.property.value = '';
474             this.$scope.editPropertyModel.property.defaultValue = '';
475             this.setMaxLength();
476             this.initForNotSimpleType();
477         };
478
479         this.$scope.onSchemaTypeChange = ():void => {
480             if (this.$scope.editPropertyModel.property.type == PROPERTY_TYPES.MAP) {
481                 this.$scope.myValue = {};
482             } else if (this.$scope.editPropertyModel.property.type == PROPERTY_TYPES.LIST) {
483                 this.$scope.myValue = [];
484             }
485             this.setMaxLength();
486         };
487
488         this.$scope.delete = (property:PropertyModel):void => {
489             let onOk: Function = ():void => {
490                 this.deleteProperty(property.uniqueId).subscribe(
491                     this.$scope.close
492                 );
493             };
494             let title:string = this.$filter('translate')("PROPERTY_VIEW_DELETE_MODAL_TITLE");
495             let message:string = this.$filter('translate')("PROPERTY_VIEW_DELETE_MODAL_TEXT", "{'name': '" + property.name + "'}");
496             const okButton = {testId: "OK", text: "OK", type: SdcUiCommon.ButtonType.info, callback: onOk, closeModal: true} as SdcUiComponents.ModalButtonComponent;
497             this.modalService.openInfoModal(title, message, 'delete-modal', [okButton]);
498         };
499
500         this.$scope.onValueTypeChange = (): void => {
501             this.setEmptyValue();
502             if (this.$scope.editPropertyModel.hasGetFunctionValue) {
503                 this.$scope.editPropertyModel.isGetFunctionValid = undefined;
504             } else {
505                 this.$scope.editPropertyModel.property.toscaFunction = undefined;
506                 this.$scope.editPropertyModel.isGetFunctionValid = true;
507             }
508         }
509
510         this.$scope.onConstraintChange = (constraints: any): void => {
511             console.log('$scope.onConstraintChange', constraints);
512
513             if (!this.$scope.invalidMandatoryFields) {
514                 this.$scope.footerButtons[0].disabled = !constraints.valid;
515             } else {
516                 this.$scope.footerButtons[0].disabled = this.$scope.invalidMandatoryFields;
517             }
518             if (!constraints.constraints || constraints.constraints.length == 0) {
519                 this.$scope.editPropertyModel.property.propertyConstraints = null;
520                 this.$scope.editPropertyModel.property.constraints = null;
521                 return;
522             }
523             this.$scope.editPropertyModel.property.propertyConstraints = this.serializePropertyConstraints(constraints.constraints);
524             this.$scope.editPropertyModel.property.constraints = constraints.constraints;
525         }
526
527         this.$scope.onGetFunctionValidFunction = (toscaGetFunction: ToscaGetFunction): void => {
528             this.$scope.editPropertyModel.property.toscaFunction = toscaGetFunction;
529         }
530
531         this.$scope.onToscaFunctionValidityChange = (validationEvent: ToscaFunctionValidationEvent): void => {
532             if (validationEvent.isValid) {
533                 this.$scope.editPropertyModel.isGetFunctionValid = true;
534                 return;
535             }
536             this.$scope.editPropertyModel.isGetFunctionValid = undefined;
537         }
538     };
539
540     private serializePropertyConstraints(constraints: any[]): string[] {
541         if (constraints) {
542             let stringConstrsints = new Array();
543             constraints.forEach((constraint) => {
544                 stringConstrsints.push(JSON.stringify(constraint));
545             })
546             return stringConstrsints;
547         }
548         return null;
549     }
550
551     private setEmptyValue() {
552         const property1 = this.$scope.editPropertyModel.property;
553         property1.value = undefined;
554         if (this.isComplexType(property1.type)) {
555             this.initEmptyComplexValue(property1.type);
556             return;
557         }
558         this.$scope.myValue = '';
559     }
560
561     private updateInstanceProperties = (componentInstanceId:string, properties:PropertyModel[]):Observable<PropertyModel[]> => {
562
563         return this.ComponentInstanceServiceNg2.updateInstanceProperties(this.workspaceService.metadata.componentType, this.workspaceService.metadata.uniqueId, componentInstanceId, properties)
564             .map(newProperties => {
565                 newProperties.forEach((newProperty) => {
566                     if (!_.isNil(newProperty.path)) {
567                         if (newProperty.path[0] === newProperty.resourceInstanceUniqueId) newProperty.path.shift();
568                         // find exist instance property in parent component for update the new value ( find bu uniqueId & path)
569                         let existProperty: PropertyModel = <PropertyModel>_.find(this.compositionService.componentInstancesProperties[newProperty.resourceInstanceUniqueId], {
570                             uniqueId: newProperty.uniqueId,
571                             path: newProperty.path
572                         });
573                         let index = this.compositionService.componentInstancesProperties[newProperty.resourceInstanceUniqueId].indexOf(existProperty);
574                         this.compositionService.componentInstancesProperties[newProperty.resourceInstanceUniqueId][index] = newProperty;
575                     }
576                 });
577                 return newProperties;
578             });
579     };
580
581     private addOrUpdateProperty = (property: PropertyModel): Observable<PropertyModel> => {
582         if (!property.uniqueId) {
583             let onSuccess = (newProperty: PropertyModel): PropertyModel => {
584                 this.filteredProperties.push(newProperty);
585                 return newProperty;
586             };
587             return this.topologyTemplateService.addProperty(this.workspaceService.metadata.componentType, this.workspaceService.metadata.uniqueId, property)
588                 .map(onSuccess);
589         } else {
590             let onSuccess = (newProperty: PropertyModel): PropertyModel => {
591                 // find exist instance property in parent component for update the new value ( find bu uniqueId )
592                 let existProperty: PropertyModel = <PropertyModel>_.find(this.filteredProperties, {uniqueId: newProperty.uniqueId});
593                 let propertyIndex = this.filteredProperties.indexOf(existProperty);
594                 this.filteredProperties[propertyIndex] = newProperty;
595                 return newProperty;
596             };
597             return this.topologyTemplateService.updateProperty(this.workspaceService.metadata.componentType, this.workspaceService.metadata.uniqueId, property).map(onSuccess);
598         }
599     };
600
601     public deleteProperty = (propertyId:string):Observable<void> => {
602         let onSuccess = ():void => {
603             console.debug("Property deleted");
604             delete _.remove(this.filteredProperties, {uniqueId: propertyId})[0];
605         };
606         let onFailed = ():void => {
607             console.debug("Failed to delete property");
608         };
609         return this.topologyTemplateService.deleteProperty(this.workspaceService.metadata.componentType, this.workspaceService.metadata.uniqueId, propertyId).map(onSuccess, onFailed);
610     };
611
612 }