Added support for showing typeless Policies
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / policy-control / policy-instance-dialog.component.ts
index aea3453..60ffbd3 100644 (file)
@@ -123,11 +123,20 @@ export class PolicyInstanceDialogComponent implements OnInit, AfterViewInit {
         if (!this.policyInstanceId) {
             this.fetchRics();
         }
+        if (this.isSchemaEmpty()) {
+            // Empty schema, hide form, show json instead
+            this.isVisible.form = false;
+            this.isVisible.json = true;
+        }
     }
 
     ngAfterViewInit() {
     }
 
+    private isSchemaEmpty(): boolean {
+        return Object.keys(this.jsonSchemaObject).length === 0;
+    }
+
     onSubmit() {
         if (this.policyInstanceId == null) {
             this.policyInstanceId = uuid.v4();
@@ -154,15 +163,18 @@ export class PolicyInstanceDialogComponent implements OnInit, AfterViewInit {
         this.liveFormData = formData;
     }
 
-    get prettyLiveFormData() {
+    get prettyLiveFormData(): string {
+        if (this.isSchemaEmpty()) {
+            return this.jsonAsString;
+        }
         return JSON.stringify(this.liveFormData, null, 2);
     }
 
-    get schemaAsString() {
+    get schemaAsString(): string {
         return JSON.stringify(this.jsonSchemaObject, null, 2);
     }
 
-    get jsonAsString() {
+    get jsonAsString(): string {
         return JSON.stringify(this.jsonObject, null, 2);
     }