From fe4afd47955705bb377583649cb53e2cf4508493 Mon Sep 17 00:00:00 2001 From: talio Date: Sun, 14 Apr 2019 15:37:20 +0300 Subject: Declare properties as policies Change-Id: I54dc7b444e08117097c314cf5f51bd356ac5287d Issue-ID: SDC-2240 Signed-off-by: talio --- .../properties-assignment.module.ts | 2 + .../properties-assignment.page.component.html | 22 +++++-- .../properties-assignment.page.component.less | 11 ++-- .../properties-assignment.page.component.ts | 73 +++++++++++++++++++++- .../services/properties.utils.ts | 4 ++ 5 files changed, 98 insertions(+), 14 deletions(-) (limited to 'catalog-ui/src/app/ng2/pages/properties-assignment') diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts index 907f7638bb..c46d617b86 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.module.ts @@ -27,6 +27,7 @@ import {GlobalPipesModule} from "../../pipes/global-pipes.module"; import {BrowserModule} from "@angular/platform-browser"; import {FilterPropertiesAssignmentComponent} from "../../components/logic/filter-properties-assignment/filter-properties-assignment.component"; import {InputsTableComponent} from "../../components/logic/inputs-table/inputs-table.component"; +import {PoliciesTableModule} from "../../components/logic/policies-table/policies-table.module"; import {PropertiesService} from "../../services/properties.service"; import {DataTypeService} from "../../services/data-type.service"; import {PropertiesAssignmentComponent} from "./properties-assignment.page.component"; @@ -48,6 +49,7 @@ import {ComponentModeService} from "../../services/component-services/component- HttpModule, GlobalPipesModule, PropertyTableModule, + PoliciesTableModule, UiElementsModule], entryComponents: [PropertiesAssignmentComponent], diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.html b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.html index 8a3e8d23ee..1ec6df9bc1 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.html +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.html @@ -49,6 +49,15 @@ (inputChanged)="dataChanged($event)"> + + + +
@@ -56,13 +65,14 @@
-
+
Clear All
- + +
@@ -75,10 +85,10 @@
{{component.name}}
-
No data to display
+
No data to display
@@ -88,10 +98,10 @@
{{isPropertiesTabSelected ? (propertyStructureHeader || "No Property Selected") : "No Property Selected"}}
-
No data to display
+
No data to display
diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.less b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.less index 95ff94317c..523eda2e9f 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.less +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.less @@ -59,11 +59,10 @@ position:absolute; top:0; right:0; + display: flex; } .search-filter-container{ - position: absolute; - right: 100px; display:flex; flex-direction:row; @@ -87,7 +86,7 @@ width: 14px; height: 14px; position: absolute; - right:42px; + left:170px; top: 8px; } @@ -110,9 +109,9 @@ } .declare-button{ - position: absolute; - top: 0; - right: 0; + &:first-of-type { + margin-right: 10px; + } } .main-tabs-section { diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts index 615325559e..037b7f4963 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts @@ -61,6 +61,7 @@ export class PropertiesAssignmentComponent { instanceFePropertiesMap:InstanceFePropertiesMap; inputs: Array = []; + policies: Array = []; instances: Array = []; searchQuery: string; propertyStructureHeader: string; @@ -76,10 +77,12 @@ export class PropertiesAssignmentComponent { currentMainTab:Tab; isInputsTabSelected:boolean; isPropertiesTabSelected:boolean; + isPoliciesTabSelected:boolean; isReadonly:boolean; resourceIsReadonly:boolean; loadingInstances:boolean = false; loadingInputs:boolean = false; + loadingPolicies:boolean = false; loadingProperties:boolean = false; changedData:Array; hasChangedData:boolean; @@ -123,6 +126,7 @@ export class PropertiesAssignmentComponent { ngOnInit() { console.log("==>" + this.constructor.name + ": ngOnInit"); this.loadingInputs = true; + this.loadingPolicies = true; this.loadingInstances = true; this.loadingProperties = true; this.componentServiceNg2 @@ -139,10 +143,16 @@ export class PropertiesAssignmentComponent { this.componentServiceNg2 .getComponentResourcePropertiesData(this.component) .subscribe(response => { + this.loadingPolicies = false; this.instances = []; this.instances.push(...response.componentInstances); this.instances.push(...response.groupInstances); - this.instances.push(...response.policies); + + _.forEach(response.policies, (policy: any) => { + const newPolicy: InputFEModel = new InputFEModel(policy); + this.inputsUtils.resetInputDefaultValue(newPolicy, policy.defaultValue); + this.policies.push(policy); + }); // add the service self instance to the top of the list. const serviceInstance = new ComponentInstance(); @@ -296,6 +306,8 @@ export class PropertiesAssignmentComponent { itemHasChanged = item.hasValueObjChanged(); } else if (this.isInputsTabSelected && item instanceof InputFEModel) { itemHasChanged = item.hasDefaultValueChanged(); + } else if (this.isPoliciesTabSelected && item instanceof InputFEModel) { + itemHasChanged = item.hasDefaultValueChanged(); } const dataChangedIdx = this.changedData.findIndex((changedItem) => changedItem === item); @@ -311,7 +323,7 @@ export class PropertiesAssignmentComponent { if (this.isPropertiesTabSelected) { this.isValidChangedData = this.changedData.every((changedItem) => (changedItem).valueObjIsValid); - } else if (this.isInputsTabSelected) { + } else if (this.isInputsTabSelected || this.isPoliciesTabSelected) { this.isValidChangedData = this.changedData.every((changedItem) => (changedItem).defaultValueObjIsValid); } this.updateHasChangedData(); @@ -385,6 +397,7 @@ export class PropertiesAssignmentComponent { this.currentMainTab = this.propertyInputTabs.tabs.find((tab) => tab.title === event.title); this.isPropertiesTabSelected = this.currentMainTab.title === "Properties"; this.isInputsTabSelected = this.currentMainTab.title === "Inputs"; + this.isPoliciesTabSelected = this.currentMainTab.title === "Policies"; this.propertyStructureHeader = null; this.searchQuery = ''; }; @@ -432,6 +445,46 @@ export class PropertiesAssignmentComponent { }, error => {}); //ignore error }; + /*** DECLARE PROPERTIES/POLICIES ***/ + declarePropertiesToPolicies = (): void => { + let selectedComponentInstancesProperties: InstanceBePropertiesMap = new InstanceBePropertiesMap(); + let instancesIds = new KeysPipe().transform(this.instanceFePropertiesMap, []); + + angular.forEach(instancesIds, (instanceId: string): void => { + let selectedInstanceData: any = this.instances.find(instance => instance.uniqueId == instanceId); + if (selectedInstanceData instanceof ComponentInstance) { + if (!this.isInput(selectedInstanceData.originType)) { + selectedComponentInstancesProperties[instanceId] = this.propertiesService.getCheckedProperties(this.instanceFePropertiesMap[instanceId]); + } + } + }); + + let policiesToCreate: InstancePropertiesAPIMap = new InstancePropertiesAPIMap(null, selectedComponentInstancesProperties, null, null); + this.loadingPolicies = true; + + this.componentServiceNg2 + .createPolicy(this.component, policiesToCreate, this.isSelf()) + .subscribe(response => { + this.setPolicyTabIndication(response.length); + this.checkedPropertiesCount = 0; + this.displayPoliciesAsDeclared(response); + this.loadingPolicies = false; + }); //ignore error + + }; + + displayPoliciesAsDeclared = (policies) => { + _.forEach(policies, (policy: any) => { + let newPolicy: InputFEModel = new InputFEModel(policy); + this.inputsUtils.resetInputDefaultValue(newPolicy, policy.defaultValue); + newPolicy.relatedPropertyName = policy.name; + newPolicy.relatedPropertyValue = policy.value; + this.updatePropertyValueAfterDeclare(newPolicy); + this.policies.push(policy); + }); + }; + + saveChangedData = ():Promise<(PropertyBEModel|InputBEModel)[]> => { return new Promise((resolve, reject) => { if (!this.isValidChangedData) { @@ -648,6 +701,10 @@ export class PropertiesAssignmentComponent { this.propertyInputTabs.setTabIndication('Inputs', numInputs); }; + setPolicyTabIndication = (numPolicies: number): void => { + this.propertyInputTabs.setTabIndication('Policies', numPolicies); + }; + resetUnsavedChangesForInput = (input:InputFEModel) => { this.inputsUtils.resetInputDefaultValue(input, input.defaultValue); this.changedData = this.changedData.filter((changedItem) => changedItem.uniqueId !== input.uniqueId); @@ -685,6 +742,18 @@ export class PropertiesAssignmentComponent { }, error => {}); //ignore error }; + deletePolicy = (policy: PolicyInstance) => { + this.loadingPolicies = true; + this.componentServiceNg2 + .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; + }); + }; + deleteProperty = (property: PropertyFEModel) => { let propertyToDelete = new PropertyFEModel(property); this.loadingProperties = true; diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/services/properties.utils.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/services/properties.utils.ts index 3ed535d6a0..011be41611 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/services/properties.utils.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/services/properties.utils.ts @@ -67,6 +67,10 @@ export class PropertiesUtils { this.propertiesService.disableRelatedProperties(newFEProp, inputPath); }); } + if (newFEProp.getPolicyValues && newFEProp.getPolicyValues.length) { + newFEProp.setAsDeclared(newFEProp.inputPath); //if a path is sent, its a child prop. this param is optional + this.propertiesService.disableRelatedProperties(newFEProp, newFEProp.inputPath); + } } }); instanceFePropertiesMap[instanceId] = propertyFeArray; -- cgit 1.2.3-korg