diff options
author | MichaelMorris <michael.morris@est.tech> | 2022-08-26 11:00:03 +0100 |
---|---|---|
committer | Vasyl Razinkov <vasyl.razinkov@est.tech> | 2022-09-07 13:17:19 +0000 |
commit | 0411615fe4f55fe3463da2576de376c7478fcfb2 (patch) | |
tree | 6e9792f607de443c2d04dde2d54412d0e6a85603 /catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function | |
parent | 00f293346ed73585faea502c6fc6bac1481f7422 (diff) |
Support TOSCA functions in sub properties
Change-Id: Ibfd95c928bbb10089cfc9749ae4e7b05270e3d68
Issue-ID: SDC-4151
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Diffstat (limited to 'catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function')
2 files changed, 42 insertions, 3 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 ae778006ce..70df4eaced 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 @@ -18,7 +18,7 @@ */ import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {ComponentMetadata, PropertyBEModel} from 'app/models'; +import {ComponentMetadata, PropertyBEModel, PropertyDeclareAPIModel} from 'app/models'; import {TopologyTemplateService} from "../../../services/component-services/topology-template.service"; import {WorkspaceService} from "../../workspace/workspace.service"; import {ToscaGetFunctionType} from "../../../../models/tosca-get-function-type"; @@ -86,6 +86,21 @@ export class ToscaFunctionComponent implements OnInit { } private initToscaFunction() { + if (this.property instanceof PropertyDeclareAPIModel && this.property.subPropertyToscaFunctions && (<PropertyDeclareAPIModel> this.property).propertiesName){ + let propertiesPath = (<PropertyDeclareAPIModel> this.property).propertiesName.split("#"); + if (propertiesPath.length > 1){ + propertiesPath = propertiesPath.slice(1); + let subPropertyToscaFunction = this.property.subPropertyToscaFunctions.find(subPropertyToscaFunction => this.areEqual(subPropertyToscaFunction.subPropertyPath, propertiesPath)); + + if (subPropertyToscaFunction){ + this.toscaFunction = subPropertyToscaFunction.toscaFunction; + this.toscaFunctionForm.setValue(this.toscaFunction); + this.toscaFunctionTypeForm.setValue(this.toscaFunction.type); + } + return; + } + } + if (!this.property.isToscaFunction()) { return; } @@ -93,6 +108,10 @@ export class ToscaFunctionComponent implements OnInit { this.toscaFunctionTypeForm.setValue(this.property.toscaFunction.type); } + private areEqual(array1: string[], array2: string[]): boolean { + return array1.length === array2.length && array1.every(function(value, index) { return value === array2[index]}) + } + private loadToscaFunctions(): void { this.toscaFunctions.push(ToscaFunctionType.GET_ATTRIBUTE); this.toscaFunctions.push(ToscaFunctionType.GET_INPUT); 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 64d155a55f..1f658f968a 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 @@ -18,7 +18,7 @@ */ import {Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core'; -import {AttributeBEModel, ComponentMetadata, DataTypeModel, PropertyBEModel, PropertyModel} from 'app/models'; +import {AttributeBEModel, ComponentMetadata, DataTypeModel, PropertyBEModel, PropertyModel, PropertyDeclareAPIModel} from 'app/models'; import {TopologyTemplateService} from "../../../../services/component-services/topology-template.service"; import {WorkspaceService} from "../../../workspace/workspace.service"; import {PropertiesService} from "../../../../services/properties.service"; @@ -261,12 +261,19 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges { } private propertyTypeToString() { + if (this.isSubProperty()){ + return this.getType((<PropertyDeclareAPIModel>this.property).propertiesName.split("#").slice(1), this.property.type); + } if (this.property.schemaType) { return `${this.property.type} of ${this.property.schemaType}`; } return this.property.type; } + private isSubProperty(): boolean{ + return this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel>this.property).propertiesName && (<PropertyDeclareAPIModel>this.property).propertiesName.length > 1; + } + private extractProperties(componentGenericResponse: ComponentGenericResponse): Array<PropertyBEModel | AttributeBEModel> { if (this.isGetInput()) { return componentGenericResponse.inputs; @@ -358,17 +365,30 @@ export class ToscaGetFunctionComponent implements OnInit, OnChanges { }); } - private hasSameType(property: PropertyBEModel | AttributeBEModel) { + private hasSameType(property: PropertyBEModel | AttributeBEModel): boolean { if (this.typeHasSchema(this.property.type)) { if (!property.schema || !property.schema.property) { return false; } return property.type === this.property.type && this.property.schema.property.type === property.schema.property.type; } + if (this.property.schema.property.isDataType && this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel>this.property).propertiesName){ + let typeToMatch = this.getType((<PropertyDeclareAPIModel>this.property).propertiesName.split("#").slice(1), this.property.type); + return property.type === typeToMatch; + } return property.type === this.property.type; } + private getType(propertyPath:string[], type: string): string { + const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, type); + let nestedProperty = dataTypeFound.properties.find(property => property.name === propertyPath[0]); + if (propertyPath.length === 1){ + return nestedProperty.type; + } + return this.getType(propertyPath.slice(1), nestedProperty.type); + } + private isGetProperty(): boolean { return this.functionType === ToscaGetFunctionType.GET_PROPERTY; } |