X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fpolicy-control%2Fpolicy-type.datasource.ts;h=a7aa98d86f52f6f1ebbf7d722f60d5f58983e3de;hb=ad70d4114bbfc5dbf20fd1a8151095d89610c759;hp=61ecc4ab767d4a2f9dbd8e008a14771180952b95;hpb=c491ddd364164e8b7db6ccb502087383bb4be789;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/policy-control/policy-type.datasource.ts b/webapp-frontend/src/app/policy-control/policy-type.datasource.ts index 61ecc4a..a7aa98d 100644 --- a/webapp-frontend/src/app/policy-control/policy-type.datasource.ts +++ b/webapp-frontend/src/app/policy-control/policy-type.datasource.ts @@ -19,67 +19,64 @@ */ import { CollectionViewer, DataSource } from '@angular/cdk/collections'; -import { HttpErrorResponse } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { of } from 'rxjs/observable/of'; -import { catchError, finalize, map } from 'rxjs/operators'; import { Observable } from 'rxjs/Observable'; -import { PolicyType } from '../interfaces/policy.types'; +import { PolicyType, PolicyTypes, PolicyTypeSchema } from '../interfaces/policy.types'; import { PolicyService } from '../services/policy/policy.service'; -import { NotificationService } from '../services/ui/notification.service'; @Injectable({ providedIn: 'root' }) -export class PolicyTypeDataSource extends DataSource { +export class PolicyTypeDataSource extends DataSource { - private policyTypeSubject = new BehaviorSubject([]); + policyTypes: PolicyTypeSchema[] = []; - private loadingSubject = new BehaviorSubject(false); - - public loading$ = this.loadingSubject.asObservable(); + policyTypeSubject = new BehaviorSubject([]); public rowCount = 1; // hide footer during intial load - constructor(private policySvc: PolicyService, - private notificationService: NotificationService) { + constructor(public policySvc: PolicyService) { super(); } - loadTable() { - this.loadingSubject.next(true); + public getPolicyTypes() { + this.policyTypes = [] as PolicyTypeSchema[]; this.policySvc.getPolicyTypes() - .pipe( - catchError((her: HttpErrorResponse) => { - this.notificationService.error('Failed to get policy types: ' + her.statusText + ', ' + her.error); - return of([]); - }), - finalize(() => this.loadingSubject.next(false)) - ) - .subscribe((types: PolicyType[]) => { - this.rowCount = types.length; - for (let i = 0; i < types.length; i++) { - const policyType = types[i]; - try { - policyType.schemaObject = JSON.parse(policyType.schema); - } catch (jsonError) { - console.error('Could not parse schema: ' + policyType.schema); - policyType.schemaObject = { description: 'Incorrect schema: ' + jsonError }; - } + .subscribe((policyType: PolicyTypes) => { + this.rowCount = policyType.policytype_ids.length; + if (policyType.policytype_ids.length != 0) { + policyType.policytype_ids.forEach(policyTypeId => { + var policyTypeSchema = {} as PolicyTypeSchema + if (policyTypeId === "") { + policyTypeSchema.id = ''; + policyTypeSchema.name = ''; + policyTypeSchema.schemaObject = '{}'; + this.policyTypes.push(policyTypeSchema); + } + else { + this.policySvc.getPolicyType(policyTypeId) + .subscribe((policyType: PolicyType) => { + policyTypeSchema.id = policyTypeId; + policyTypeSchema.schemaObject = policyType.policy_schema; + policyTypeSchema.name = policyType.policy_schema.title; + this.policyTypes.push(policyTypeSchema); + }) + } + this.policyTypeSubject.next(this.policyTypes); + }) } - this.policyTypeSubject.next(types); - }); + }) } - connect(collectionViewer: CollectionViewer): Observable { + connect(collectionViewer: CollectionViewer): Observable { return of(this.policyTypeSubject.getValue()); } disconnect(collectionViewer: CollectionViewer): void { this.policyTypeSubject.complete(); - this.loadingSubject.complete(); } }