X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fpolicy%2Fpolicy-type%2Fpolicy-type.component.ts;h=f6c8d2a19b6b594c97402d80e76d6b6d89d15aaa;hb=refs%2Fchanges%2F71%2F6071%2F2;hp=be5b30583e7be33597298bbd1ebc6d3422923b04;hpb=41a57e4d75761207f2da883d0e4396c81159e58e;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/policy/policy-type/policy-type.component.ts b/webapp-frontend/src/app/policy/policy-type/policy-type.component.ts index be5b305..f6c8d2a 100644 --- a/webapp-frontend/src/app/policy/policy-type/policy-type.component.ts +++ b/webapp-frontend/src/app/policy/policy-type/policy-type.component.ts @@ -18,46 +18,76 @@ * ========================LICENSE_END=================================== */ -import { Component, Input, OnInit } from '@angular/core'; -import { BehaviorSubject } from 'rxjs'; -import { PolicyTypeSchema } from '@interfaces/policy.types'; -import { PolicyService } from '@services/policy/policy.service'; -import { PolicyTypeDataSource } from './policy-type.datasource'; +import { Component, Input, OnInit, OnChanges, SimpleChanges} from "@angular/core"; +import { BehaviorSubject } from "rxjs"; +import { PolicyType, PolicyTypeSchema } from "@interfaces/policy.types"; +import { PolicyService } from "@services/policy/policy.service"; +import "@policy/policy-control.component"; class PolicyTypeInfo { - constructor(public type: PolicyTypeSchema) { } + constructor(public type: PolicyTypeSchema) {} isExpanded: BehaviorSubject = new BehaviorSubject(false); } @Component({ - selector: 'nrcp-policy-type', - templateUrl: './policy-type.component.html', - styleUrls: ['./policy-type.component.scss'] + selector: "nrcp-policy-type", + 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 = new BehaviorSubject(false); policyTypeInfo: PolicyTypeInfo; + policyType: string; + policyDescription: string; - constructor(private policyTypeDataSource: PolicyTypeDataSource) { - } + constructor(private policyService: PolicyService) {} ngOnInit(): void { - const policyTypeSchema = this.policyTypeDataSource.getPolicyType(this.policyTypeId); - this.policyTypeInfo = new PolicyTypeInfo(policyTypeSchema); - console.log("this.policyType: ", this.policyTypeInfo); + this.loadTypeInfo(); this.isVisible.next(false); } - public setIsVisible(status: boolean){ - this.isVisible.next(status); + 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) => { + const policyTypeSchema = this.getSchemaObject(policyType); + this.policyTypeInfo = new PolicyTypeInfo(policyTypeSchema); + this.policyType = this.policyTypeId; + this.policyDescription = policyTypeSchema.schemaObject.description; + }); + } else { + const noType = { + 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"; + } +} + + private getSchemaObject(policyType: PolicyType) { + const policyTypeSchema = {} as PolicyTypeSchema; + policyTypeSchema.id = this.policyTypeId; + policyTypeSchema.schemaObject = policyType.policy_schema; + policyTypeSchema.name = policyType.policy_schema.title; + return policyTypeSchema; } public toggleVisible() { this.isVisible.next(!this.isVisible.value); } -} \ No newline at end of file +}