summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/components
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2020-10-05 10:45:11 +0100
committerChristophe Closset <christophe.closset@intl.att.com>2020-11-16 12:08:35 +0000
commit1ae28c3a8b33e286331608e1c4a1e3cc483699eb (patch)
treee0862ec700300fd5a55e2cab01d5add631b3da1d /catalog-ui/src/app/ng2/components
parent126df1ea8430799f1fd2db2ea5227543df17d699 (diff)
Fix node filter capability filters
Issue-ID: SDC-3335 Signed-off-by: aribeiro <anderson.ribeiro@est.tech> Change-Id: I6ffc1e0fb079ac0e33262f16a62deefda97f7616 Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Diffstat (limited to 'catalog-ui/src/app/ng2/components')
-rw-r--r--catalog-ui/src/app/ng2/components/logic/capabilities-constraint/capabilities-constraint.component.ts61
-rw-r--r--catalog-ui/src/app/ng2/components/logic/service-dependencies/service-dependencies.component.html16
-rw-r--r--catalog-ui/src/app/ng2/components/logic/service-dependencies/service-dependencies.component.ts137
3 files changed, 183 insertions, 31 deletions
diff --git a/catalog-ui/src/app/ng2/components/logic/capabilities-constraint/capabilities-constraint.component.ts b/catalog-ui/src/app/ng2/components/logic/capabilities-constraint/capabilities-constraint.component.ts
new file mode 100644
index 0000000000..853106c806
--- /dev/null
+++ b/catalog-ui/src/app/ng2/components/logic/capabilities-constraint/capabilities-constraint.component.ts
@@ -0,0 +1,61 @@
+/*
+* ============LICENSE_START=======================================================
+* SDC
+* ================================================================================
+* Copyright (C) 2020 Nordix Foundation. All rights reserved.
+* ================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* SPDX-License-Identifier: Apache-2.0
+* ============LICENSE_END=========================================================
+*/
+
+export class CapabilitiesConstraintObject {
+ capabilityName: string;
+ servicePropertyName: string;
+ constraintOperator: string;
+ sourceType: string;
+ sourceName: string;
+ value: string;
+
+ constructor(input?: any) {
+ if (input) {
+ this.capabilityName = input.capabilityName;
+ this.servicePropertyName = input.servicePropertyName;
+ this.constraintOperator = input.constraintOperator;
+ this.sourceType = input.sourceType;
+ this.sourceName = input.sourceName;
+ this.value = input.value;
+ }
+ }
+}
+
+export class CapabilitiesConstraintObjectUI extends CapabilitiesConstraintObject{
+ 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;
+ }
+}
diff --git a/catalog-ui/src/app/ng2/components/logic/service-dependencies/service-dependencies.component.html b/catalog-ui/src/app/ng2/components/logic/service-dependencies/service-dependencies.component.html
index ef5e29b049..5f6e992d96 100644
--- a/catalog-ui/src/app/ng2/components/logic/service-dependencies/service-dependencies.component.html
+++ b/catalog-ui/src/app/ng2/components/logic/service-dependencies/service-dependencies.component.html
@@ -24,13 +24,13 @@
[ngClass]="{'hand': !readonly}"
*ngFor="let capability of constraintCapabilities; let i = index">
<div class="filter-details" [ngClass]="{'readonly': readonly}">
- <div class="filter-desc" (click)="!readonly && onSelectNodeFilter(capabilities, i)"
+ <div class="filter-desc" (click)="!readonly && onSelectNodeFilterCapability(capabilities, i)"
tooltips
- tooltip="{{capability.servicePropertyName + ' ' + getSymbol(capability.constraintOperator) + ' '
- + (capability.sourceName ? capability.sourceName + ':' : '') + capability.value}}">
- {{capability.servicePropertyName + ' ' + getSymbol(capability.constraintOperator)
- + ' '
- + (capability.sourceName ? capability.sourceName + ':' : '') + capability.value}}
+ tooltip="{{capability.capabilityName + ' : ' +
+ capability.servicePropertyName + ' ' + getSymbol(capability.constraintOperator) + ' '
+ + (capability.sourceName ? capability.sourceName + ':' : '') + capability.value}}">
+ {{capability.capabilityName + ' : ' + capability.servicePropertyName + ' ' + getSymbol(capability.constraintOperator)
+ + ' ' + (capability.sourceName ? capability.sourceName + ':' : '') + capability.value}}
</div>
<span *ngIf="!readonly" class="sprite-new delete-btn delete-icon"
(click)="openDeleteModal(capabilities, i)"
@@ -42,7 +42,7 @@
<button
class="w-sdc-designer-sidebar-section-node-filter-footer-action add-rule-btn tlv-btn blue"
data-tests-id="add-rule-button"
- (click)="onAddNodeFilter(capabilities)"
+ (click)="onAddNodeFilterCapabilities()"
[disabled]="readonly">
{{'DIRECTIVES_AND_NODE_FILTER_ADD_NODE_FILTER' | translate}}
</button>
@@ -75,7 +75,7 @@
<button
class="w-sdc-designer-sidebar-section-node-filter-footer-action add-rule-btn tlv-btn blue"
data-tests-id="add-rule-button"
- (click)="onAddNodeFilter(properties)"
+ (click)="onAddNodeFilter()"
[disabled]="readonly">
{{'DIRECTIVES_AND_NODE_FILTER_ADD_NODE_FILTER' | translate}}
</button>
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..ff3779119d 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
@@ -20,6 +20,7 @@ import {
InputBEModel,
ModalModel,
PropertyBEModel,
+ PropertyModel,
} 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';
@@ -29,6 +30,9 @@ 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 {CapabilitiesFilterPropertiesEditorComponent} from "../../../pages/composition/capabilities-filter-properties-editor/capabilities-filter-properties-editor.component";
+import {CapabilitiesConstraintObject} from "../capabilities-constraint/capabilities-constraint.component";
+import {ToscaFilterConstraintType} from "../../../../models/tosca-filter-constraint-type.enum";
export class ConstraintObject {
servicePropertyName: string;
@@ -91,6 +95,8 @@ class I18nTexts {
static updateNodeFilterTxt: string;
static deleteNodeFilterTxt: string;
static deleteNodeFilterMsg: string;
+ static validateCapabilitiesTxt: string
+ static validateCapabilitiesMsg: string
public static translateTexts(translateService) {
I18nTexts.removeDirectiveModalTitle = translateService.translate('DIRECTIVES_AND_NODE_FILTER_REMOVE_TITLE');
@@ -106,6 +112,8 @@ 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');
}
}
@@ -123,10 +131,10 @@ export class ServiceDependenciesComponent {
isLoading: boolean;
parentServiceInputs: InputBEModel[] = [];
constraintProperties: ConstraintObject[] = [];
- constraintCapabilities: ConstraintObject[] = [];
+ constraintCapabilities: CapabilitiesConstraintObject[] = [];
operatorTypes: any[];
- capabilities: string = 'capabilities';
- properties: string = 'properties';
+ capabilities: string = ToscaFilterConstraintType.CAPABILITIES;
+ properties: string = ToscaFilterConstraintType.PROPERTIES;
private componentInstancesConstraints: ConstraintObject[] = [];
directiveOptions: string[];
@@ -138,10 +146,12 @@ export class ServiceDependenciesComponent {
@Input() selectedInstanceProperties: PropertyBEModel[] = [];
@Output() updateRulesListEvent: EventEmitter<ConstraintObject[]> = new EventEmitter<ConstraintObject[]>();
@Output() updateNodeFilterProperties: EventEmitter<ConstraintObject[]> = new EventEmitter<ConstraintObject[]>();
- @Output() updateNodeFilterCapabilities: EventEmitter<ConstraintObject[]> = new EventEmitter<ConstraintObject[]>();
+ @Output() updateNodeFilterCapabilities: EventEmitter<CapabilitiesConstraintObject[]> = new EventEmitter<CapabilitiesConstraintObject[]>();
@Output() loadRulesListEvent:EventEmitter<any> = new EventEmitter();
@Output() dependencyStatus = new EventEmitter<boolean>();
+ @Input() componentInstanceCapabilitiesMap: Map<string, PropertyModel[]>;
+
constructor(private topologyTemplateService: TopologyTemplateService, private modalServiceNg2: ModalService, private translateService: TranslateService) {
}
@@ -205,7 +215,7 @@ export class ServiceDependenciesComponent {
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;
+ const nodeFilterCapabilitiesResponse: CapabilitiesConstraintObject[] = response.nodeFilterforNode[this.currentServiceInstance.uniqueId].capabilities;
this.constraintCapabilities = nodeFilterCapabilitiesResponse;
}
});
@@ -270,10 +280,9 @@ export class ServiceDependenciesComponent {
});
}
- onAddNodeFilter = (constraintType: string) => {
- console.info("constraintType: ", constraintType);
+ onAddNodeFilter = () => {
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 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.addDynamicContentToModal(
@@ -291,9 +300,92 @@ export class ServiceDependenciesComponent {
this.modalInstance.instance.open();
}
+ onAddNodeFilterCapabilities = () => {
+ 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.addDynamicContentToModal(
+ this.modalInstance,
+ CapabilitiesFilterPropertiesEditorComponent,
+ {
+ currentServiceName: this.currentServiceInstance.name,
+ operatorTypes: this.operatorTypes,
+ compositeServiceName: this.compositeService.name,
+ parentServiceInputs: this.parentServiceInputs,
+ selectedInstanceProperties: this.selectedInstanceProperties,
+ selectedInstanceSiblings: this.selectedInstanceSiblings,
+ componentInstanceCapabilitiesMap: this.componentInstanceCapabilitiesMap
+ }
+ );
+ this.modalInstance.instance.open();
+ }
+ }
+
+ createNodeFilter = (constraintType: string) => {
+ this.isLoading = true;
+ this.topologyTemplateService.createServiceFilterConstraints(
+ this.compositeService.uniqueId,
+ this.currentServiceInstance.uniqueId,
+ new ConstraintObject(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) => {
+ this.isLoading = true;
+ this.topologyTemplateService.createServiceFilterCapabilitiesConstraints(
+ this.compositeService.uniqueId,
+ this.currentServiceInstance.uniqueId,
+ new CapabilitiesConstraintObject(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) {
+ const cancelButton: ButtonModel = new ButtonModel(I18nTexts.modalCancel, 'outline white', this.modalServiceNg2.closeCurrentModal);
+ 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(
+ this.modalInstance,
+ CapabilitiesFilterPropertiesEditorComponent,
+ {
+ serviceRuleIndex: index,
+ serviceRules: _.map(this.constraintCapabilities, (rule) => new CapabilitiesConstraintObject(rule)),
+ currentServiceName: this.currentServiceInstance.name,
+ operatorTypes: this.operatorTypes,
+ compositeServiceName: this.compositeService.name,
+ parentServiceInputs: this.parentServiceInputs,
+ selectedInstanceProperties: this.selectedInstanceProperties,
+ selectedInstanceSiblings: this.selectedInstanceSiblings,
+ componentInstanceCapabilitiesMap: this.componentInstanceCapabilitiesMap
+ }
+ );
+ this.modalInstance.instance.open();
+ }
+
onSelectNodeFilter(constraintType: string, index: number) {
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(
@@ -301,8 +393,7 @@ export class ServiceDependenciesComponent {
ServiceDependenciesEditorComponent,
{
serviceRuleIndex: index,
- serviceRules: _.map(this.properties == constraintType ? this.constraintProperties :
- this.constraintCapabilities, (rule) => new ConstraintObjectUI(rule)),
+ serviceRules: _.map(this.constraintProperties, (rule) => new ConstraintObjectUI(rule)),
currentServiceName: this.currentServiceInstance.name,
operatorTypes: this.operatorTypes,
compositeServiceName: this.compositeService.name,
@@ -315,19 +406,19 @@ export class ServiceDependenciesComponent {
}
getDisabled = (): boolean => {
- return !this.modalInstance.instance.dynamicContent.instance.checkFormValidForSubmit();
+ return false;
}
- createNodeFilter = (constraintType: string) => {
- const newRuleToCreate: ConstraintObject = new ConstraintObject(this.modalInstance.instance.dynamicContent.instance.currentRule);
+ updateNodeFilter = (constraintType: string, index: number) => {
this.isLoading = true;
- this.topologyTemplateService.createServiceFilterConstraints(
+ this.topologyTemplateService.updateServiceFilterConstraints(
this.compositeService.uniqueId,
this.currentServiceInstance.uniqueId,
- newRuleToCreate,
+ new ConstraintObject(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 +427,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) => {
this.isLoading = true;
- this.topologyTemplateService.updateServiceFilterConstraints(
+ this.topologyTemplateService.updateServiceFilterCapabilitiesConstraint(
this.compositeService.uniqueId,
this.currentServiceInstance.uniqueId,
- allRulesToUpdate,
+ new CapabilitiesConstraintObject(this.modalInstance.instance.dynamicContent.instance.currentRule),
this.compositeService.componentType,
- constraintType
+ constraintType,
+ index
).subscribe((response) => {
this.emitEventOnChanges(constraintType, response);
this.isLoading = false;