X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fei-coordinator%2Fei-producer.datasource.ts;h=cb4809cb82af35a37bfbc8250f43fae4d1c8a181;hb=b3f060ed6175d6dab20e16f51cb96a8ed02a6fc2;hp=2b12021cabbf7bb8b587dbcb28276a1b904ff768;hpb=94225563a68aecb49e713eb8508fb278682cec08;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.ts b/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.ts index 2b12021..cb4809c 100644 --- a/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.ts +++ b/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.ts @@ -18,68 +18,67 @@ * ========================LICENSE_END=================================== */ -import { HttpErrorResponse } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { MatTableDataSource } from '@angular/material'; -import { Observable } from 'rxjs/Observable'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; -import { of } from 'rxjs/observable/of'; -import { catchError, finalize, tap } from 'rxjs/operators'; +import { mergeMap, finalize } from 'rxjs/operators'; +import { Observable, forkJoin, of } from 'rxjs'; import { EIProducer } from '../interfaces/ei.types'; import { EIService } from '../services/ei/ei.service'; -import { NotificationService } from '../services/ui/notification.service'; @Injectable({ providedIn: 'root' }) -export class EIProducerDataSource extends MatTableDataSource { +export class EIProducerDataSource { - private producerSubject = new BehaviorSubject([]); + private producers: Array = []; + + public eiProducers(): EIProducer[] { + return this.producers; + } + + public eiProducersSubject(): Observable { + return this.producersSubject.asObservable() as Observable; + } private loadingSubject = new BehaviorSubject(false); + private producersSubject = new BehaviorSubject([]); public loading$ = this.loadingSubject.asObservable(); public rowCount = 1; // hide footer during intial load constructor( - private eiSvc: EIService, - private notificationService: NotificationService) { - super(); + private eiSvc: EIService) { } - loadTable() { + loadProducers() { this.loadingSubject.next(true); - this.eiSvc.getEIProducers() - .pipe( - catchError((her: HttpErrorResponse) => { - this.notificationService.error('Failed to get producers: ' + her.error); - return of([]); - }), - finalize(() => this.loadingSubject.next(false)) - ) - .subscribe((prods: EIProducer[]) => { - console.log("Producers: " + prods); - this.rowCount = prods.length; - this.producerSubject.next(prods); - }); - this.connect(); - } + this.producers = []; - connect(): BehaviorSubject { - return this.producerSubject; - } - - disconnect(): void { - this.producerSubject.complete(); - this.loadingSubject.complete(); - } - - getProducers(): Observable { - return this.eiSvc.getEIProducers() - .pipe(tap(console.log)); + this.eiSvc.getProducerIds().pipe( + mergeMap(prodIds => + forkJoin(prodIds.map(id => { + return forkJoin([ + of(id), + this.eiSvc.getProducer(id), + this.eiSvc.getProducerStatus(id) + ]) + }) + )), + finalize(() => this.loadingSubject.next(false)) + ).subscribe(result => { + this.producers = result.map(producer => { + let eiProducer = {}; + eiProducer.ei_producer_id = producer[0]; + eiProducer.ei_producer_types = producer[1].supported_ei_types; + eiProducer.status = producer[2].operational_state.toString(); + return eiProducer; + }); + this.producersSubject.next(this.producers); + }); + this.rowCount = this.producers.length; } -} +} \ No newline at end of file