Updated Control Panel for changed ECS NBI
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / policy / policy-type / policy-type.component.ts
index 7d82cb4..f6c8d2a 100644 (file)
  * ========================LICENSE_END===================================
  */
 
-import { Component, Input, OnInit } from "@angular/core";
+import { Component, Input, OnInit, OnChanges, SimpleChanges} from "@angular/core";
 import { BehaviorSubject } from "rxjs";
 import { PolicyType, PolicyTypeSchema } from "@interfaces/policy.types";
-import { PolicyService } from "@app/services/policy/policy.service";
+import { PolicyService } from "@services/policy/policy.service";
+import "@policy/policy-control.component";
 
 class PolicyTypeInfo {
   constructor(public type: PolicyTypeSchema) {}
@@ -34,8 +35,9 @@ class PolicyTypeInfo {
   templateUrl: "./policy-type.component.html",
   styleUrls: ["./policy-type.component.scss"],
 })
-export class PolicyTypeComponent implements OnInit {
+export class PolicyTypeComponent implements OnInit, OnChanges {
   @Input() policyTypeId: string;
+  @Input() minimiseTrigger: boolean;
 
   isVisible: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
 
@@ -46,7 +48,18 @@ export class PolicyTypeComponent implements OnInit {
   constructor(private policyService: PolicyService) {}
 
   ngOnInit(): void {
-    if (this.policyTypeId !== "") {
+    this.loadTypeInfo();
+    this.isVisible.next(false);
+  }
+
+  ngOnChanges(changes: SimpleChanges): void {
+    if(changes['minimiseTrigger']){
+      this.isVisible.next(false);
+    }
+  }
+
+  public loadTypeInfo() {
+    if (this.policyTypeId && this.policyTypeId !== "") {
       this.policyService
         .getPolicyType(this.policyTypeId)
         .subscribe((policyType: PolicyType) => {
@@ -57,15 +70,14 @@ export class PolicyTypeComponent implements OnInit {
         });
     } else {
       const noType = {
-        policy_schema: JSON.parse('{"schemaObject": "{}"}'),
+        policy_schema: JSON.parse('{}'),
       } as PolicyType;
       const noTypeSchema = this.getSchemaObject(noType);
       this.policyTypeInfo = new PolicyTypeInfo(noTypeSchema);
       this.policyType = "< No Type >";
       this.policyDescription = "Type with no schema";
     }
-    this.isVisible.next(false);
-  }
+}
 
   private getSchemaObject(policyType: PolicyType) {
     const policyTypeSchema = {} as PolicyTypeSchema;
@@ -75,10 +87,6 @@ export class PolicyTypeComponent implements OnInit {
     return policyTypeSchema;
   }
 
-  public setIsVisible(status: boolean) {
-    this.isVisible.next(status);
-  }
-
   public toggleVisible() {
     this.isVisible.next(!this.isVisible.value);
   }