X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fei-coordinator%2Fei-job.datasource.ts;h=64c948c158eafe3302c68055d01d7a51342d7496;hb=c57eea20731c196a5de55faef024c6c07f7689fe;hp=9e048b6b2c2e618c705e41e0e911f8260a3873f3;hpb=94225563a68aecb49e713eb8508fb278682cec08;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts b/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts index 9e048b6..64c948c 100644 --- a/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts +++ b/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts @@ -18,17 +18,13 @@ * ========================LICENSE_END=================================== */ -import { HttpErrorResponse } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { MatTableDataSource } from '@angular/material'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; -import { of } from 'rxjs/observable/of'; -import { catchError, finalize, map } from 'rxjs/operators'; import { EIJob } from '../interfaces/ei.types'; import { EIService } from '../services/ei/ei.service'; -import { NotificationService } from '../services/ui/notification.service'; @Injectable({ providedIn: 'root' @@ -36,7 +32,7 @@ import { NotificationService } from '../services/ui/notification.service'; export class EIJobDataSource extends MatTableDataSource { - private eiJobSubject = new BehaviorSubject([]); + eiJobsSubject = new BehaviorSubject([]); private loadingSubject = new BehaviorSubject(false); @@ -45,33 +41,40 @@ export class EIJobDataSource extends MatTableDataSource { public rowCount = 1; // hide footer during intial load constructor( - private eiSvc: EIService, - private notificationService: NotificationService) { + private eiSvc: EIService) { super(); } - loadTable() { + getJobs() { this.loadingSubject.next(true); - this.eiSvc.getEIJobs() - .pipe( - catchError((her: HttpErrorResponse) => { - this.notificationService.error('Failed to get EI jobs: ' + her.error); - return of([]); - }), - finalize(() => this.loadingSubject.next(false)) - ) - .subscribe((instances: EIJob[]) => { - this.rowCount = instances.length; - this.eiJobSubject.next(instances); + this.eiSvc.getProducerIds() + .subscribe((producerIds: string[]) => { + producerIds.forEach(id => { + this.getJobsForProducer(id); + }); }); } + private getJobsForProducer(id: string) { + console.log('Getting jobs for producer ID: ', id); + this.eiSvc.getJobsForProducer(id).subscribe(jobs => { + this.addJobsToSubject(jobs); + this.rowCount = this.eiJobsSubject.getValue().length; + }); + } + + private addJobsToSubject(jobs: EIJob[]) { + const currentValue = this.eiJobsSubject.value; + const updatedValue = [...currentValue, ...jobs]; + this.eiJobsSubject.next(updatedValue); + } + connect(): BehaviorSubject { - return this.eiJobSubject; + return this.eiJobsSubject; } disconnect(): void { - this.eiJobSubject.complete(); + this.eiJobsSubject.complete(); this.loadingSubject.complete(); } }