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 { Injectable } from '@angular/core';
23 import { BehaviorSubject } from 'rxjs/BehaviorSubject';
25 import { EIJob } from '../interfaces/ei.types';
26 import { EIService } from '../services/ei/ei.service';
32 export class EIJobDataSource {
34 private eiJobsSubject = new BehaviorSubject<EIJob[]>([]);
36 public eiJobs(): EIJob[] {
37 return this.eiJobsSubject.value;
40 private loadingSubject = new BehaviorSubject<boolean>(false);
42 public loading$ = this.loadingSubject.asObservable();
44 public rowCount = 1; // hide footer during intial load
47 private eiSvc: EIService) {
51 this.loadingSubject.next(true);
52 this.eiSvc.getProducerIds()
53 .subscribe((producerIds: string[]) => {
54 producerIds.forEach(id => {
55 this.getJobsForProducer(id);
60 private getJobsForProducer(id: string) {
61 console.log('Getting jobs for producer ID: ', id);
62 this.eiSvc.getJobsForProducer(id).subscribe(jobs => {
63 this.addJobsToSubject(jobs);
64 this.rowCount = this.eiJobsSubject.getValue().length;
68 private addJobsToSubject(jobs: EIJob[]) {
69 const currentValue = this.eiJobsSubject.value;
70 const updatedValue = [...currentValue, ...jobs];
71 this.eiJobsSubject.next(updatedValue);