From f13f58eb867c763e6ed1c3b674fd99b1081a0664 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Wed, 9 Feb 2022 19:00:35 +0000 Subject: Support complex types in interface operation inputs Issue-ID: SDC-3897 Change-Id: Ieac2d74ad340de1d9f6e4cd3ac830e2ec8c35d5b Signed-off-by: andre.schmid Signed-off-by: vasraz Signed-off-by: MichaelMorris --- .../models/properties-inputs/property-be-model.ts | 56 ++++++++++++++++++++-- 1 file changed, 51 insertions(+), 5 deletions(-) (limited to 'catalog-ui/src/app/models/properties-inputs/property-be-model.ts') diff --git a/catalog-ui/src/app/models/properties-inputs/property-be-model.ts b/catalog-ui/src/app/models/properties-inputs/property-be-model.ts index bd65c3a70a..267a2adc71 100644 --- a/catalog-ui/src/app/models/properties-inputs/property-be-model.ts +++ b/catalog-ui/src/app/models/properties-inputs/property-be-model.ts @@ -109,15 +109,61 @@ export class PropertyBEModel { return temp; } - public getDerivedPropertyType = () => { + public getDerivedPropertyType = (): DerivedPropertyType => { if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1) { return DerivedPropertyType.SIMPLE; - } else if (this.type === PROPERTY_TYPES.LIST) { + } + if (this.type === PROPERTY_TYPES.LIST) { return DerivedPropertyType.LIST; - } else if (this.type === PROPERTY_TYPES.MAP) { + } + if (this.type === PROPERTY_TYPES.MAP) { return DerivedPropertyType.MAP; - } else { - return DerivedPropertyType.COMPLEX; + } + return DerivedPropertyType.COMPLEX; + } + + /** + * Parses default value to JSON. + */ + public parseDefaultValueToJson(): any { + if (this.defaultValue == undefined) { + return undefined; + } + + const propertyType: DerivedPropertyType = this.getDerivedPropertyType(); + if (propertyType == DerivedPropertyType.SIMPLE) { + return this.parseDefaultSimpleValue(); + } + + try { + return JSON.parse(this.defaultValue); + } catch (e) { + console.error(`Could not parse the property of type '${this.type}' default value to JSON '${this.defaultValue}'`, e); + } + + return undefined; + } + + private parseDefaultSimpleValue() { + switch (this.type) { + case PROPERTY_TYPES.INTEGER: + try { + return parseInt(this.defaultValue); + } catch (e) { + console.error(`Could not parse the property of type '${this.type}' default value to int '${this.defaultValue}'`, e); + } + return undefined; + case PROPERTY_TYPES.FLOAT: + try { + return parseFloat(this.defaultValue); + } catch (e) { + console.error(`Could not parse the property of type '${this.type}' default value to float '${this.defaultValue}'`, e); + } + return undefined; + case PROPERTY_TYPES.BOOLEAN: + return this.defaultValue === 'true'; + default: + return this.defaultValue; } } -- cgit