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;fp=webapp-frontend%2Fsrc%2Fapp%2Fpolicy-control%2Fpolicy-type.datasource.ts;h=2e10f55affcaf8d7d20319114093a2db71c601e8;hb=23b0fff7d2ab5e731cf0143a88e9b34638ae0398;hp=2fed8f3f5edca0c2e82c31769f0ad2b1a2e8496d;hpb=b78d2c9ac49341c5354c4e591ee72da320a30481;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 2fed8f3..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,39 +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(policyType => { - 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 => { - policyTypeSchema.id = policyTypeId; - 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 {