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=2e10f55affcaf8d7d20319114093a2db71c601e8;hb=a3e0f85eff3e8203612c547045e11f8d83639df1;hp=db8f01fb63ac00dc76eead3d4ffce6e89b034153;hpb=9872b8b01da34a6677844ebd56352c9d8c3ec09b;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 db8f01f..2e10f55 100644 --- a/webapp-frontend/src/app/policy-control/policy-type.datasource.ts +++ b/webapp-frontend/src/app/policy-control/policy-type.datasource.ts @@ -18,13 +18,15 @@ * ========================LICENSE_END=================================== */ +import { HttpErrorResponse } from '@angular/common/http'; import { CollectionViewer, DataSource } from '@angular/cdk/collections'; import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { of } from 'rxjs/observable/of'; import { Observable } from 'rxjs/Observable'; +import { catchError, finalize, map } from 'rxjs/operators'; -import { PolicyTypeSchema } 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'; @@ -36,37 +38,58 @@ export class PolicyTypeDataSource extends DataSource { policyTypes: PolicyTypeSchema[] = []; - private policyTypeSubject = new BehaviorSubject([]); + policyTypeSubject = new BehaviorSubject([]); + + private loadingSubject = new BehaviorSubject(false); public rowCount = 1; // hide footer during intial load - constructor(private policySvc: PolicyService, + constructor(public policySvc: PolicyService, private notificationService: NotificationService) { super(); } public getPolicyTypes() { this.policyTypes = [] as PolicyTypeSchema[]; - this.policySvc.getPolicyTypes().subscribe(data => { - if (data.policytype_ids.length != 0) { - data.policytype_ids.forEach(policyId => { - var policyTypeSchema = {} as PolicyTypeSchema - if (policyId === "") { - policyTypeSchema.name = ''; - policyTypeSchema.schemaObject = '{}'; - this.policyTypes.push(policyTypeSchema); - } - else { - this.policySvc.getPolicyType(policyId).subscribe(policyType => { - policyTypeSchema.schemaObject = policyType.policy_schema; - policyTypeSchema.name = policyType.policy_schema.title; + this.policySvc.getPolicyTypes() + .pipe( + catchError((httpError: HttpErrorResponse) => { + this.notificationService.error('Failed to get policy types: ' + httpError.error); + return of([]); + }), + finalize(() => this.loadingSubject.next(false)) + ) + .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); - }) - } - this.policyTypeSubject.next(this.policyTypes); - }) - } - }) + } + else { + this.policySvc.getPolicyType(policyTypeId) + .pipe( + catchError((httpError: HttpErrorResponse) => { + this.notificationService.error('Failed to get policy type: ' + httpError.error); + return of([]); + }), + finalize(() => this.loadingSubject.next(false)) + ) + .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); + }) + } + }) } connect(collectionViewer: CollectionViewer): Observable {