-/*!
+/*
* 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.
* 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';
-import {DirectivesEnum, DirectiveValue} from "./directive-option";
-
-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;
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');
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',
providers: [ModalService, TranslateService]
})
-export class ServiceDependenciesComponent {
+export class ServiceDependenciesComponent implements OnInit, OnChanges {
modalInstance: ComponentRef<ModalComponent>;
isDependent: boolean;
isLoading: boolean;
parentServiceInputs: InputBEModel[] = [];
- rulesList: ConstraintObject[] = [];
+ parentServiceProperties: PropertyBEModel[] = [];
+ constraintProperties: FilterConstraint[] = [];
+ constraintPropertyLabels: string[] = [];
+ constraintCapabilities: PropertyFilterConstraintUi[] = [];
+ constraintCapabilityLabels: string[] = [];
operatorTypes: any[];
+ capabilities: string = ToscaFilterConstraintType.CAPABILITIES;
+ properties: string = ToscaFilterConstraintType.PROPERTIES;
+ private componentInstancesConstraints: FilterConstraint[] = [];
+ isEditable: boolean;
+ customToscaFunctions: Array<CustomToscaFunction>;
@Input() readonly: boolean;
@Input() compositeService: ComponentMetadata;
@Input() currentServiceInstance: ComponentInstance;
@Input() selectedInstanceSiblings: ServiceInstanceObject[];
- @Input() selectedInstanceConstraints: ConstraintObject[] = [];
+ @Input() selectedInstanceConstraints: FilterConstraint[] = [];
@Input() selectedInstanceProperties: PropertyBEModel[] = [];
- @Input() directiveValues: any = DirectiveValue;
- @Output() updateRulesListEvent: EventEmitter<ConstraintObject[]> = new EventEmitter<ConstraintObject[]>();
+ @Input() componentInstanceCapabilitiesMap: Map<string, PropertyModel[]>;
+ @Output() updateRulesListEvent: EventEmitter<FilterConstraint[]> = new EventEmitter<FilterConstraint[]>();
+ @Output() updateNodeFilterProperties: EventEmitter<FilterConstraint[]> = new EventEmitter<FilterConstraint[]>();
+ @Output() updateNodeFilterCapabilities: EventEmitter<PropertyFilterConstraintUi[]> = new EventEmitter<PropertyFilterConstraintUi[]>();
@Output() loadRulesListEvent:EventEmitter<any> = new EventEmitter();
@Output() dependencyStatus = new EventEmitter<boolean>();
- constructor(private topologyTemplateService: TopologyTemplateService, private modalServiceNg2: ModalService, private translateService: TranslateService) {
+ constructor(private topologyTemplateService: TopologyTemplateService,
+ private modalServiceNg2: ModalService,
+ private translateService: TranslateService,
+ private compositionService: CompositionService) {
}
- ngOnInit() {
+ 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.loadRules();
+ this.initCustomToscaFunctions();
+ this.loadNodeFilter();
this.translateService.languageChangedObservable.subscribe((lang) => {
I18nTexts.translateTexts(this.translateService);
});
}
- ngOnChanges(changes) {
+ 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): void {
if (changes.currentServiceInstance) {
this.currentServiceInstance = changes.currentServiceInstance.currentValue;
this.isDependent = this.currentServiceInstance.isDependent();
}
if (changes.selectedInstanceConstraints && changes.selectedInstanceConstraints.currentValue !== changes.selectedInstanceConstraints.previousValue) {
this.selectedInstanceConstraints = changes.selectedInstanceConstraints.currentValue;
- this.loadRules();
+ this.loadNodeFilter();
}
}
- private getActualDirectiveValue = (): string => {
- return this.currentServiceInstance.directives.length > 0 ? this.currentServiceInstance.directives[0] : "";
- }
-
- private isServiceProxy = (): boolean => {
- return this.currentServiceInstance.isServiceProxy();
+ private getActualDirectiveValue = (): string[] => {
+ return this.currentServiceInstance.directives.length > 0 ? this.currentServiceInstance.directives : [];
}
public openRemoveDependencyModal = (): ComponentRef<ModalComponent> => {
const cancelButton: ButtonModel = new ButtonModel(I18nTexts.modalCancel, 'grey', this.onCloseRemoveDependencyModal);
const modalModel: ModalModel = new ModalModel('sm', I18nTexts.removeDirectiveModalTitle,
I18nTexts.removeDirectiveModalText, [actionButton, cancelButton]);
+ this.loadNodeFilter();
return this.modalServiceNg2.createCustomModal(modalModel);
}
- public openUpdateDependencyModal = (): ComponentRef<ModalComponent> => {
- 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);
- }
-
- loadRules() {
- this.rulesList = this.selectedInstanceConstraints && this.selectedInstanceConstraints.map((co: ConstraintObject) => ({
- servicePropertyName: co.servicePropertyName,
- constraintOperator: co.constraintOperator,
- sourceType: co.sourceType,
- sourceName: co.sourceName !== 'SELF' ? co.sourceName : this.compositeService.name,
- value: co.value,
- }));
+ 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;
+ 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;
- const rulesListOrig = this.rulesList;
+ const rulesListOrig = this.componentInstancesConstraints;
this.currentServiceInstance.unmarkAsDependent(this.getActualDirectiveValue());
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.rulesList;
- this.setDirectiveValue(newDirectiveValue);
- this.rulesList = [];
- 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.rulesList = [];
+ this.constraintProperties = [];
+ this.constraintPropertyLabels = [];
+ this.constraintCapabilities = [];
+ this.constraintCapabilityLabels = [];
}
- private setDirectiveValue(newDirectiveValue: string) {
- if (this.isDependent) {
- this.openUpdateDependencyModal().instance.open();
- }
- if (DirectivesEnum.SELECT == newDirectiveValue.toLowerCase() ||
- DirectivesEnum.SELECTABLE == newDirectiveValue.toLowerCase()) {
- this.currentServiceInstance.markAsSelect();
- } else {
- this.currentServiceInstance.markAsSubstitute();
- }
+ private onEditDirectives(): void {
+ this.isEditable = true;
}
- updateComponentInstance(isDependentOrigVal: boolean, rulesListOrig: ConstraintObject[]) {
+ private setDirectiveValue(newDirectiveValues: string[]): void {
+ this.currentServiceInstance.setDirectiveValue(newDirectiveValues);
+ }
+
+ 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);
this.isLoading = false;
}, (err) => {
this.isDependent = isDependentOrigVal;
- this.rulesList = rulesListOrig;
+ this.componentInstancesConstraints = rulesListOrig;
+ this.isLoading = false;
+ console.error('An error has occurred.', err);
+ });
+ }
+
+ 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;
- console.log('An error has occurred.');
});
+ this.modalServiceNg2.closeCurrentModal();
}
- onAddRule() {
+ 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.createRule, 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();
}
- onSelectRule(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.updateRules(), 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.rulesList, (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();
}
return !this.modalInstance.instance.dynamicContent.instance.checkFormValidForSubmit();
}
- createRule = (): void => {
- 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,
- this.compositeService.componentType
- ).subscribe( (response) => {
- this.updateRulesListEvent.emit(response.properties);
+ new FilterConstraint(this.modalInstance.instance.dynamicContent.instance.currentRule),
+ this.compositeService.componentType,
+ constraintType,
+ index
+ ).subscribe((response) => {
+ this.emitEventOnChanges(constraintType, response);
this.isLoading = false;
}, (err) => {
this.isLoading = false;
this.modalServiceNg2.closeCurrentModal();
}
- updateRules = (): void => {
- 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,
- this.compositeService.componentType
+ new PropertyFilterConstraintUi(this.modalInstance.instance.dynamicContent.instance.currentRule),
+ this.compositeService.componentType,
+ constraintType,
+ index
).subscribe((response) => {
- this.updateRulesListEvent.emit(response.properties);
+ this.emitEventOnChanges(constraintType, response);
this.isLoading = false;
}, (err) => {
this.isLoading = false;
this.modalServiceNg2.closeCurrentModal();
}
- getSymbol(constraintOperator) {
- switch (constraintOperator) {
- case OPERATOR_TYPES.LESS_THAN: return '<';
- case OPERATOR_TYPES.EQUAL: return '=';
- case OPERATOR_TYPES.GREATER_THAN: return '>';
- }
- }
-
- onDeleteRule = (index: number) => {
+ onDeleteNodeFilter = (constraintType: string, index: number): void => {
this.isLoading = true;
this.topologyTemplateService.deleteServiceFilterConstraints(
this.compositeService.uniqueId,
this.currentServiceInstance.uniqueId,
index,
- this.compositeService.componentType
+ this.compositeService.componentType,
+ constraintType
).subscribe( (response) => {
- this.updateRulesListEvent.emit(response.properties);
+ this.emitEventOnChanges(constraintType, response);
this.isLoading = false;
}, (err) => {
this.isLoading = false;
this.modalServiceNg2.closeCurrentModal();
}
- openDeleteModal = (index: number) => {
+ private emitEventOnChanges(constraintType: string, response) {
+ 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): void => {
this.modalServiceNg2.createActionModal(I18nTexts.deleteNodeFilterTxt, I18nTexts.deleteNodeFilterMsg,
- I18nTexts.modalDelete, () => this.onDeleteRule(index), I18nTexts.modalCancel).instance.open();
+ 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))
+ )
}
}