From 468d0770593e167990df815e45cde717bd845d18 Mon Sep 17 00:00:00 2001 From: franciscovila Date: Tue, 21 Mar 2023 16:54:46 +0000 Subject: Support TOSCA functions in operation inputs Issue-ID: SDC-4442 Signed-off-by: franciscovila Change-Id: I1e6135da6f41d512a7758d5494df12da874d7146 --- catalog-ui/src/app/models/tosca-get-function.ts | 20 ++++++++++++++++---- .../input-list-item/input-list-item.component.html | 2 +- .../interface-operation-handler.component.html | 2 ++ .../interface-operation-handler.component.ts | 13 ++++++++++--- 4 files changed, 29 insertions(+), 8 deletions(-) (limited to 'catalog-ui/src/app') diff --git a/catalog-ui/src/app/models/tosca-get-function.ts b/catalog-ui/src/app/models/tosca-get-function.ts index 67d9b0a836..784c7ea407 100644 --- a/catalog-ui/src/app/models/tosca-get-function.ts +++ b/catalog-ui/src/app/models/tosca-get-function.ts @@ -71,22 +71,34 @@ export class ToscaGetFunction implements ToscaFunction, ToscaFunctionParameter { private buildGetInputFunctionValue(): Object { if (this.propertyPathFromSource.length === 1) { - return {[this.functionType.toLowerCase()]: [this.propertyPathFromSource[0], this.toscaIndexList]}; + if (this.toscaIndexList) { + return {[this.functionType.toLowerCase()]: [this.propertyPathFromSource[0], this.toscaIndexList]}; + } + return {[this.functionType.toLowerCase()]: [this.propertyPathFromSource[0]]}; } return {[this.functionType.toLowerCase()]: [this.propertyPathFromSource, this.toscaIndexList]}; } private buildFunctionValueWithPropertySource(): Object { if (this.propertySource == PropertySource.SELF) { + if (this.toscaIndexList) { + return { + [this.functionType.toLowerCase()]: [PropertySource.SELF, ...this.propertyPathFromSource, this.toscaIndexList] + }; + } return { - [this.functionType.toLowerCase()]: [PropertySource.SELF, ...this.propertyPathFromSource, this.toscaIndexList] + [this.functionType.toLowerCase()]: [PropertySource.SELF, ...this.propertyPathFromSource] }; } if (this.propertySource == PropertySource.INSTANCE) { + if (this.toscaIndexList) { + return { + [this.functionType.toLowerCase()]: [this.sourceName, ...this.propertyPathFromSource, this.toscaIndexList] + }; + } return { - [this.functionType.toLowerCase()]: [this.sourceName, ...this.propertyPathFromSource,this.toscaIndexList] + [this.functionType.toLowerCase()]: [this.sourceName, ...this.propertyPathFromSource] }; } } - } \ No newline at end of file diff --git a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list-item/input-list-item.component.html b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list-item/input-list-item.component.html index 44db3b0d00..3824d75055 100644 --- a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list-item/input-list-item.component.html +++ b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list-item/input-list-item.component.html @@ -102,7 +102,7 @@ [name]="property.name" [type]="getDataType(property.type)" [dataTypeMap]="dataTypeMap" - [valueObjRef]="valueObjRef[property.name]" + [valueObjRef]="valueObjRef ? valueObjRef[property.name] : undefined" [schema]="property.schema" [nestingLevel]="nestingLevel + 1" [isViewOnly]="isViewOnly" diff --git a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/interface-operation-handler.component.html b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/interface-operation-handler.component.html index 8ab1b97cda..cf9a04ae0a 100644 --- a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/interface-operation-handler.component.html +++ b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/interface-operation-handler.component.html @@ -130,6 +130,8 @@ [dataTypeMap]="dataTypeMap" [isViewOnly]="isViewOnly" [allowDeletion]="true" + [componentInstanceMap]="componentInstanceMap" + [showToscaFunctionOption]="true" (onValueChange)="onInputValueChange($event)" (onDelete)="onInputDelete($event)" > diff --git a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/interface-operation-handler.component.ts b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/interface-operation-handler.component.ts index ab9cad0a39..4ceaa78148 100644 --- a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/interface-operation-handler.component.ts +++ b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/interface-operation-handler.component.ts @@ -138,8 +138,10 @@ export class InterfaceOperationHandlerComponent { private initCustomToscaFunctions() { this.customToscaFunctions = []; this.topologyTemplateService.getDefaultCustomFunction().toPromise().then((data) => { - for (let customFunction of data) { - this.customToscaFunctions.push(new CustomToscaFunction(customFunction)); + if (data) { + for (let customFunction of data) { + this.customToscaFunctions.push(new CustomToscaFunction(customFunction)); + } } }); } @@ -299,7 +301,12 @@ export class InterfaceOperationHandlerComponent { changedInput.value = JSON.stringify(changedInput.value); } const inputOperationParameter = this.inputs.find(value => value.name == changedInput.name); + inputOperationParameter.toscaFunction = null; inputOperationParameter.value = changedInput.value; + if (changedInput.isToscaFunction()) { + inputOperationParameter.toscaFunction = changedInput.toscaFunction; + inputOperationParameter.value = changedInput.toscaFunction.buildValueString(); + } } onArtifactPropertyValueChange(changedProperty: InputOperationParameter) { @@ -345,7 +352,7 @@ export class InterfaceOperationHandlerComponent { const input1 = currentInputs.find(value => value.name === inputName); const indexOfInput = currentInputs.indexOf(input1); if (indexOfInput === -1) { - console.error(`Could delete input '${inputName}'. Input not found.`); + console.error(`Could not delete input '${inputName}'. Input not found.`); return; } currentInputs.splice(currentInputs.indexOf(input1), 1); -- cgit 1.2.3-korg