- /**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);