From fc1e10df3b4be3520092f4dafa11f85efe4594a6 Mon Sep 17 00:00:00 2001 From: Ahmedeldeeb50 Date: Tue, 15 Dec 2020 20:21:23 +0200 Subject: handle json inputs in function attributes Issue-ID: CCSDK-3050 Signed-off-by: Ahmedeldeeb50 Change-Id: I4f30e5288196de68a9c755baecec47f0e1757119 --- .../functions-attribute.component.html | 32 ++++++++++++++-------- .../functions-attribute.component.ts | 21 +++++++++++++- 2 files changed, 41 insertions(+), 12 deletions(-) (limited to 'cds-ui/designer-client/src/app/modules') diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/functions-attribute/functions-attribute.component.html b/cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/functions-attribute/functions-attribute.component.html index ded7e5f23..f00878a74 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/functions-attribute/functions-attribute.component.html +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/functions-attribute/functions-attribute.component.html @@ -59,8 +59,7 @@
+ (click)="setArtifact(true)" class="custom-control-input">
@@ -82,7 +81,7 @@
-
+ +
+ + +
@@ -207,7 +217,7 @@
-
+
@@ -225,13 +235,13 @@ diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/functions-attribute/functions-attribute.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/functions-attribute/functions-attribute.component.ts index f46004b0b..8780621ea 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/functions-attribute/functions-attribute.component.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/designer/functions-attribute/functions-attribute.component.ts @@ -139,7 +139,7 @@ export class FunctionsAttributeComponent implements OnInit, OnDestroy { if (inputs) { for (const [key, value] of Object.entries(inputs)) { console.log(key + ' - ' + value); - if (typeof value === 'object') { + if (this.isValidJson(value)) { this.currentFuncion.inputs[key] = JSON.stringify(value); } else { this.currentFuncion.inputs[key] = value; @@ -154,6 +154,25 @@ export class FunctionsAttributeComponent implements OnInit, OnDestroy { } } } + + isValidJson(val) { + try { + JSON.parse(val); + return true; + } catch (e) { } + return false; + } + + jsonToStr(json) { + return JSON.stringify(json); + } + + bind(key, e) { + const val = JSON.parse(e.target.value); + this.currentFuncion.inputs[key] = { + ...val + }; + } ngOnDestroy() { this.ngUnsubscribe.next(); this.ngUnsubscribe.complete(); -- cgit 1.2.3-korg