From 92b18f188105d5ba4b2c469cdfaedc7d2953d593 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Wed, 10 Aug 2022 14:50:08 +0100 Subject: Support TOSCA functions in Node Filters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds support to use tosca functions as value in the node property filters and substitution filters Change-Id: Id242691cc9ddd233245b58f052b9f0e2c7bbd66b Issue-ID: SDC-4128 Signed-off-by: André Schmid --- .../tosca-concat-function.component.ts | 29 ++++++----- .../tosca-function/tosca-function.component.html | 2 +- .../tosca-function/tosca-function.component.ts | 58 +++++++++++++++++----- .../tosca-function/tosca-function.module.ts | 4 +- .../tosca-get-function.component.ts | 1 + 5 files changed, 65 insertions(+), 29 deletions(-) (limited to 'catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function') diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.ts index d808c284a8..ef45211ea0 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-concat-function/tosca-concat-function.component.ts @@ -8,6 +8,7 @@ import {PropertyBEModel} from "../../../../../models/properties-inputs/property- import {PROPERTY_TYPES} from "../../../../../utils/constants"; import {InstanceFeDetails} from "../../../../../models/instance-fe-details"; import {ToscaFunctionValidationEvent} from "../tosca-function.component"; +import {ToscaFunction} from "../../../../../models/tosca-function"; @Component({ selector: 'app-tosca-concat-function', @@ -30,7 +31,6 @@ export class ToscaConcatFunctionComponent implements OnInit { parameters: ToscaFunctionParameter[] = []; propertyInputList: Array = []; - stringProperty: PropertyBEModel STRING_FUNCTION_TYPE = ToscaFunctionType.STRING @@ -44,7 +44,7 @@ export class ToscaConcatFunctionComponent implements OnInit { this.initForm(); } - private initForm() { + private initForm(): void { this.formGroup.valueChanges.subscribe(() => { this.onValidityChange.emit({ isValid: this.formGroup.valid, @@ -57,12 +57,13 @@ export class ToscaConcatFunctionComponent implements OnInit { if (!this.toscaConcatFunction) { return; } - if (this.toscaConcatFunction.parameters) { this.parameters = Array.from(this.toscaConcatFunction.parameters); for (const parameter of this.parameters) { if (parameter.type !== PROPERTY_TYPES.STRING) { - this.propertyInputList.push(this.createStringProperty(parameter)); + const propertyBEModel = this.createStringProperty(parameter.value); + propertyBEModel.toscaFunction = parameter; + this.propertyInputList.push(propertyBEModel); this.concatParameterFormArray.push( new FormControl(parameter, [Validators.required, Validators.minLength(1)]) ); @@ -92,7 +93,7 @@ export class ToscaConcatFunctionComponent implements OnInit { return toscaConcatFunction1; } - addFunction() { + addFunction(): void { this.propertyInputList.push(this.createStringProperty()); this.parameters.push({} as ToscaFunctionParameter); this.concatParameterFormArray.push( @@ -100,32 +101,30 @@ export class ToscaConcatFunctionComponent implements OnInit { ); } - addStringParameter() { - this.parameters.push({ - type: ToscaFunctionType.STRING, - value: '' - }); + addStringParameter(): void { + const toscaStringParameter = new ToscaStringParameter(); + toscaStringParameter.value = '' + this.parameters.push(toscaStringParameter); this.propertyInputList.push(undefined); this.concatParameterFormArray.push( new FormControl('', [Validators.required, Validators.minLength(1)]) ); } - removeParameter(position) { + removeParameter(position): void { this.propertyInputList.splice(position, 1); this.parameters.splice(position, 1); this.concatParameterFormArray.removeAt(position); } - createStringProperty(toscaFunctionParameter?: ToscaFunctionParameter) { + createStringProperty(value?: any): PropertyBEModel { const property = new PropertyBEModel(); property.type = PROPERTY_TYPES.STRING; - property.toscaFunction = toscaFunctionParameter ? toscaFunctionParameter : undefined; - property.value = toscaFunctionParameter ? toscaFunctionParameter.value : undefined; + property.value = value ? value : undefined; return property; } - onFunctionValidityChange(event: ToscaFunctionValidationEvent, index: number) { + onFunctionValidityChange(event: ToscaFunctionValidationEvent, index: number): void { if (event.isValid && event.toscaFunction) { this.concatParameterFormArray.controls[index].setValue(event.toscaFunction) } else { 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 f93973cb16..8ee253e5dc 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 @@ -21,7 +21,7 @@
- diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts index 70df4eaced..e40a4d6e1e 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts @@ -17,7 +17,7 @@ * ============LICENSE_END========================================================= */ -import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; +import {Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core'; import {ComponentMetadata, PropertyBEModel, PropertyDeclareAPIModel} from 'app/models'; import {TopologyTemplateService} from "../../../services/component-services/topology-template.service"; import {WorkspaceService} from "../../workspace/workspace.service"; @@ -31,13 +31,15 @@ import {ToscaFunction} from "../../../../models/tosca-function"; import {ToscaConcatFunctionValidationEvent} from "./tosca-concat-function/tosca-concat-function.component"; import {PROPERTY_TYPES} from "../../../../utils/constants"; import {YamlFunctionValidationEvent} from "./yaml-function/yaml-function.component"; +import {ToscaConcatFunction} from "../../../../models/tosca-concat-function"; +import {YamlFunction} from "../../../../models/yaml-function"; @Component({ selector: 'tosca-function', templateUrl: './tosca-function.component.html', styleUrls: ['./tosca-function.component.less'], }) -export class ToscaFunctionComponent implements OnInit { +export class ToscaFunctionComponent implements OnInit, OnChanges { @Input() property: PropertyBEModel; @Input() componentInstanceMap: Map = new Map(); @@ -81,11 +83,21 @@ export class ToscaFunctionComponent implements OnInit { this.isInitialized = true; } - private validate() { + ngOnChanges(changes: SimpleChanges): void { + if (changes.property) { + this.resetForm(); + this.toscaFunction = this.property.toscaFunction ? this.property.toscaFunction : undefined; + this.initToscaFunction(); + this.loadToscaFunctions(); + this.emitValidityChange(); + } + } + + private validate(): boolean { return (!this.toscaFunctionForm.value && !this.toscaFunctionTypeForm.value) || this.formGroup.valid; } - private initToscaFunction() { + private initToscaFunction(): void { if (this.property instanceof PropertyDeclareAPIModel && this.property.subPropertyToscaFunctions && ( this.property).propertiesName){ let propertiesPath = ( this.property).propertiesName.split("#"); if (propertiesPath.length > 1){ @@ -100,7 +112,7 @@ export class ToscaFunctionComponent implements OnInit { return; } } - + if (!this.property.isToscaFunction()) { return; } @@ -113,6 +125,7 @@ export class ToscaFunctionComponent implements OnInit { } private loadToscaFunctions(): void { + this.toscaFunctions = []; this.toscaFunctions.push(ToscaFunctionType.GET_ATTRIBUTE); this.toscaFunctions.push(ToscaFunctionType.GET_INPUT); this.toscaFunctions.push(ToscaFunctionType.GET_PROPERTY); @@ -151,7 +164,7 @@ export class ToscaFunctionComponent implements OnInit { return this.formGroup.get('toscaFunctionType').value === ToscaFunctionType.YAML; } - onClearValues() { + onClearValues(): void { this.resetForm(); } @@ -159,7 +172,7 @@ export class ToscaFunctionComponent implements OnInit { return this.allowClear && this.toscaFunctionTypeForm.value; } - onConcatFunctionValidityChange(validationEvent: ToscaConcatFunctionValidationEvent) { + onConcatFunctionValidityChange(validationEvent: ToscaConcatFunctionValidationEvent): void { if (validationEvent.isValid) { this.toscaFunctionForm.setValue(validationEvent.toscaConcatFunction); } else { @@ -167,7 +180,7 @@ export class ToscaFunctionComponent implements OnInit { } } - onGetFunctionValidityChange(validationEvent: ToscaGetFunctionValidationEvent) { + onGetFunctionValidityChange(validationEvent: ToscaGetFunctionValidationEvent): void { if (validationEvent.isValid) { this.toscaFunctionForm.setValue(validationEvent.toscaGetFunction); } else { @@ -175,7 +188,7 @@ export class ToscaFunctionComponent implements OnInit { } } - onYamlFunctionValidityChange(validationEvent: YamlFunctionValidationEvent) { + onYamlFunctionValidityChange(validationEvent: YamlFunctionValidationEvent): void { if (validationEvent.isValid) { this.toscaFunctionForm.setValue(validationEvent.value); } else { @@ -183,14 +196,35 @@ export class ToscaFunctionComponent implements OnInit { } } - private emitValidityChange() { - const isValid = this.validate(); + onFunctionTypeChange(): void { + this.toscaFunction = undefined; + this.toscaFunctionForm.reset(); + } + + private emitValidityChange(): void { + const isValid: boolean = this.validate(); this.onValidityChange.emit({ isValid: isValid, - toscaFunction: isValid ? this.toscaFunctionForm.value : undefined + toscaFunction: isValid ? this.buildFunctionFromForm() : undefined }); } + private buildFunctionFromForm(): ToscaFunction { + if (!this.toscaFunctionTypeForm.value) { + return undefined; + } + if (this.isConcatSelected()) { + return new ToscaConcatFunction(this.toscaFunctionForm.value); + } + if (this.isGetFunctionSelected()) { + return new ToscaGetFunction(this.toscaFunctionForm.value); + } + if (this.isYamlFunctionSelected()) { + return new YamlFunction(this.toscaFunctionForm.value); + } + + console.error(`Function ${this.toscaFunctionTypeForm.value} not supported`); + } } export class ToscaFunctionValidationEvent { diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.module.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.module.ts index 19cf2fb260..bcf10728f8 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.module.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.module.ts @@ -45,7 +45,9 @@ import { YamlFunctionComponent } from './yaml-function/yaml-function.component'; TranslateModule, SdcUiComponentsModule ], - exports: [], + exports: [ + ToscaFunctionComponent + ], entryComponents: [ ToscaFunctionComponent ], diff --git a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts index 1f658f968a..a32a4d0e45 100644 --- a/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts +++ b/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-get-function/tosca-get-function.component.ts @@ -426,6 +426,7 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges { } onPropertySourceChange(): void { + this.selectedProperty.reset(); if (!this.functionType || !this.propertySource.valid) { return; } -- cgit 1.2.3-korg