aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-08-10 14:50:08 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2022-09-08 18:24:44 +0000
commit92b18f188105d5ba4b2c469cdfaedc7d2953d593 (patch)
treedf7c7562faa99a76b0e6b5bc079de8d514b35006 /catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts
parentc0c2637f201f488a74cb1916f05eece0cc207e9d (diff)
Support TOSCA functions in Node Filters
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 <andre.schmid@est.tech>
Diffstat (limited to 'catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts')
-rw-r--r--catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts58
1 files changed, 46 insertions, 12 deletions
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<string, InstanceFeDetails> = new Map<string, InstanceFeDetails>();
@@ -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 && (<PropertyDeclareAPIModel> this.property).propertiesName){
let propertiesPath = (<PropertyDeclareAPIModel> 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 {