diff options
author | JvD_Ericsson <jeff.van.dam@est.tech> | 2023-06-02 17:02:18 +0100 |
---|---|---|
committer | Vasyl Razinkov <vasyl.razinkov@est.tech> | 2023-06-29 14:54:21 +0000 |
commit | cf0a8b21e85ec41260da802a2b923fabe89c9aaa (patch) | |
tree | b6c67c2670d56da685d213ed7d738a3b80d51e7c /catalog-ui/src/app/ng2/pages/composition | |
parent | 1c9375a06ee65147418b17af2a382e0c6cdb64f1 (diff) |
Fix unable to set tosca function on complex type on input operation
Issue-ID: SDC-4527
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Change-Id: Icc7166978c13f3692dc25d9f33a7613d64f87f6a
Diffstat (limited to 'catalog-ui/src/app/ng2/pages/composition')
5 files changed, 54 insertions, 20 deletions
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 88a4d6b437..c67563ebf1 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 @@ -109,6 +109,7 @@ [isViewOnly]="isViewOnly" [showToscaFunctionOption]="showToscaFunctionOption" [allowDeletion]="allowDeletion" + [componentInstanceMap]="componentInstanceMap" (onValueChange)="onPropertyValueChange($event)"> </app-input-list-item> </ng-container> @@ -137,6 +138,7 @@ [isListChild]="true" [isViewOnly]="isViewOnly" [allowDeletion]="allowDeletion" + [componentInstanceMap]="componentInstanceMap" (onValueChange)="onPropertyValueChange($event)" (onChildListItemDelete)="onListItemDelete($event)"> </app-input-list-item> @@ -169,6 +171,7 @@ [nestingLevel]="nestingLevel + 1" [isViewOnly]="isViewOnly" [allowDeletion]="allowDeletion" + [componentInstanceMap]="componentInstanceMap" (onValueChange)="onPropertyValueChange($event)" (onDelete)="onMapKeyDelete($event)"> </app-input-list-item> diff --git a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list-item/input-list-item.component.ts b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list-item/input-list-item.component.ts index 61708ab948..21e8363eb8 100644 --- a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list-item/input-list-item.component.ts +++ b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list-item/input-list-item.component.ts @@ -30,6 +30,7 @@ import {ToscaFunctionValidationEvent} from "../../../../../properties-assignment import {InstanceFeDetails} from "../../../../../../../models/instance-fe-details"; import {ToscaTypeHelper} from "app/utils/tosca-type-helper"; import {CustomToscaFunction} from "../../../../../../../models/default-custom-functions"; +import {SubPropertyToscaFunction} from "../../../../../../../models/sub-property-tosca-function"; @Component({ selector: 'app-input-list-item', @@ -49,7 +50,7 @@ export class InputListItemComponent implements OnInit { @Input() isMapChild: boolean = false; @Input() showToscaFunctionOption: boolean = false; @Input() listIndex: number; - @Input() subPropertyToscaFunctions: SubPropertyToscaFunctions[]; + @Input() subPropertyToscaFunctions: SubPropertyToscaFunction[]; @Input() isViewOnly: boolean; @Input() allowDeletion: boolean = false; @Input() toscaFunction: ToscaFunction; @@ -86,6 +87,15 @@ export class InputListItemComponent implements OnInit { } } + ngOnChanges(): void { + if (this.isToscaFunction) { + this.property.toscaFunction = this.toscaFunction; + this.valueObjRef = this.toscaFunction.value; + } else { + this.property.toscaFunction = undefined; + } + } + private initEmptyPropertyInValueObjRef(property: PropertyBEModel) { if (this.valueObjRef[property.name] == undefined) { if (this.isTypeComplex(property.type) || this.isTypeMap(property.type)) { @@ -101,18 +111,12 @@ export class InputListItemComponent implements OnInit { getToscaFunction(key: any): any { if (this.subPropertyToscaFunctions) { for (let subPropertyToscaFunction of this.subPropertyToscaFunctions) { - let found = subPropertyToscaFunction.subPropertyPath.find(value => value === key); + let found = subPropertyToscaFunction.subPropertyPath ? subPropertyToscaFunction.subPropertyPath.find(value => value === key) : false; if (found) { return subPropertyToscaFunction.toscaFunction; } } } - if ((key && this.valueObjRef[key] && this.valueObjRef[key].type)) { - const type = this.valueObjRef[key].type; - if (type in ToscaFunctionType) { - return <ToscaFunction> this.valueObjRef[key]; - } - } return undefined; } @@ -347,8 +351,3 @@ export class InputListItemComponent implements OnInit { } } - -export interface SubPropertyToscaFunctions { - subPropertyPath: string[]; - toscaFunction: ToscaFunction; -} diff --git a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list.component.spec.ts b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list.component.spec.ts index 824592f58f..53848645d7 100644 --- a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list.component.spec.ts +++ b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list.component.spec.ts @@ -29,7 +29,7 @@ import {TranslateService} from '../../../../../shared/translator/translate.servi import {ToscaFunction} from '../../../../../../models/tosca-function'; import {InstanceFeDetails} from "../../../../../../models/instance-fe-details"; import {CustomToscaFunction} from "../../../../../../models/default-custom-functions"; -import {SubPropertyToscaFunctions} from "./input-list-item/input-list-item.component"; +import {SubPropertyToscaFunction} from "../../../../../../models/sub-property-tosca-function"; @Component({selector: 'app-input-list-item', template: ''}) class InputListItemStubComponent { @@ -37,7 +37,7 @@ class InputListItemStubComponent { @Input() type: DataTypeModel; @Input() dataTypeMap: any; @Input() valueObjRef: any; - @Input() subPropertyToscaFunctions: SubPropertyToscaFunctions[]; + @Input() subPropertyToscaFunctions: SubPropertyToscaFunction[]; @Input() schema: any; @Input() allowDeletion: any; @Input() isViewOnly: boolean; diff --git a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list.component.ts b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list.component.ts index 208c0030f6..62c5e8a52a 100644 --- a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list.component.ts +++ b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list.component.ts @@ -23,9 +23,12 @@ import {Component, EventEmitter, Input, Output} from '@angular/core'; import {InputOperationParameter} from "../../../../../../models/interfaceOperation"; import {DataTypeModel} from "../../../../../../models/data-types"; import {DerivedPropertyType} from "../../../../../../models/properties-inputs/property-be-model"; +import {SubPropertyToscaFunction} from "../../../../../../models/sub-property-tosca-function"; import {PROPERTY_DATA, PROPERTY_TYPES} from "../../../../../../utils/constants"; import {InstanceFeDetails} from "../../../../../../models/instance-fe-details"; +import {ToscaFunction} from "../../../../../../models/tosca-function"; import {CustomToscaFunction} from "../../../../../../models/default-custom-functions"; +import {ToscaFunctionType} from 'app/models/tosca-function-type.enum'; @Component({ selector: 'input-list', @@ -121,6 +124,9 @@ export class InputListComponent { onValueChange($event: any) { const inputOperationParameter = this._inputs.find(input => input.name == $event.name); + if (!inputOperationParameter.subPropertyToscaFunctions) { + inputOperationParameter.subPropertyToscaFunctions = []; + } if (inputOperationParameter) { inputOperationParameter.valid = true; if ($event.isToscaFunction) { @@ -128,15 +134,44 @@ export class InputListComponent { if (!inputOperationParameter.toscaFunction) { inputOperationParameter.valid = false; } + } else if (this.isTypeComplex(inputOperationParameter.type)) { + this.setComplexType($event, inputOperationParameter); } else { inputOperationParameter.value = $event.value; inputOperationParameter.toscaFunction = null; } + } this.inputsValidityChangeEvent.emit(this._inputs.every(input => input.valid === true)); this.inputValueChangeEvent.emit(new InputOperationParameter(inputOperationParameter)); - } } + private setComplexType ($event, inputOperationParameter): void { + Object.keys($event.value).forEach(function (key) { + let value = $event.value[key]; + if (!value || value.length < 1) { + return; + } + let subPropertyToscaFunction = inputOperationParameter.subPropertyToscaFunctions.find(existingSubPropertyToscaFunction => { + const prop = existingSubPropertyToscaFunction.subPropertyPath; + return prop && [key] && prop.length === [key].length && prop.every(function(value, index) { return value === [key][index]}); + }); + let valueKeys = value instanceof Object ? Object.keys(value) : undefined; + if (value && value.type && value.type in ToscaFunctionType) { + if (!subPropertyToscaFunction){ + subPropertyToscaFunction = new SubPropertyToscaFunction(); + inputOperationParameter.subPropertyToscaFunctions.push(subPropertyToscaFunction); + } + subPropertyToscaFunction.toscaFunction = value; + $event.value[key] = (value as ToscaFunction).buildValueObject(); + let array: string[] = []; + array.push(key) + subPropertyToscaFunction.subPropertyPath = array; + } else if (subPropertyToscaFunction && (!valueKeys || !valueKeys.every(value => value.toUpperCase() in ToscaFunctionType))) { + inputOperationParameter.subPropertyToscaFunctions.splice(inputOperationParameter.subPropertyToscaFunctions.indexOf(subPropertyToscaFunction), 1) + } + }); +} + onDelete(inputName: string) { this.inputDeleteEvent.emit(inputName); } 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 812490c12a..4a68de26bc 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 @@ -36,7 +36,6 @@ import {DataTypeModel} from "../../../../../models/data-types"; import {InstanceFeDetails} from "../../../../../models/instance-fe-details"; import {TopologyTemplateService} from "app/ng2/services/component-services/topology-template.service"; import {CustomToscaFunction} from "../../../../../models/default-custom-functions"; -import {ToscaFunctionType} from "../../../../../models/tosca-function-type.enum"; @Component({ selector: 'operation-handler', @@ -303,9 +302,7 @@ export class InterfaceOperationHandlerComponent { const inputOperationParameter = this.inputs.find(value => value.name == changedInput.name); inputOperationParameter.toscaFunction = null; inputOperationParameter.value = changedInput.value; - if (inputOperationParameter.subPropertyToscaFunctions) { - inputOperationParameter.subPropertyToscaFunctions = undefined; - } + inputOperationParameter.subPropertyToscaFunctions = changedInput.subPropertyToscaFunctions; if (changedInput.isToscaFunction()) { inputOperationParameter.toscaFunction = changedInput.toscaFunction; inputOperationParameter.value = changedInput.toscaFunction.buildValueString(); |