2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 Nordix Foundation
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
21 import { HttpErrorResponse } from '@angular/common/http';
22 import { Injectable } from '@angular/core';
23 import { MatTableDataSource } from '@angular/material';
25 import { Observable } from 'rxjs/Observable';
26 import { BehaviorSubject } from 'rxjs/BehaviorSubject';
27 import { of } from 'rxjs/observable/of';
28 import { catchError, finalize, tap } from 'rxjs/operators';
30 import { EIProducer } from '../interfaces/ei.types';
31 import { EIService } from '../services/ei/ei.service';
32 import { NotificationService } from '../services/ui/notification.service';
38 export class EIProducerDataSource extends MatTableDataSource<EIProducer> {
40 private producerSubject = new BehaviorSubject<EIProducer[]>([]);
42 private loadingSubject = new BehaviorSubject<boolean>(false);
44 public loading$ = this.loadingSubject.asObservable();
46 public rowCount = 1; // hide footer during intial load
49 private eiSvc: EIService,
50 private notificationService: NotificationService) {
55 this.loadingSubject.next(true);
56 this.eiSvc.getEIProducers()
58 catchError((her: HttpErrorResponse) => {
59 this.notificationService.error('Failed to get producers: ' + her.error);
62 finalize(() => this.loadingSubject.next(false))
64 .subscribe((prods: EIProducer[]) => {
65 console.log("Producers: " + prods);
66 this.rowCount = prods.length;
67 this.producerSubject.next(prods);
72 connect(): BehaviorSubject<EIProducer[]> {
73 return this.producerSubject;
77 this.producerSubject.complete();
78 this.loadingSubject.complete();
81 getProducers(): Observable<EIProducer[]> {
82 return this.eiSvc.getEIProducers()
83 .pipe(tap(console.log));