X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-ui%2Fsrc%2Fapp%2Fng2%2Fpages%2Fproperties-assignment%2Ftosca-function%2Ftosca-function.component.ts;h=412e29a427c90db65fa709da68cabc5015871f81;hb=d32437595314c9b5b2aa439a482d0b07286a8072;hp=b9559838f46a7ac92fd5922cfd68cad4c02f25a7;hpb=bc7dd3ad94acace55a2910abc22cc5cb64e0862d;p=sdc.git 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 b9559838f4..412e29a427 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 @@ -52,6 +52,7 @@ export class ToscaFunctionComponent implements OnInit, OnChanges { @Input() allowClear: boolean = true; @Input() compositionMap: boolean = false; @Input() compositionMapKey: string = ""; + @Input() complexListKey: string = null; @Output() onValidFunction: EventEmitter = new EventEmitter(); @Output() onValidityChange: EventEmitter = new EventEmitter(); @@ -82,7 +83,6 @@ export class ToscaFunctionComponent implements OnInit, OnChanges { if (!this.isInitialized) { return; } - this.emitValidityChange(); if (this.formGroup.valid) { this.onValidFunction.emit(this.toscaFunctionForm.value); } @@ -109,14 +109,33 @@ export class ToscaFunctionComponent implements OnInit, OnChanges { private initToscaFunction(): void { if (this.compositionMap && this.property.subPropertyToscaFunctions) { let keyToFind = [this.compositionMapKey]; - let subPropertyToscaFunction = this.property.subPropertyToscaFunctions.find(subPropertyToscaFunction => this.areEqual(subPropertyToscaFunction.subPropertyPath, keyToFind)); - - if (subPropertyToscaFunction){ - this.toscaFunction = subPropertyToscaFunction.toscaFunction; - this.toscaFunctionForm.setValue(this.toscaFunction); - this.toscaFunctionTypeForm.setValue(this.toscaFunction.type); + if (this.complexListKey != null) { + keyToFind = [this.complexListKey,this.compositionMapKey]; + } + let subPropertyToscaFunction; + this.property.subPropertyToscaFunctions.forEach(subToscaFunction => { + if (subToscaFunction.subPropertyPath.toString() == keyToFind.toString()) { + subPropertyToscaFunction = subToscaFunction; } - return; + }); + + if (subPropertyToscaFunction){ + this.toscaFunction = subPropertyToscaFunction.toscaFunction; + this.toscaFunctionForm.setValue(this.toscaFunction); + let type = this.toscaFunction.type; + if (type == ToscaFunctionType.CUSTOM) { + let name = (subPropertyToscaFunction.toscaFunction as ToscaCustomFunction).name; + let customToscaFunc = this.customToscaFunctions.find(custToscFunc => _.isEqual(custToscFunc.name, name)) + if (customToscaFunc) { + this.toscaFunctionTypeForm.setValue(name); + } else { + this.toscaFunctionTypeForm.setValue("other"); + } + } else { + this.toscaFunctionTypeForm.setValue(type); + } + } + return; } if (this.property instanceof PropertyDeclareAPIModel && this.property.subPropertyToscaFunctions && ( this.property).propertiesName){ let propertiesPath = ( this.property).propertiesName.split("#"); @@ -127,7 +146,18 @@ export class ToscaFunctionComponent implements OnInit, OnChanges { if (subPropertyToscaFunction){ this.toscaFunction = subPropertyToscaFunction.toscaFunction; this.toscaFunctionForm.setValue(this.toscaFunction); - this.toscaFunctionTypeForm.setValue(this.toscaFunction.type); + let type = this.toscaFunction.type; + if (type == ToscaFunctionType.CUSTOM) { + let name = (subPropertyToscaFunction.toscaFunction as ToscaCustomFunction).name; + let customToscaFunc = this.customToscaFunctions.find(custToscFunc => _.isEqual(custToscFunc.name, name)) + if (customToscaFunc) { + this.toscaFunctionTypeForm.setValue(name); + } else { + this.toscaFunctionTypeForm.setValue("other"); + } + } else { + this.toscaFunctionTypeForm.setValue(type); + } } return; } @@ -137,11 +167,11 @@ export class ToscaFunctionComponent implements OnInit, OnChanges { } this.toscaFunctionForm.setValue(this.inToscaFunction ? this.inToscaFunction : this.property.toscaFunction); - let type = this.property.toscaFunction.type; + let type = this.property.toscaFunction.type ? this.property.toscaFunction.type : this.toscaFunctionForm.value.type; if (type == ToscaFunctionType.CUSTOM) { - let name = (this.property.toscaFunction as ToscaCustomFunction).name; - let test = this.customToscaFunctions.find(custToscFunc => _.isEqual(custToscFunc.name, name)) - if (test) { + let name = (this.toscaFunctionForm.value as ToscaCustomFunction).name; + let customToscaFunc = this.customToscaFunctions.find(custToscFunc => _.isEqual(custToscFunc.name, name)) + if (customToscaFunc) { this.toscaFunctionTypeForm.setValue(name); } else { this.toscaFunctionTypeForm.setValue("other"); @@ -160,9 +190,6 @@ export class ToscaFunctionComponent implements OnInit, OnChanges { this.toscaFunctions.push(ToscaFunctionType.GET_ATTRIBUTE); this.toscaFunctions.push(ToscaFunctionType.GET_INPUT); this.toscaFunctions.push(ToscaFunctionType.GET_PROPERTY); - if (this.property.type === PROPERTY_TYPES.STRING || this.property.type === PROPERTY_TYPES.ANY) { - this.toscaFunctions.push(ToscaFunctionType.CUSTOM); - } if ((this.property.type === PROPERTY_TYPES.STRING || this.property.type === PROPERTY_TYPES.ANY) && this.overridingType === undefined) { this.toscaFunctions.push(ToscaFunctionType.CONCAT); } @@ -189,7 +216,8 @@ export class ToscaFunctionComponent implements OnInit, OnChanges { getCustomFunctionName():string { let toscaFunctionType: CustomToscaFunction = this.getCustomToscaFunction(); - return toscaFunctionType.name; + let name = toscaFunctionType.name; + return name == 'other' ? '' : name; } getCustomFunctionType():string { @@ -253,6 +281,7 @@ export class ToscaFunctionComponent implements OnInit, OnChanges { } else { this.toscaFunctionForm.setValue(undefined); } + this.emitValidityChange(); } onCustomFunctionValidityChange(validationEvent: ToscaCustomFunctionValidationEvent): void { @@ -261,6 +290,7 @@ export class ToscaFunctionComponent implements OnInit, OnChanges { } else { this.toscaFunctionForm.setValue(undefined); } + this.emitValidityChange(); } onGetFunctionValidityChange(validationEvent: ToscaGetFunctionValidationEvent): void { @@ -269,6 +299,7 @@ export class ToscaFunctionComponent implements OnInit, OnChanges { } else { this.toscaFunctionForm.setValue(undefined); } + this.emitValidityChange(); } onYamlFunctionValidityChange(validationEvent: YamlFunctionValidationEvent): void { @@ -277,6 +308,7 @@ export class ToscaFunctionComponent implements OnInit, OnChanges { } else { this.toscaFunctionForm.setValue(undefined); } + this.emitValidityChange(); } onFunctionTypeChange(): void {