summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/models/properties-inputs/property-be-model.ts
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-02-09 19:00:35 +0000
committerMichael Morris <michael.morris@est.tech>2022-03-11 15:25:28 +0000
commitf13f58eb867c763e6ed1c3b674fd99b1081a0664 (patch)
treec0ccc70b8fdf4362bce26efa0a5bb1c435f98575 /catalog-ui/src/app/models/properties-inputs/property-be-model.ts
parent767b122ea026099e17a2ffde30e6718d2abf150f (diff)
Support complex types in interface operation inputs
Issue-ID: SDC-3897 Change-Id: Ieac2d74ad340de1d9f6e4cd3ac830e2ec8c35d5b Signed-off-by: andre.schmid <andre.schmid@est.tech> Signed-off-by: vasraz <vasyl.razinkov@est.tech> Signed-off-by: MichaelMorris <michael.morris@est.tech>
Diffstat (limited to 'catalog-ui/src/app/models/properties-inputs/property-be-model.ts')
-rw-r--r--catalog-ui/src/app/models/properties-inputs/property-be-model.ts56
1 files changed, 51 insertions, 5 deletions
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;
}
}