X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-ui%2Fsrc%2Fapp%2Fng2%2Fcomponents%2Flogic%2Fservice-dependencies%2Fservice-dependencies.component.ts;h=e5f1f6f91889b0bac54a00a3a0bbcddd426c3a23;hb=ee6e389e64b55615800a81ce43a41fa3e7ff93ce;hp=ff5207bb2c7508fe519124d9d872207137fdbefc;hpb=4f251edb14a4f525475df18f4f651696152b3b42;p=sdc.git diff --git a/catalog-ui/src/app/ng2/components/logic/service-dependencies/service-dependencies.component.ts b/catalog-ui/src/app/ng2/components/logic/service-dependencies/service-dependencies.component.ts index ff5207bb2c..e5f1f6f918 100644 --- a/catalog-ui/src/app/ng2/components/logic/service-dependencies/service-dependencies.component.ts +++ b/catalog-ui/src/app/ng2/components/logic/service-dependencies/service-dependencies.component.ts @@ -1,5 +1,6 @@ -/*! +/* * Copyright © 2016-2018 European Support Limited + * Modification Copyright (C) 2022 Nordix Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,70 +14,31 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -import { Component, ComponentRef, EventEmitter, Input, Output } from '@angular/core'; -import { - ButtonModel, - ComponentInstance, - InputBEModel, - ModalModel, - PropertyBEModel, -} from 'app/models'; -import { ModalComponent } from 'app/ng2/components/ui/modal/modal.component'; -import { ServiceDependenciesEditorComponent } from 'app/ng2/pages/service-dependencies-editor/service-dependencies-editor.component'; -import { ModalService } from 'app/ng2/services/modal.service'; -import { ComponentGenericResponse } from 'app/ng2/services/responses/component-generic-response'; -import { TranslateService } from 'app/ng2/shared/translator/translate.service'; -import { ComponentMetadata } from '../../../../models/component-metadata'; -import { ServiceInstanceObject } from '../../../../models/service-instance-properties-and-interfaces'; -import { TopologyTemplateService } from '../../../services/component-services/topology-template.service'; - -export class ConstraintObject { - servicePropertyName: string; - constraintOperator: string; - sourceType: string; - sourceName: string; - value: string; - - constructor(input?: any) { - if (input) { - this.servicePropertyName = input.servicePropertyName; - this.constraintOperator = input.constraintOperator; - this.sourceType = input.sourceType; - this.sourceName = input.sourceName; - this.value = input.value; - } - } -} -// tslint:disable-next-line:max-classes-per-file -export class ConstraintObjectUI extends ConstraintObject{ - isValidValue: boolean; - - constructor(input?: any) { - super(input); - if (input) { - this.isValidValue = input.isValidValue ? input.isValidValue : input.value !== ''; - } - } - - public updateValidity(isValidValue: boolean) { - this.isValidValue = isValidValue; - } - - public isValidRule(isStatic) { - const isValidValue = isStatic ? this.isValidValue : true; - return this.servicePropertyName != null && this.servicePropertyName !== '' - && this.value != null && this.value !== '' && isValidValue; - } +import {Component, ComponentRef, EventEmitter, Input, OnChanges, OnInit, Output} from '@angular/core'; +import {ButtonModel, ComponentInstance, InputBEModel, ModalModel, PropertyBEModel, PropertyModel,} from 'app/models'; +import {ModalComponent} from 'app/ng2/components/ui/modal/modal.component'; +import {FilterType, ServiceDependenciesEditorComponent} from 'app/ng2/pages/service-dependencies-editor/service-dependencies-editor.component'; +import {ModalService} from 'app/ng2/services/modal.service'; +import {ComponentGenericResponse} from 'app/ng2/services/responses/component-generic-response'; +import {TranslateService} from 'app/ng2/shared/translator/translate.service'; +import {ComponentMetadata} from '../../../../models/component-metadata'; +import {ServiceInstanceObject} from '../../../../models/service-instance-properties-and-interfaces'; +import {TopologyTemplateService} from '../../../services/component-services/topology-template.service'; +import {ToscaFilterConstraintType} from "../../../../models/tosca-filter-constraint-type.enum"; +import {CompositionService} from "../../../pages/composition/composition.service"; +import {FilterConstraint} from "app/models/filter-constraint"; +import {PropertyFilterConstraintUi} from "../../../../models/ui-models/property-filter-constraint-ui"; +import {ConstraintOperatorType, FilterConstraintHelper} from "../../../../utils/filter-constraint-helper"; +import {CustomToscaFunction} from "../../../../models/default-custom-functions"; + +export enum SourceType { + STATIC = 'static', + SEVERAL = 'several', + TOSCA_FUNCTION = 'tosca_function', + TOSCA_FUNCTION_LIST = 'tosca_function_list' } -export const OPERATOR_TYPES = { - EQUAL: 'equal', - GREATER_THAN: 'greater_than', - LESS_THAN: 'less_than' -}; - -// tslint:disable-next-line:max-classes-per-file class I18nTexts { static removeDirectiveModalTitle: string; static removeDirectiveModalText: string; @@ -91,6 +53,10 @@ class I18nTexts { static updateNodeFilterTxt: string; static deleteNodeFilterTxt: string; static deleteNodeFilterMsg: string; + static validateCapabilitiesTxt: string + static validateCapabilitiesMsg: string + static validateNodePropertiesTxt: string + static validateNodePropertiesMsg: string public static translateTexts(translateService) { I18nTexts.removeDirectiveModalTitle = translateService.translate('DIRECTIVES_AND_NODE_FILTER_REMOVE_TITLE'); @@ -106,10 +72,13 @@ class I18nTexts { I18nTexts.updateNodeFilterTxt = translateService.translate('DIRECTIVES_AND_NODE_FILTER_UPDATE_NODE_FILTER'); I18nTexts.deleteNodeFilterTxt = translateService.translate('DIRECTIVES_AND_NODE_FILTER_DELETE_NODE_FILTER'); I18nTexts.deleteNodeFilterMsg = translateService.translate('DIRECTIVES_AND_NODE_FILTER_DELETE_NODE_FILTER_MSG'); + I18nTexts.validateCapabilitiesTxt = translateService.translate('VALIDATE_CAPABILITIES_TXT'); + I18nTexts.validateCapabilitiesMsg = translateService.translate('VALIDATE_CAPABILITIES_MSG'); + I18nTexts.validateNodePropertiesTxt = translateService.translate('VALIDATE_NODE_PROPERTIES_TXT'); + I18nTexts.validateNodePropertiesMsg = translateService.translate('VALIDATE_NODE_PROPERTIES_MSG'); } } -// tslint:disable-next-line:max-classes-per-file @Component({ selector: 'service-dependencies', templateUrl: './service-dependencies.component.html', @@ -117,58 +86,80 @@ class I18nTexts { providers: [ModalService, TranslateService] }) -export class ServiceDependenciesComponent { +export class ServiceDependenciesComponent implements OnInit, OnChanges { modalInstance: ComponentRef; isDependent: boolean; isLoading: boolean; parentServiceInputs: InputBEModel[] = []; - constraintProperties: ConstraintObject[] = []; - constraintCapabilities: ConstraintObject[] = []; + parentServiceProperties: PropertyBEModel[] = []; + constraintProperties: FilterConstraint[] = []; + constraintPropertyLabels: string[] = []; + constraintCapabilities: PropertyFilterConstraintUi[] = []; + constraintCapabilityLabels: string[] = []; operatorTypes: any[]; - capabilities: string = 'capabilities'; - properties: string = 'properties'; - private componentInstancesConstraints: ConstraintObject[] = []; - directiveOptions: string[]; + capabilities: string = ToscaFilterConstraintType.CAPABILITIES; + properties: string = ToscaFilterConstraintType.PROPERTIES; + private componentInstancesConstraints: FilterConstraint[] = []; + isEditable: boolean; + customToscaFunctions: Array; @Input() readonly: boolean; @Input() compositeService: ComponentMetadata; @Input() currentServiceInstance: ComponentInstance; @Input() selectedInstanceSiblings: ServiceInstanceObject[]; - @Input() selectedInstanceConstraints: ConstraintObject[] = []; + @Input() selectedInstanceConstraints: FilterConstraint[] = []; @Input() selectedInstanceProperties: PropertyBEModel[] = []; - @Output() updateRulesListEvent: EventEmitter = new EventEmitter(); - @Output() updateNodeFilterProperties: EventEmitter = new EventEmitter(); - @Output() updateNodeFilterCapabilities: EventEmitter = new EventEmitter(); + @Input() componentInstanceCapabilitiesMap: Map; + @Output() updateRulesListEvent: EventEmitter = new EventEmitter(); + @Output() updateNodeFilterProperties: EventEmitter = new EventEmitter(); + @Output() updateNodeFilterCapabilities: EventEmitter = new EventEmitter(); @Output() loadRulesListEvent:EventEmitter = new EventEmitter(); @Output() dependencyStatus = new EventEmitter(); - constructor(private topologyTemplateService: TopologyTemplateService, private modalServiceNg2: ModalService, private translateService: TranslateService) { + constructor(private topologyTemplateService: TopologyTemplateService, + private modalServiceNg2: ModalService, + private translateService: TranslateService, + private compositionService: CompositionService) { } - ngOnInit() { - this.loadDirectives(); + ngOnInit(): void { this.isLoading = false; this.operatorTypes = [ - {label: '>', value: OPERATOR_TYPES.GREATER_THAN}, - {label: '<', value: OPERATOR_TYPES.LESS_THAN}, - {label: '=', value: OPERATOR_TYPES.EQUAL} + {label: FilterConstraintHelper.convertToSymbol(ConstraintOperatorType.GREATER_THAN), value: ConstraintOperatorType.GREATER_THAN}, + {label: FilterConstraintHelper.convertToSymbol(ConstraintOperatorType.LESS_THAN), value: ConstraintOperatorType.LESS_THAN}, + {label: FilterConstraintHelper.convertToSymbol(ConstraintOperatorType.EQUAL), value: ConstraintOperatorType.EQUAL}, + {label: FilterConstraintHelper.convertToSymbol(ConstraintOperatorType.GREATER_OR_EQUAL), value: ConstraintOperatorType.GREATER_OR_EQUAL}, + {label: FilterConstraintHelper.convertToSymbol(ConstraintOperatorType.LESS_OR_EQUAL), value: ConstraintOperatorType.LESS_OR_EQUAL}, + {label: FilterConstraintHelper.convertToSymbol(ConstraintOperatorType.LENGTH), value: ConstraintOperatorType.LENGTH}, + {label: FilterConstraintHelper.convertToSymbol(ConstraintOperatorType.IN_RANGE), value: ConstraintOperatorType.IN_RANGE}, + {label: FilterConstraintHelper.convertToSymbol(ConstraintOperatorType.MIN_LENGTH), value: ConstraintOperatorType.MIN_LENGTH}, + {label: FilterConstraintHelper.convertToSymbol(ConstraintOperatorType.MAX_LENGTH), value: ConstraintOperatorType.MAX_LENGTH}, + {label: FilterConstraintHelper.convertToSymbol(ConstraintOperatorType.PATTERN), value: ConstraintOperatorType.PATTERN} ]; - this.topologyTemplateService.getComponentInputsWithProperties(this.compositeService.componentType, this.compositeService.uniqueId).subscribe((result: ComponentGenericResponse) => { + this.topologyTemplateService.getComponentInputsWithProperties(this.compositeService.componentType, this.compositeService.uniqueId) + .subscribe((result: ComponentGenericResponse) => { this.parentServiceInputs = result.inputs; + this.parentServiceProperties = result.properties; }); + this.initCustomToscaFunctions(); this.loadNodeFilter(); this.translateService.languageChangedObservable.subscribe((lang) => { I18nTexts.translateTexts(this.translateService); }); } - loadDirectives() { - this.topologyTemplateService.getDirectiveList().subscribe((data: string[]) => { - this.directiveOptions = data; - }) + private initCustomToscaFunctions() { + if (!this.customToscaFunctions) { + this.customToscaFunctions = []; + this.topologyTemplateService.getDefaultCustomFunction().toPromise().then((data) => { + for (let customFunction of data) { + this.customToscaFunctions.push(new CustomToscaFunction(customFunction)); + } + }); + } } - ngOnChanges(changes) { + ngOnChanges(changes): void { if (changes.currentServiceInstance) { this.currentServiceInstance = changes.currentServiceInstance.currentValue; this.isDependent = this.currentServiceInstance.isDependent(); @@ -179,9 +170,10 @@ export class ServiceDependenciesComponent { } } - private getActualDirectiveValue = (): string => { - return this.currentServiceInstance.directives.length > 0 ? this.currentServiceInstance.directives[0] : ""; + private getActualDirectiveValue = (): string[] => { + return this.currentServiceInstance.directives.length > 0 ? this.currentServiceInstance.directives : []; } + public openRemoveDependencyModal = (): ComponentRef => { const actionButton: ButtonModel = new ButtonModel(I18nTexts.modalApprove, 'blue', this.onUncheckDependency); const cancelButton: ButtonModel = new ButtonModel(I18nTexts.modalCancel, 'grey', this.onCloseRemoveDependencyModal); @@ -191,27 +183,19 @@ export class ServiceDependenciesComponent { return this.modalServiceNg2.createCustomModal(modalModel); } - public openUpdateDependencyModal = (): ComponentRef => { - const actionButton: ButtonModel = new ButtonModel(I18nTexts.modalApprove, 'blue', this.onUncheckDependency); - const cancelButton: ButtonModel = new ButtonModel(I18nTexts.modalCancel, 'grey', this.onCloseRemoveDependencyModal); - const modalModel: ModalModel = new ModalModel('sm', I18nTexts.updateDirectiveModalTitle, - I18nTexts.updateDirectiveModalText, [actionButton, cancelButton]); - return this.modalServiceNg2.createCustomModal(modalModel); - } - private loadNodeFilter = (): void => { this.topologyTemplateService.getServiceFilterConstraints(this.compositeService.componentType, this.compositeService.uniqueId).subscribe((response) => { if (response.nodeFilterforNode && response.nodeFilterforNode[this.currentServiceInstance.uniqueId]) { this.componentInstancesConstraints = response.nodeFilterforNode; - const nodeFilterPropertiesResponse: ConstraintObject[] = response.nodeFilterforNode[this.currentServiceInstance.uniqueId].properties; - this.constraintProperties = nodeFilterPropertiesResponse; - const nodeFilterCapabilitiesResponse: ConstraintObject[] = response.nodeFilterforNode[this.currentServiceInstance.uniqueId].capabilities; - this.constraintCapabilities = nodeFilterCapabilitiesResponse; + this.constraintProperties = response.nodeFilterforNode[this.currentServiceInstance.uniqueId].properties; + this.buildConstraintPropertyLabels(); + this.constraintCapabilities = response.nodeFilterforNode[this.currentServiceInstance.uniqueId].capabilities; + this.buildCapabilityFilterConstraintLabels(); } }); } - onUncheckDependency = () => { + onUncheckDependency = (): void => { this.modalServiceNg2.closeCurrentModal(); this.isLoading = true; const isDepOrig = this.isDependent; @@ -220,41 +204,48 @@ export class ServiceDependenciesComponent { this.updateComponentInstance(isDepOrig, rulesListOrig); } - onCloseRemoveDependencyModal = () => { + onCloseRemoveDependencyModal = (): void => { this.isDependent = true; this.modalServiceNg2.closeCurrentModal(); } - onOptionsSelected(event: any) { - const newDirectiveValue = event.target.value; - if (newDirectiveValue.toLowerCase() !== this.getActualDirectiveValue()) { - const rulesListOrig = this.componentInstancesConstraints; - this.setDirectiveValue(newDirectiveValue); - this.constraintProperties = []; - this.constraintCapabilities = []; - this.updateComponentInstance(this.isDependent, rulesListOrig); - } + onAddDirectives(directives: string[]): void { + this.isEditable = false; + this.setDirectiveValue(directives); + const rulesListOrig = this.componentInstancesConstraints; + this.constraintProperties = []; + this.constraintPropertyLabels = []; + this.constraintCapabilities = []; + this.constraintCapabilityLabels = []; + this.loadNodeFilter(); + this.updateComponentInstance(this.isDependent, rulesListOrig); } - private onRemoveDirective() { + private onRemoveDirective(): void { this.openRemoveDependencyModal().instance.open(); this.constraintProperties = []; + this.constraintPropertyLabels = []; this.constraintCapabilities = []; + this.constraintCapabilityLabels = []; } - private setDirectiveValue(newDirectiveValue: string) { - if (this.isDependent) { - this.openUpdateDependencyModal().instance.open(); - } - this.currentServiceInstance.setDirectiveValue(newDirectiveValue); + private onEditDirectives(): void { + this.isEditable = true; + } + + private setDirectiveValue(newDirectiveValues: string[]): void { + this.currentServiceInstance.setDirectiveValue(newDirectiveValues); } - updateComponentInstance(isDependentOrigVal: boolean, rulesListOrig: ConstraintObject[]) { + updateComponentInstance(isDependentOrigVal: boolean, rulesListOrig: FilterConstraint[]): void { this.isLoading = true; this.topologyTemplateService.updateComponentInstance(this.compositeService.uniqueId, this.compositeService.componentType, this.currentServiceInstance) .subscribe((updatedServiceIns: ComponentInstance) => { + const selectedComponentInstance = this.compositionService.getComponentInstances() + .find(componentInstance => componentInstance.uniqueId == this.currentServiceInstance.uniqueId); + selectedComponentInstance.directives = updatedServiceIns.directives; this.currentServiceInstance = new ComponentInstance(updatedServiceIns); this.isDependent = this.currentServiceInstance.isDependent(); this.dependencyStatus.emit(this.isDependent); @@ -266,51 +257,143 @@ export class ServiceDependenciesComponent { this.isDependent = isDependentOrigVal; this.componentInstancesConstraints = rulesListOrig; this.isLoading = false; - console.log('An error has occurred.'); + console.error('An error has occurred.', err); }); } - onAddNodeFilter = (constraintType: string) => { - console.info("constraintType: ", constraintType); + onAddNodeFilter = (): void => { + if (!this.selectedInstanceProperties) { + this.modalServiceNg2.openAlertModal(I18nTexts.validateNodePropertiesTxt, I18nTexts.validateNodePropertiesMsg); + } else { + const cancelButton: ButtonModel = new ButtonModel(I18nTexts.modalCancel, 'outline white', this.modalServiceNg2.closeCurrentModal); + const saveButton: ButtonModel = new ButtonModel(I18nTexts.modalCreate, 'blue', () => this.createNodeFilter(this.properties), this.getDisabled); + const modalModel: ModalModel = new ModalModel('l', I18nTexts.addNodeFilterTxt, '', [saveButton, cancelButton], 'standard'); + this.modalInstance = this.modalServiceNg2.createCustomModal(modalModel); + this.modalServiceNg2.addDynamicContentToModalAndBindInputs( + this.modalInstance, + ServiceDependenciesEditorComponent, + { + 'currentServiceName': this.currentServiceInstance.name, + 'operatorTypes': this.operatorTypes, + 'compositeServiceName': this.compositeService.name, + 'parentServiceInputs': this.parentServiceInputs, + 'parentServiceProperties': this.parentServiceProperties, + 'selectedInstanceProperties': this.selectedInstanceProperties, + 'customToscaFunctions': this.customToscaFunctions, + 'filterType': FilterType.PROPERTY, + } + ); + this.modalInstance.instance.open(); + } + } + + onAddNodeFilterCapabilities = (): void => { + if (this.componentInstanceCapabilitiesMap.size == 0) { + this.modalServiceNg2.openAlertModal(I18nTexts.validateCapabilitiesTxt, I18nTexts.validateCapabilitiesMsg); + } else { + const cancelButton: ButtonModel = new ButtonModel(I18nTexts.modalCancel, 'outline white', this.modalServiceNg2.closeCurrentModal); + const saveButton: ButtonModel = new ButtonModel(I18nTexts.modalCreate, 'blue', () => this.createNodeFilterCapabilities(this.capabilities), this.getDisabled); + const modalModel: ModalModel = new ModalModel('l', I18nTexts.addNodeFilterTxt, '', [saveButton, cancelButton], 'standard'); + this.modalInstance = this.modalServiceNg2.createCustomModal(modalModel); + this.modalServiceNg2.addDynamicContentToModalAndBindInputs( + this.modalInstance, + ServiceDependenciesEditorComponent, + { + 'currentServiceName': this.currentServiceInstance.name, + 'operatorTypes': this.operatorTypes, + 'compositeServiceName': this.compositeService.name, + 'parentServiceInputs': this.parentServiceInputs, + 'parentServiceProperties': this.parentServiceProperties, + 'selectedInstanceProperties': this.selectedInstanceProperties, + 'capabilityNameAndPropertiesMap': this.componentInstanceCapabilitiesMap, + 'filterType': FilterType.CAPABILITY, + } + ); + this.modalInstance.instance.open(); + } + } + + createNodeFilter = (constraintType: string): void => { + this.customToscaFunctions = this.modalInstance.instance.dynamicContent.instance.customToscaFunctions; + this.isLoading = true; + this.topologyTemplateService.createServiceFilterConstraints( + this.compositeService.uniqueId, + this.currentServiceInstance.uniqueId, + new FilterConstraint(this.modalInstance.instance.dynamicContent.instance.currentRule), + this.compositeService.componentType, + constraintType + ).subscribe( (response) => { + this.emitEventOnChanges(constraintType, response); + this.isLoading = false; + }, (err) => { + this.isLoading = false; + }); + this.modalServiceNg2.closeCurrentModal(); + } + + createNodeFilterCapabilities = (constraintType: string): void => { + this.isLoading = true; + this.topologyTemplateService.createServiceFilterCapabilitiesConstraints( + this.compositeService.uniqueId, + this.currentServiceInstance.uniqueId, + new PropertyFilterConstraintUi(this.modalInstance.instance.dynamicContent.instance.currentRule), + this.compositeService.componentType, + constraintType + ).subscribe( (response) => { + this.emitEventOnChanges(constraintType, response); + this.isLoading = false; + }, (err) => { + this.isLoading = false; + }); + this.modalServiceNg2.closeCurrentModal(); + } + + onSelectNodeFilterCapability(constraintType: string, index: number): void { const cancelButton: ButtonModel = new ButtonModel(I18nTexts.modalCancel, 'outline white', this.modalServiceNg2.closeCurrentModal); - const saveButton: ButtonModel = new ButtonModel(I18nTexts.modalCreate, 'blue', () => this.createNodeFilter(constraintType), this.getDisabled); - const modalModel: ModalModel = new ModalModel('l', I18nTexts.addNodeFilterTxt, '', [saveButton, cancelButton], 'standard'); + const saveButton: ButtonModel = new ButtonModel(I18nTexts.modalSave, 'blue', () => this.updateNodeFilterCapability(constraintType, index), this.getDisabled); + const modalModel: ModalModel = new ModalModel('l', I18nTexts.updateNodeFilterTxt, '', [saveButton, cancelButton], 'standard'); this.modalInstance = this.modalServiceNg2.createCustomModal(modalModel); - this.modalServiceNg2.addDynamicContentToModal( + const selectedFilterConstraint = new PropertyFilterConstraintUi(this.constraintCapabilities[index]); + this.modalServiceNg2.addDynamicContentToModalAndBindInputs( this.modalInstance, ServiceDependenciesEditorComponent, { - currentServiceName: this.currentServiceInstance.name, - operatorTypes: this.operatorTypes, - compositeServiceName: this.compositeService.name, - parentServiceInputs: this.parentServiceInputs, - selectedInstanceProperties: this.selectedInstanceProperties, - selectedInstanceSiblings: this.selectedInstanceSiblings + 'filterConstraint': selectedFilterConstraint, + 'currentServiceName': this.currentServiceInstance.name, + 'operatorTypes': this.operatorTypes, + 'compositeServiceName': this.compositeService.name, + 'parentServiceInputs': this.parentServiceInputs, + 'parentServiceProperties': this.parentServiceProperties, + 'selectedInstanceProperties': this.selectedInstanceProperties, + 'capabilityNameAndPropertiesMap': this.componentInstanceCapabilitiesMap, + 'filterType': FilterType.CAPABILITY, } ); this.modalInstance.instance.open(); } - onSelectNodeFilter(constraintType: string, index: number) { + onSelectNodeFilter(constraintType: string, index: number): void { const cancelButton: ButtonModel = new ButtonModel(I18nTexts.modalCancel, 'outline white', this.modalServiceNg2.closeCurrentModal); - const saveButton: ButtonModel = new ButtonModel(I18nTexts.modalSave, 'blue', () => this.updateNodeFilter(constraintType), this.getDisabled); + const saveButton: ButtonModel = new ButtonModel(I18nTexts.modalSave, 'blue', () => this.updateNodeFilter(constraintType, index), this.getDisabled); const modalModel: ModalModel = new ModalModel('l', I18nTexts.updateNodeFilterTxt, '', [saveButton, cancelButton], 'standard'); this.modalInstance = this.modalServiceNg2.createCustomModal(modalModel); - this.modalServiceNg2.addDynamicContentToModal( + const selectedFilterConstraint = new PropertyFilterConstraintUi(this.constraintProperties[index]); + this.modalServiceNg2.addDynamicContentToModalAndBindInputs( this.modalInstance, ServiceDependenciesEditorComponent, { - serviceRuleIndex: index, - serviceRules: _.map(this.properties == constraintType ? this.constraintProperties : - this.constraintCapabilities, (rule) => new ConstraintObjectUI(rule)), - currentServiceName: this.currentServiceInstance.name, - operatorTypes: this.operatorTypes, - compositeServiceName: this.compositeService.name, - parentServiceInputs: this.parentServiceInputs, - selectedInstanceProperties: this.selectedInstanceProperties, - selectedInstanceSiblings: this.selectedInstanceSiblings + 'filterConstraint': selectedFilterConstraint, + 'currentServiceName': this.currentServiceInstance.name, + 'operatorTypes': this.operatorTypes, + 'compositeServiceName': this.compositeService.name, + 'parentServiceInputs': this.parentServiceInputs, + 'parentServiceProperties': this.parentServiceProperties, + 'selectedInstanceProperties': this.selectedInstanceProperties, + 'customToscaFunctions': this.customToscaFunctions, + 'filterType': FilterType.PROPERTY } ); + this.modalInstance.instance.open(); } @@ -318,16 +401,16 @@ export class ServiceDependenciesComponent { return !this.modalInstance.instance.dynamicContent.instance.checkFormValidForSubmit(); } - createNodeFilter = (constraintType: string) => { - const newRuleToCreate: ConstraintObject = new ConstraintObject(this.modalInstance.instance.dynamicContent.instance.currentRule); + updateNodeFilter = (constraintType: string, index: number): void => { this.isLoading = true; - this.topologyTemplateService.createServiceFilterConstraints( + this.topologyTemplateService.updateServiceFilterConstraints( this.compositeService.uniqueId, this.currentServiceInstance.uniqueId, - newRuleToCreate, + new FilterConstraint(this.modalInstance.instance.dynamicContent.instance.currentRule), this.compositeService.componentType, - constraintType - ).subscribe( (response) => { + constraintType, + index + ).subscribe((response) => { this.emitEventOnChanges(constraintType, response); this.isLoading = false; }, (err) => { @@ -336,15 +419,15 @@ export class ServiceDependenciesComponent { this.modalServiceNg2.closeCurrentModal(); } - updateNodeFilter = (constraintType: string) => { - const allRulesToUpdate: ConstraintObject[] = this.modalInstance.instance.dynamicContent.instance.serviceRulesList.map((rule) => new ConstraintObject(rule)); + updateNodeFilterCapability = (constraintType: string, index: number): void => { this.isLoading = true; - this.topologyTemplateService.updateServiceFilterConstraints( + this.topologyTemplateService.updateServiceFilterCapabilitiesConstraint( this.compositeService.uniqueId, this.currentServiceInstance.uniqueId, - allRulesToUpdate, + new PropertyFilterConstraintUi(this.modalInstance.instance.dynamicContent.instance.currentRule), this.compositeService.componentType, - constraintType + constraintType, + index ).subscribe((response) => { this.emitEventOnChanges(constraintType, response); this.isLoading = false; @@ -354,15 +437,7 @@ export class ServiceDependenciesComponent { this.modalServiceNg2.closeCurrentModal(); } - getSymbol(constraintOperator) { - switch (constraintOperator) { - case OPERATOR_TYPES.LESS_THAN: return '<'; - case OPERATOR_TYPES.EQUAL: return '='; - case OPERATOR_TYPES.GREATER_THAN: return '>'; - } - } - - onDeleteNodeFilter = (constraintType: string, index: number) => { + onDeleteNodeFilter = (constraintType: string, index: number): void => { this.isLoading = true; this.topologyTemplateService.deleteServiceFilterConstraints( this.compositeService.uniqueId, @@ -383,15 +458,37 @@ export class ServiceDependenciesComponent { if (this.properties === constraintType) { this.updateNodeFilterProperties.emit(response.properties); this.constraintProperties = response.properties; + this.buildConstraintPropertyLabels(); } else { this.updateNodeFilterCapabilities.emit(response.capabilities); this.constraintCapabilities = response.capabilities; + this.buildCapabilityFilterConstraintLabels(); } } - openDeleteModal = (constraintType: string, index: number) => { + openDeleteModal = (constraintType: string, index: number): void => { this.modalServiceNg2.createActionModal(I18nTexts.deleteNodeFilterTxt, I18nTexts.deleteNodeFilterMsg, I18nTexts.modalDelete, () => this.onDeleteNodeFilter(constraintType, index), I18nTexts.modalCancel).instance.open(); } + private buildConstraintPropertyLabels(): void { + this.constraintPropertyLabels = []; + if (!this.constraintProperties) { + return; + } + this.constraintProperties.forEach( + constraint => this.constraintPropertyLabels.push(FilterConstraintHelper.buildFilterConstraintLabel(constraint)) + ) + } + + private buildCapabilityFilterConstraintLabels(): void { + this.constraintCapabilityLabels = []; + if (!this.constraintCapabilities) { + return; + } + this.constraintCapabilities.forEach( + constraint => this.constraintCapabilityLabels.push(FilterConstraintHelper.buildFilterConstraintLabel(constraint)) + ) + } + }