From d5edf5274286e9808dfabf2f49a03a1ba235b70c Mon Sep 17 00:00:00 2001 From: aribeiro Date: Thu, 18 Nov 2021 10:29:39 +0000 Subject: Add node filter with getInput function Support get_input functions for creating node and substitution filters Issue-ID: SDC-3793 Signed-off-by: aribeiro Change-Id: Ie00f621be8418b4a9c88afcbbc07d80c22165e9b --- .../service-dependencies.component.ts | 7 +- .../substitution-filter.component.ts | 13 +- .../substitution-filter-tab.component.html | 5 +- .../substitution-filter-tab.component.ts | 23 ++-- .../service-dependencies-editor.component.html | 10 +- .../service-dependencies-editor.component.ts | 136 ++++++++++++++------- .../topology-template.service.ts | 6 +- 7 files changed, 127 insertions(+), 73 deletions(-) (limited to 'catalog-ui') 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 f9f9286fe5..35e80dc70a 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 @@ -134,6 +134,7 @@ export class ServiceDependenciesComponent { isDependent: boolean; isLoading: boolean; parentServiceInputs: InputBEModel[] = []; + parentServiceProperties: PropertyBEModel[] = []; constraintProperties: ConstraintObject[] = []; constraintCapabilities: CapabilitiesConstraintObject[] = []; operatorTypes: any[]; @@ -167,8 +168,10 @@ export class ServiceDependenciesComponent { {label: '<', value: OPERATOR_TYPES.LESS_THAN}, {label: '=', value: OPERATOR_TYPES.EQUAL} ]; - 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.loadNodeFilter(); this.translateService.languageChangedObservable.subscribe((lang) => { @@ -300,6 +303,7 @@ export class ServiceDependenciesComponent { operatorTypes: this.operatorTypes, compositeServiceName: this.compositeService.name, parentServiceInputs: this.parentServiceInputs, + parentServiceProperties: this.parentServiceProperties, selectedInstanceProperties: this.selectedInstanceProperties, selectedInstanceSiblings: this.selectedInstanceSiblings } @@ -406,6 +410,7 @@ export class ServiceDependenciesComponent { operatorTypes: this.operatorTypes, compositeServiceName: this.compositeService.name, parentServiceInputs: this.parentServiceInputs, + parentServiceProperties: this.parentServiceProperties, selectedInstanceProperties: this.selectedInstanceProperties, selectedInstanceSiblings: this.selectedInstanceSiblings } diff --git a/catalog-ui/src/app/ng2/components/logic/substitution-filter/substitution-filter.component.ts b/catalog-ui/src/app/ng2/components/logic/substitution-filter/substitution-filter.component.ts index e0754af549..7671d653e4 100644 --- a/catalog-ui/src/app/ng2/components/logic/substitution-filter/substitution-filter.component.ts +++ b/catalog-ui/src/app/ng2/components/logic/substitution-filter/substitution-filter.component.ts @@ -30,7 +30,6 @@ import {ServiceDependenciesEditorComponent} from 'app/ng2/pages/service-dependen import {ModalService} from 'app/ng2/services/modal.service'; 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"; @@ -112,7 +111,6 @@ class I18nTexts { export class SubstitutionFilterComponent { modalInstance: ComponentRef; isLoading: boolean; - parentServiceInputs: InputBEModel[] = []; operatorTypes: any[]; constraintProperties: ConstraintObject[] = []; PROPERTIES: string = ToscaFilterConstraintType.PROPERTIES; @@ -120,9 +118,10 @@ export class SubstitutionFilterComponent { @Input() readonly: boolean; @Input() compositeService: ComponentMetadata; @Input() currentServiceInstance: ComponentInstance; - @Input() selectedInstanceSiblings: ServiceInstanceObject[]; @Input() selectedInstanceConstraints: ConstraintObject[] = []; @Input() selectedInstanceProperties: PropertyBEModel[] = []; + @Input() parentServiceProperties: PropertyBEModel[] = []; + @Input() parentServiceInputs: InputBEModel[] = []; @Output() updateSubstitutionFilterProperties: EventEmitter = new EventEmitter(); @Output() updateConstraintListEvent: EventEmitter = new EventEmitter(); @Output() loadConstraintListEvent: EventEmitter = new EventEmitter(); @@ -176,8 +175,8 @@ export class SubstitutionFilterComponent { operatorTypes: this.operatorTypes, compositeServiceName: this.compositeService.name, parentServiceInputs: this.parentServiceInputs, - selectedInstanceProperties: this.selectedInstanceProperties, - selectedInstanceSiblings: this.selectedInstanceSiblings + parentServiceProperties: this.parentServiceProperties, + selectedInstanceProperties: this.parentServiceProperties, } ); this.modalInstance.instance.open(); @@ -216,8 +215,8 @@ export class SubstitutionFilterComponent { operatorTypes: this.operatorTypes, compositeServiceName: this.compositeService.name, parentServiceInputs: this.parentServiceInputs, - selectedInstanceProperties: this.selectedInstanceProperties, - selectedInstanceSiblings: this.selectedInstanceSiblings + parentServiceProperties: this.parentServiceProperties, + selectedInstanceProperties: this.parentServiceProperties, } ); this.modalInstance.instance.open(); diff --git a/catalog-ui/src/app/ng2/pages/composition/panel/panel-tabs/substitution-filter-tab/substitution-filter-tab.component.html b/catalog-ui/src/app/ng2/pages/composition/panel/panel-tabs/substitution-filter-tab/substitution-filter-tab.component.html index c8845deece..a9fad5a733 100644 --- a/catalog-ui/src/app/ng2/pages/composition/panel/panel-tabs/substitution-filter-tab/substitution-filter-tab.component.html +++ b/catalog-ui/src/app/ng2/pages/composition/panel/panel-tabs/substitution-filter-tab/substitution-filter-tab.component.html @@ -23,8 +23,9 @@ { - this.topologyTemplateService.getComponentPropertiesSubstitutionFilter(this.metaData.componentType, this.metaData.uniqueId).subscribe((genericResponse: ComponentGenericResponse) => { - this.selectedInstanceProperties = genericResponse.properties; - this.updateInstanceAttributes(); + this.topologyTemplateService.getComponentPropertiesAndInputsForSubstitutionFilter(this.metaData.componentType, this.metaData.uniqueId) + .subscribe((genericResponse: ComponentGenericResponse) => { + this.parentServiceProperties = genericResponse.properties; + this.parentServiceInputs = genericResponse.inputs; }); } - private updateInstanceAttributes = (): void => { - if (this.isComponentInstanceSelected && this.componentInstanceProperties) { - const instancesMappedList = this.compositionService.componentInstances.map((coInstance) => new ServiceInstanceObject({ - id: coInstance.uniqueId, - name: coInstance.name, - properties: this.componentInstanceProperties[coInstance.uniqueId] || [] - })); - this.selectedInstanceProperties = this.componentInstanceProperties[this.component.uniqueId]; - this.selectedInstanceSiblings = instancesMappedList.filter((coInstance) => coInstance.id !== this.component.uniqueId); - } - } } diff --git a/catalog-ui/src/app/ng2/pages/service-dependencies-editor/service-dependencies-editor.component.html b/catalog-ui/src/app/ng2/pages/service-dependencies-editor/service-dependencies-editor.component.html index f84214e4ce..8a577aef77 100644 --- a/catalog-ui/src/app/ng2/pages/service-dependencies-editor/service-dependencies-editor.component.html +++ b/catalog-ui/src/app/ng2/pages/service-dependencies-editor/service-dependencies-editor.component.html @@ -6,7 +6,7 @@
- +
+ + +
+ +
- +
+
diff --git a/catalog-ui/src/app/ng2/pages/service-dependencies-editor/service-dependencies-editor.component.ts b/catalog-ui/src/app/ng2/pages/service-dependencies-editor/service-dependencies-editor.component.ts index cb3e87c8d1..c6b3b65512 100644 --- a/catalog-ui/src/app/ng2/pages/service-dependencies-editor/service-dependencies-editor.component.ts +++ b/catalog-ui/src/app/ng2/pages/service-dependencies-editor/service-dependencies-editor.component.ts @@ -56,6 +56,7 @@ export class ServiceDependenciesEditorComponent { compositeServiceName: string, currentServiceName: string, parentServiceInputs: InputBEModel[], + parentServiceProperties: PropertyBEModel[]; selectedInstanceProperties: PropertyBEModel[], operatorTypes: DropdownValue[], selectedInstanceSiblings: ServiceInstanceObject[] @@ -65,6 +66,7 @@ export class ServiceDependenciesEditorComponent { selectedPropertyObj: PropertyFEModel; ddValueSelectedServicePropertiesNames: DropdownValue[]; operatorTypes: DropdownValue[]; + functionTypes: DropdownValue[]; sourceTypes: UIDropDownSourceTypesElement[] = []; currentRule: ConstraintObjectUI; currentIndex: number; @@ -75,7 +77,8 @@ export class ServiceDependenciesEditorComponent { SOURCE_TYPES = { STATIC: {label: 'Static', value: 'static'}, - SERVICE_PROPERTY: {label: 'Service Property', value: 'property'} + SERVICE_PROPERTY: {label: 'Service Property', value: 'property'}, + SERVICE_INPUT: {label: 'Service Input', value: 'service_input'} }; constructor(private propertiesUtils: PropertiesUtils) {} @@ -83,6 +86,19 @@ export class ServiceDependenciesEditorComponent { ngOnInit() { this.currentIndex = this.input.serviceRuleIndex; this.serviceRulesList = this.input.serviceRules; + this.initCurrentRule(); + this.currentServiceName = this.input.currentServiceName; + this.operatorTypes = this.input.operatorTypes; + this.selectedServiceProperties = this.input.selectedInstanceProperties; + this.ddValueSelectedServicePropertiesNames = _.map(this.input.selectedInstanceProperties, (prop) => new DropdownValue(prop.name, prop.name)); + this.initFunctionTypes(); + if (this.SOURCE_TYPES.STATIC.value !== this.currentRule.sourceType) { + this.loadSourceTypesData(); + } + this.syncRuleData(); + } + + private initCurrentRule() { this.currentRule = this.serviceRulesList && this.input.serviceRuleIndex >= 0 ? this.serviceRulesList[this.input.serviceRuleIndex] : new ConstraintObjectUI({ @@ -91,39 +107,73 @@ export class ServiceDependenciesEditorComponent { value: '', constraintOperator: OPERATOR_TYPES.EQUAL }); - this.currentServiceName = this.input.currentServiceName; - this.operatorTypes = this.input.operatorTypes; - this.selectedServiceProperties = this.input.selectedInstanceProperties; - this.ddValueSelectedServicePropertiesNames = _.map(this.input.selectedInstanceProperties, (prop) => new DropdownValue(prop.name, prop.name)); - this.initSourceTypes(); - this.syncRuleData(); + if (this.currentRule && this.currentRule.sourceType === this.SOURCE_TYPES.SERVICE_INPUT.value) { + this.currentRule.sourceName = this.input.compositeServiceName; + } + } + + private initFunctionTypes() { + this.functionTypes = [ + {label: this.SOURCE_TYPES.STATIC.label, value: this.SOURCE_TYPES.STATIC.value}, + {label: this.SOURCE_TYPES.SERVICE_PROPERTY.label, value: this.SOURCE_TYPES.SERVICE_PROPERTY.value}, + {label: this.SOURCE_TYPES.SERVICE_INPUT.label, value: this.SOURCE_TYPES.SERVICE_INPUT.value}]; + } + + onServicePropertyChanged() { + this.updateSelectedPropertyObj(); + this.updateOperatorTypesList(); + this.currentRule.sourceName = ""; + this.currentRule.value = ""; + } + + onSelectFunctionType() { + this.currentRule.value = ""; + this.currentRule.sourceName = ""; + this.listOfValuesToAssign = []; + this.currentRule.sourceType = this.updateCurrentSourceType(this.currentRule.sourceType); + this.loadSourceTypesData(); this.updateSourceTypesRelatedValues(); } - initSourceTypes() { - this.sourceTypes.push({ - label: this.SOURCE_TYPES.STATIC.label, - value: this.SOURCE_TYPES.STATIC.value, - options: [], - assignedLabel: this.SOURCE_TYPES.STATIC.label, - type: this.SOURCE_TYPES.STATIC.value - }); + onSelectSourceType() { + this.currentRule.value = ""; + this.updateSourceTypesRelatedValues(); + } + + loadSourceTypesData() { + this.sourceTypes = []; this.sourceTypes.push({ label: this.input.compositeServiceName, value: this.input.compositeServiceName, - assignedLabel: this.SOURCE_TYPES.SERVICE_PROPERTY.label, - type: this.SOURCE_TYPES.SERVICE_PROPERTY.value, - options: this.input.parentServiceInputs + assignedLabel: this.currentRule.sourceType == this.SOURCE_TYPES.SERVICE_PROPERTY.value + ? this.SOURCE_TYPES.SERVICE_PROPERTY.label : this.SOURCE_TYPES.SERVICE_INPUT.label, + type: this.currentRule.sourceType == this.SOURCE_TYPES.SERVICE_PROPERTY.value + ? this.SOURCE_TYPES.SERVICE_PROPERTY.value : this.SOURCE_TYPES.SERVICE_INPUT.value, + options: this.loadSourceTypeBySelectedFunction().get(this.currentRule.sourceType) }); - _.forEach(this.input.selectedInstanceSiblings, (sib) => - this.sourceTypes.push({ - label: sib.name, - value: sib.name, - options: sib.properties || [], - assignedLabel: this.SOURCE_TYPES.SERVICE_PROPERTY.label, - type: this.SOURCE_TYPES.SERVICE_PROPERTY.value - }) - ); + + if (this.currentRule.sourceType === this.SOURCE_TYPES.SERVICE_INPUT.value) { + this.currentRule.sourceName = this.input.compositeServiceName; + } else { + if (this.input.selectedInstanceSiblings && this.isPropertyFunctionSelected) { + _.forEach(this.input.selectedInstanceSiblings, (sib) => + this.sourceTypes.push({ + label: sib.name, + value: sib.name, + options: sib.properties || [], + assignedLabel: this.SOURCE_TYPES.SERVICE_PROPERTY.label, + type: this.SOURCE_TYPES.SERVICE_PROPERTY.value + }) + ); + } + } + } + + loadSourceTypeBySelectedFunction = (): any => { + let parentDataMap = new Map(); + parentDataMap.set(this.SOURCE_TYPES.SERVICE_PROPERTY.value, this.input.parentServiceProperties); + parentDataMap.set(this.SOURCE_TYPES.SERVICE_INPUT.value , this.input.parentServiceInputs); + return parentDataMap; } syncRuleData() { @@ -151,6 +201,7 @@ export class ServiceDependenciesEditorComponent { (t) => t.value === this.currentRule.sourceName && t.type === this.currentRule.sourceType ); if (selectedSourceType) { + this.listOfSourceOptions = []; this.listOfSourceOptions = selectedSourceType.options || []; this.assignedValueLabel = selectedSourceType.assignedLabel || this.SOURCE_TYPES.STATIC.label; this.filterOptionsByType(); @@ -166,19 +217,15 @@ export class ServiceDependenciesEditorComponent { } } - onServicePropertyChanged() { - this.currentRule.value = ''; - this.updateSelectedPropertyObj(); - this.updateOperatorTypesList(); - this.filterOptionsByType(); - } - - onSelectSourceType() { - this.currentRule.value = ''; - this.currentRule.sourceType = this.currentRule.sourceName === this.SOURCE_TYPES.STATIC.value ? - this.SOURCE_TYPES.STATIC.value : - this.SOURCE_TYPES.SERVICE_PROPERTY.value; - this.updateSourceTypesRelatedValues(); + private updateCurrentSourceType = (sourceType: string): string => { + switch (sourceType) { + case this.SOURCE_TYPES.STATIC.value: + return this.SOURCE_TYPES.STATIC.value; + case this.SOURCE_TYPES.SERVICE_PROPERTY.value: + return this.SOURCE_TYPES.SERVICE_PROPERTY.value; + case this.SOURCE_TYPES.SERVICE_INPUT.value: + return this.SOURCE_TYPES.SERVICE_INPUT.value; + } } filterOptionsByType() { @@ -214,7 +261,9 @@ export class ServiceDependenciesEditorComponent { newProp.value = JSON.stringify(this.currentRule.value); this.propertiesUtils.initValueObjectRef(newProp); console.log("TEST" + newProp.value); - setTimeout(() => {this.selectedPropertyObj = newProp}) + setTimeout(() => { + this.selectedPropertyObj = newProp}) + this.selectedPropertyObj = newProp; } } @@ -222,6 +271,10 @@ export class ServiceDependenciesEditorComponent { return this.currentRule.sourceType === this.SOURCE_TYPES.STATIC.value } + isPropertyFunctionSelected(): boolean { + return this.currentRule.sourceType === this.SOURCE_TYPES.SERVICE_PROPERTY.value; + } + isComplexListMapType(): boolean { return this.selectedPropertyObj && this.selectedPropertyObj.derivedDataType > 0; } @@ -231,4 +284,5 @@ export class ServiceDependenciesEditorComponent { this.currentRule.value = JSON.stringify(value); this.onValueChange(this.selectedPropertyObj.valueObjIsValid); } + } diff --git a/catalog-ui/src/app/ng2/services/component-services/topology-template.service.ts b/catalog-ui/src/app/ng2/services/component-services/topology-template.service.ts index 7b726e4172..20425f810a 100644 --- a/catalog-ui/src/app/ng2/services/component-services/topology-template.service.ts +++ b/catalog-ui/src/app/ng2/services/component-services/topology-template.service.ts @@ -483,8 +483,8 @@ export class TopologyTemplateService { return this.http.delete(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/' + constraintIndex + '/nodeFilter') } - getComponentPropertiesSubstitutionFilter(componentType: string, componentId: string): Observable { - return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES]); + getComponentPropertiesAndInputsForSubstitutionFilter(componentType: string, componentId: string): Observable { + return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INPUTS]); } createSubstitutionFilterConstraints(componentMetaDataId: string, constraint: ConstraintObject, componentType: string, constraintType: string): Observable { @@ -536,7 +536,6 @@ export class TopologyTemplateService { } protected getComponentDataByFieldsName(componentType: string, componentId: string, fields: string[]): Observable { - console.info("Topology template -> getComponentDataByFieldsName with id:", componentId) let params: HttpParams = new HttpParams(); _.forEach(fields, (field: string): void => { params = params.append(API_QUERY_PARAMS.INCLUDE, field); @@ -544,7 +543,6 @@ export class TopologyTemplateService { // tslint:disable-next-line:object-literal-shorthand return this.http.get(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/filteredDataByParams', {params: params}) .map((res) => { - console.info("Topology template -> getComponentDataByFieldsName response:", res); return componentType === ComponentType.SERVICE ? new ServiceGenericResponse().deserialize(res) : new ComponentGenericResponse().deserialize(res); }); -- cgit 1.2.3-korg