CSIT Fix for SDC-2585
[sdc.git] / catalog-ui / src / app / ng2 / pages / connection-wizard / properties-step / properties-step.component.ts
1 /**
2  * Created by ob0695 on 9/4/2017.
3  */
4 /**
5  * Created by rc2122 on 9/4/2017.
6  */
7 import {Component, Inject, forwardRef} from '@angular/core';
8 import {IStepComponent} from "app/models"
9 import {ConnectionWizardService} from "../connection-wizard.service";
10 import {PropertyFEModel} from "../../../../models/properties-inputs/property-fe-model";
11 import {InstanceFePropertiesMap} from "../../../../models/properties-inputs/property-fe-map";
12 import {PropertiesUtils} from "../../properties-assignment/services/properties.utils";
13 import {ComponentInstanceServiceNg2} from "../../../services/component-instance-services/component-instance.service";
14
15 @Component({
16     selector: 'properties-step',
17     templateUrl: './properties-step.component.html',
18     styleUrls: ['./properties-step.component.less']
19 })
20
21 export class PropertiesStepComponent implements IStepComponent{
22
23     capabilityPropertiesMap: InstanceFePropertiesMap;
24     savingProperty:boolean = false;
25
26     constructor(@Inject(forwardRef(() => ConnectionWizardService)) public connectWizardService: ConnectionWizardService, private componentInstanceServiceNg2:ComponentInstanceServiceNg2, private propertiesUtils:PropertiesUtils) {
27
28         this.capabilityPropertiesMap = this.propertiesUtils.convertPropertiesMapToFEAndCreateChildren({'capability' : connectWizardService.selectedMatch.capability.properties}, false);
29     }
30
31     ngOnInit() {
32         this.connectWizardService.changedCapabilityProperties = [];
33     }
34
35     onPropertySelectedUpdate = ($event) => {
36         console.log("==>" + 'PROPERTY VALUE SELECTED');
37         // this.selectedFlatProperty = $event;
38         // let parentProperty:PropertyFEModel = this.propertiesService.getParentPropertyFEModelFromPath(this.instanceFePropertiesMap[this.selectedFlatProperty.instanceName], this.selectedFlatProperty.path);
39         // parentProperty.expandedChildPropertyId = this.selectedFlatProperty.path;
40     };
41
42     propertyValueChanged = (property: PropertyFEModel) => {
43         if (!property.isDeclared) {
44             const propChangedIdx = this.connectWizardService.changedCapabilityProperties.indexOf(property);
45             if (property.hasValueObjChanged()) {
46             // if (this.componentInstanceServiceNg2.hasPropertyChanged(property)) {
47                 console.log("==>" + this.constructor.name + ": propertyValueChanged " + property);
48                 if (propChangedIdx === -1) {
49                     this.connectWizardService.changedCapabilityProperties.push(property);
50                 }
51             }
52             else {
53                 if (propChangedIdx !== -1) {
54                     console.log("==>" + this.constructor.name + ": propertyValueChanged (reset to original) " + property);
55                     this.connectWizardService.changedCapabilityProperties.splice(propChangedIdx, 1);
56                 }
57             }
58         }
59     };
60
61     preventNext = ():boolean => {
62         return false;
63     }
64
65     preventBack = ():boolean => {
66         return this.savingProperty;
67     }
68 }