From df1d6ebebe45708040048abc33aebb8980a0c9f2 Mon Sep 17 00:00:00 2001 From: franciscovila Date: Tue, 20 Jun 2023 10:38:45 +0100 Subject: Support custom tosca functions in operation input values Issue-ID: SDC-4545 Signed-off-by: franciscovila Change-Id: Icd466d4e2e1d2136f6e41b5c345e9244d5f295f6 --- .../service-dependencies.component.ts | 18 ++++++++++++++++++ .../tosca-custom-function.component.ts | 3 ++- .../tosca-function/tosca-function.component.html | 1 + .../service-dependencies-editor.component.html | 4 ++++ .../service-dependencies-editor.component.ts | 19 +++++++++++-------- catalog-ui/src/app/utils/filter-constraint-helper.ts | 4 +++- catalog-ui/src/app/utils/tosca-function-helper.ts | 3 +++ 7 files changed, 42 insertions(+), 10 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 9a63dff739..a0588c0daa 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 @@ -30,6 +30,7 @@ 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', @@ -99,6 +100,7 @@ export class ServiceDependenciesComponent implements OnInit, OnChanges { properties: string = ToscaFilterConstraintType.PROPERTIES; private componentInstancesConstraints: FilterConstraint[] = []; isEditable: boolean; + customToscaFunctions: Array; @Input() readonly: boolean; @Input() compositeService: ComponentMetadata; @@ -138,12 +140,24 @@ export class ServiceDependenciesComponent implements OnInit, OnChanges { this.parentServiceInputs = result.inputs; this.parentServiceProperties = result.properties; }); + this.initCustomToscaFunctions(); this.loadNodeFilter(); this.translateService.languageChangedObservable.subscribe((lang) => { I18nTexts.translateTexts(this.translateService); }); } + 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; @@ -264,6 +278,7 @@ export class ServiceDependenciesComponent implements OnInit, OnChanges { 'parentServiceInputs': this.parentServiceInputs, 'parentServiceProperties': this.parentServiceProperties, 'selectedInstanceProperties': this.selectedInstanceProperties, + 'customToscaFunctions': this.customToscaFunctions, 'filterType': FilterType.PROPERTY, } ); @@ -298,6 +313,7 @@ export class ServiceDependenciesComponent implements OnInit, OnChanges { } createNodeFilter = (constraintType: string): void => { + this.customToscaFunctions = this.modalInstance.instance.dynamicContent.instance.customToscaFunctions; this.isLoading = true; this.topologyTemplateService.createServiceFilterConstraints( this.compositeService.uniqueId, @@ -372,9 +388,11 @@ export class ServiceDependenciesComponent implements OnInit, OnChanges { 'parentServiceInputs': this.parentServiceInputs, 'parentServiceProperties': this.parentServiceProperties, 'selectedInstanceProperties': this.selectedInstanceProperties, + 'customToscaFunctions': this.customToscaFunctions, 'filterType': FilterType.PROPERTY } ); + this.modalInstance.instance.open(); } diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-custom-function/tosca-custom-function.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-custom-function/tosca-custom-function.component.ts index ad72adad22..7db332236b 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-custom-function/tosca-custom-function.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-custom-function/tosca-custom-function.component.ts @@ -49,6 +49,7 @@ export class ToscaCustomFunctionComponent implements OnInit { @Input() propertyType: string; @Input() propertySchemaType: string = undefined; @Input() isDefaultCustomFunction: boolean; + @Input() overridingType: PROPERTY_TYPES; @Output() onValidFunction: EventEmitter = new EventEmitter(); @Output() onValidityChange: EventEmitter = new EventEmitter(); @@ -194,7 +195,7 @@ export class ToscaCustomFunctionComponent implements OnInit { createProperty(value?: any): PropertyBEModel { const property = new PropertyBEModel(); if (this.type === this.GET_INPUT) { - property.type = this.propertyType; + property.type = this.overridingType ? this.overridingType.toString() : this.propertyType; if (this.propertySchemaType) { property.schemaType = this.propertySchemaType; } diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.html b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.html index 0d5a4973da..db96f1cece 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.html +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.html @@ -45,6 +45,7 @@ [propertyType]="property.type" [propertySchemaType]="property.schemaType" [componentInstanceMap]="componentInstanceMap" + [overridingType]="overridingType" [isDefaultCustomFunction]="isDefaultCustomFunction()" (onValidityChange)="onCustomFunctionValidityChange($event)"> 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 c90cfd8210..b5cc0cdc9e 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 @@ -77,6 +77,8 @@ @@ -103,6 +105,7 @@ @@ -123,6 +126,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 5897f272b3..d560285be9 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 @@ -72,6 +72,7 @@ export class ServiceDependenciesEditorComponent implements OnInit { @Input() capabilityNameAndPropertiesMap: Map; @Input() filterType: FilterType; @Input() filterConstraint: PropertyFilterConstraintUi; + @Input() customToscaFunctions: Array; //output currentRule: PropertyFilterConstraintUi; @@ -100,7 +101,7 @@ export class ServiceDependenciesEditorComponent implements OnInit { selectedProperty: PropertyFEModel; selectedSourceType: string; componentInstanceMap: Map = new Map(); - customToscaFunctions: Array; + capabilityDropdownList: DropdownValue[] = []; validValuesToscaFunctionList: ToscaFunction[]; rangeToscaFunctionList: ToscaFunction[]; @@ -133,13 +134,15 @@ export class ServiceDependenciesEditorComponent implements OnInit { } private initCustomToscaFunctions() { - this.customToscaFunctions = []; - this.topologyTemplateService.getDefaultCustomFunction().toPromise().then((data) => { - for (let customFunction of data) { - this.customToscaFunctions.push(new CustomToscaFunction(customFunction)); - } - }); -} + if (!this.customToscaFunctions) { + this.customToscaFunctions = []; + this.topologyTemplateService.getDefaultCustomFunction().toPromise().then((data) => { + for (let customFunction of data) { + this.customToscaFunctions.push(new CustomToscaFunction(customFunction)); + } + }); + } + } private initCapabilityDropdown(): void { if (this.filterType == FilterType.CAPABILITY) { diff --git a/catalog-ui/src/app/utils/filter-constraint-helper.ts b/catalog-ui/src/app/utils/filter-constraint-helper.ts index 7ee9d27efe..2666bbfd81 100644 --- a/catalog-ui/src/app/utils/filter-constraint-helper.ts +++ b/catalog-ui/src/app/utils/filter-constraint-helper.ts @@ -27,9 +27,11 @@ export class FilterConstraintHelper { public static buildFilterConstraintLabel(constraint: FilterConstraint): string { let value; if (ToscaFunctionHelper.isValueToscaFunction(constraint.value)) { + console.error(constraint.value); const toscaFunction = ToscaFunctionHelper.convertObjectToToscaFunction(constraint.value); if (toscaFunction) { - value = toscaFunction.buildValueString(); + value = toscaFunction.value; + console.error(value); } else { value = JSON.stringify(constraint.value, null, 4); } diff --git a/catalog-ui/src/app/utils/tosca-function-helper.ts b/catalog-ui/src/app/utils/tosca-function-helper.ts index 714f22ef57..7cef768770 100644 --- a/catalog-ui/src/app/utils/tosca-function-helper.ts +++ b/catalog-ui/src/app/utils/tosca-function-helper.ts @@ -24,6 +24,7 @@ import {ToscaConcatFunction} from "../models/tosca-concat-function"; import {ToscaGetFunction} from "../models/tosca-get-function"; import {YamlFunction} from "../models/yaml-function"; import {ToscaFunction} from "../models/tosca-function"; +import {ToscaCustomFunction} from "../models/tosca-custom-function"; export class ToscaFunctionHelper { @@ -41,6 +42,8 @@ export class ToscaFunctionHelper { return new ToscaGetFunction(value); case ToscaFunctionType.YAML: return new YamlFunction(value); + case ToscaFunctionType.CUSTOM: + return new ToscaCustomFunction(value); case ToscaFunctionType.STRING: return { type: ToscaFunctionType.STRING, -- cgit 1.2.3-korg