summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts
diff options
context:
space:
mode:
authorToshimichi Fukuda <t_fukuda@jp.fujitsu.com>2019-04-18 21:38:46 +0900
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-05-07 16:09:28 +0000
commit51411acd1d4b06fc9bbc40338a27dd061dba425f (patch)
tree51cbc4bb3372b7aa06e566eec6181b7a1838eee5 /catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts
parent55c536e65dcbd1981de61c6c8bea318585324d22 (diff)
Change to enable SDC list type input
Change-Id: Ic3a9c6e714a5afd22b58bf2cb066932b1ec2a5c0 Issue-ID: SDC-2046 Signed-off-by: Toshimichi Fukuda <t_fukuda@jp.fujitsu.com> Signed-off-by: Satoshi Fujii <fujii-satoshi@jp.fujitsu.com> Signed-off-by: Ayumu Ueha <ueha.ayumu@jp.fujitsu.com>
Diffstat (limited to 'catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts')
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts136
1 files changed, 136 insertions, 0 deletions
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 38278c9d4f..9f406f8c76 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
@@ -39,11 +39,16 @@ import {ModalService} from "../../services/modal.service";
import {Tabs, Tab} from "../../components/ui/tabs/tabs.component";
import {InputsUtils} from "./services/inputs.utils";
import {PropertyCreatorComponent} from "./property-creator/property-creator.component";
+import {DeclareListComponent} from "./declare-list/declare-list.component";
import { InstanceFeDetails } from "../../../models/instance-fe-details";
import { SdcUiComponents } from "sdc-ui/lib/angular";
//import { ModalService as ModalServiceSdcUI} from "sdc-ui/lib/angular/modals/modal.service";
import { IModalButtonComponent } from "sdc-ui/lib/angular/modals/models/modal-config";
import { UnsavedChangesComponent } from "app/ng2/components/ui/forms/unsaved-changes/unsaved-changes.component";
+import { DataTypeService } from "app/ng2/services/data-type.service";
+import { DataTypeModel } from "app/models";
+import { PROPERTY_DATA, PROPERTY_TYPES } from "app/utils";
+import { PropertyDeclareAPIModel} from "app/models";
const SERVICE_SELF_TITLE = "SELF";
@Component({
@@ -69,6 +74,7 @@ export class PropertiesAssignmentComponent {
selectedFlatProperty: SimpleFlatProperty = new SimpleFlatProperty();
selectedInstanceData: ComponentInstance|GroupInstance|PolicyInstance = null;
checkedPropertiesCount: number = 0;
+ checkedChildPropertiesCount: number = 0;
hierarchyPropertiesDisplayOptions:HierarchyDisplayOptions = new HierarchyDisplayOptions('path', 'name', 'childrens');
hierarchyInstancesDisplayOptions:HierarchyDisplayOptions = new HierarchyDisplayOptions('uniqueId', 'name', 'archived', null, 'iconClass');
@@ -296,6 +302,7 @@ export class PropertiesAssignmentComponent {
processInstancePropertiesResponse = (instanceBePropertiesMap: InstanceBePropertiesMap, originTypeIsVF: boolean) => {
this.instanceFePropertiesMap = this.propertiesUtils.convertPropertiesMapToFEAndCreateChildren(instanceBePropertiesMap, originTypeIsVF, this.inputs); //create flattened children, disable declared props, and init values
this.checkedPropertiesCount = 0;
+ this.checkedChildPropertiesCount = 0;
};
@@ -418,6 +425,7 @@ export class PropertiesAssignmentComponent {
let selectedInstanceData: any = this.instances.find(instance => instance.uniqueId == instanceId);
if (selectedInstanceData instanceof ComponentInstance) {
if (!this.isInput(selectedInstanceData.originType)) {
+ // convert Property FE model -> Property BE model, extract only checked
selectedComponentInstancesProperties[instanceId] = this.propertiesService.getCheckedProperties(this.instanceFePropertiesMap[instanceId]);
} else {
selectedComponentInstancesInputs[instanceId] = this.propertiesService.getCheckedProperties(this.instanceFePropertiesMap[instanceId]);
@@ -436,6 +444,7 @@ export class PropertiesAssignmentComponent {
.subscribe(response => {
this.setInputTabIndication(response.length);
this.checkedPropertiesCount = 0;
+ this.checkedChildPropertiesCount = 0;
_.forEach(response, (input: InputBEModel) => {
let newInput: InputFEModel = new InputFEModel(input);
this.inputsUtils.resetInputDefaultValue(newInput, input.defaultValue);
@@ -445,6 +454,123 @@ export class PropertiesAssignmentComponent {
}, error => {}); //ignore error
};
+ declareListProperties = (): void => {
+ console.log('declareListProperties() - enter');
+
+ // get selected properties
+ let selectedComponentInstancesProperties: InstanceBePropertiesMap = new InstanceBePropertiesMap();
+ let selectedGroupInstancesProperties: InstanceBePropertiesMap = new InstanceBePropertiesMap();
+ let selectedPolicyInstancesProperties: InstanceBePropertiesMap = new InstanceBePropertiesMap();
+ let selectedComponentInstancesInputs: InstanceBePropertiesMap = new InstanceBePropertiesMap();
+ let instancesIds = new KeysPipe().transform(this.instanceFePropertiesMap, []);
+ let propertyNameList: Array<string> = [];
+ 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]);
+
+ if (selectedInstanceData instanceof ComponentInstance) {
+ if (!this.isInput(selectedInstanceData.originType)) {
+ // convert Property FE model -> Property BE model, extract only checked
+ selectedComponentInstancesProperties[instanceId] = checkedProperties;
+ } else {
+ selectedComponentInstancesInputs[instanceId] = checkedProperties;
+ }
+ } else if (selectedInstanceData instanceof GroupInstance) {
+ selectedGroupInstancesProperties[instanceId] = checkedProperties;
+ } else if (selectedInstanceData instanceof PolicyInstance) {
+ selectedPolicyInstancesProperties[instanceId] = checkedProperties;
+ }
+
+ angular.forEach(checkedProperties, (property: PropertyBEModel) => {
+ propertyNameList.push(property.name);
+ });
+ });
+
+ let inputsToCreate: InstancePropertiesAPIMap = new InstancePropertiesAPIMap(selectedComponentInstancesInputs, selectedComponentInstancesProperties, selectedGroupInstancesProperties, selectedPolicyInstancesProperties);
+
+ let modalTitle = 'Declare Properties as List Input';
+ const modal = this.ModalService.createCustomModal(new ModalModel(
+ 'sm', /* size */
+ modalTitle, /* title */
+ null, /* content */
+ [ /* buttons */
+ new ButtonModel(
+ 'Save', /* text */
+ 'blue', /* css class */
+ () => { /* callback */
+ let content:any = modal.instance.dynamicContent.instance;
+
+ /* listInput */
+ let reglistInput: InstanceBePropertiesMap = new InstanceBePropertiesMap();
+ let typelist: any = PROPERTY_TYPES.LIST;
+ let uniID: any = insId;
+ let boolfalse: any = false;
+ let schem :any = {
+ "empty": boolfalse,
+ "property": {
+ "type": content.propertyModel.simpleType,
+ "required": boolfalse
+ }
+ }
+ let schemaProp :any = {
+ "type": content.propertyModel.simpleType,
+ "required": boolfalse
+ }
+
+ reglistInput.description = content.propertyModel.description;
+ reglistInput.name = content.propertyModel.name;
+ reglistInput.type = typelist;
+ reglistInput.schemaType = content.propertyModel.simpleType;
+ reglistInput.instanceUniqueId = uniID;
+ reglistInput.uniqueId = uniID;
+ reglistInput.required =boolfalse;
+ reglistInput.schema = schem;
+ reglistInput.schemaProperty = schemaProp;
+
+ let input = {
+ componentInstInputsMap: content.inputsToCreate,
+ listInput: reglistInput
+ };
+ console.log("save button clicked. input=", input);
+
+ this.componentServiceNg2
+ .createListInput(this.component, input, this.isSelf())
+ .subscribe(response => {
+ this.setInputTabIndication(response.length);
+ this.checkedPropertiesCount = 0;
+ this.checkedChildPropertiesCount = 0;
+ _.forEach(response, (input: InputBEModel) => {
+ let newInput: InputFEModel = new InputFEModel(input);
+ this.inputsUtils.resetInputDefaultValue(newInput, input.defaultValue);
+ this.inputs.push(newInput);
+ // create list input does not return updated properties info, so need to reload
+ //this.updatePropertyValueAfterDeclare(newInput);
+ // 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);
+
+ modal.instance.close();
+ });
+ }, error => {}); //ignore error
+
+ }
+ /*, getDisabled: function */
+ ),
+ new ButtonModel('Cancel', 'outline grey', () => {
+ modal.instance.close();
+ }),
+ ],
+ null /* type */
+ ));
+ // 3rd arg is passed to DeclareListComponent instance
+ this.ModalService.addDynamicContentToModal(modal, DeclareListComponent, {properties: inputsToCreate, propertyNameList: propertyNameList});
+ modal.instance.open();
+ console.log('declareListProperties() - leave');
+ };
+
/*** DECLARE PROPERTIES/POLICIES ***/
declarePropertiesToPolicies = (): void => {
let selectedComponentInstancesProperties: InstanceBePropertiesMap = new InstanceBePropertiesMap();
@@ -609,6 +735,8 @@ export class PropertiesAssignmentComponent {
handleReverseItem = (changedItem) => {
changedItem = <PropertyFEModel>changedItem;
this.propertiesUtils.resetPropertyValue(changedItem, changedItem.value);
+ this.checkedPropertiesCount = 0;
+ this.checkedChildPropertiesCount = 0;
};
} else if (this.isInputsTabSelected) {
handleReverseItem = (changedItem) => {
@@ -643,6 +771,10 @@ export class PropertiesAssignmentComponent {
title: 'Saved'
});
if(onSuccessFunction) onSuccessFunction();
+ if(this.isPropertiesTabSelected){
+ this.checkedPropertiesCount = 0;
+ this.checkedChildPropertiesCount = 0;
+ }
},
() => {
this.Notification.error({
@@ -698,6 +830,10 @@ export class PropertiesAssignmentComponent {
console.log("CheckedProperties count is now.... " + this.checkedPropertiesCount);
};
+ updateCheckedChildPropertyCount = (increment: boolean): void => {
+ this.checkedChildPropertiesCount += (increment) ? 1 : -1;
+ };
+
setInputTabIndication = (numInputs: number): void => {
this.propertyInputTabs.setTabIndication('Inputs', numInputs);
};