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';
27 import { MatTableDataSource } from '@angular/material';
28 import { ViewChild } from '@angular/core';
29 import { MatSort } from '@angular/material/sort';
30 import { delay } from 'rxjs/operators';
36 export class EIJobDataSource {
38 private jobs: Array<EIJob> = [];
39 private dataSource: MatTableDataSource<any> = new MatTableDataSource();
40 @ViewChild(MatSort, { static: true }) sort: MatSort;
43 public jobsDataSource(): MatTableDataSource<any> {
44 return this.dataSource;
47 private loadingSubject = new BehaviorSubject<boolean>(false);
49 public loading$ = this.loadingSubject.asObservable();
51 public rowCount = 1; // hide footer during intial load
54 private eiSvc: EIService) {
58 this.loadingSubject.next(true);
60 this.eiSvc.getProducerIds()
61 .subscribe((producerIds: string[]) => {
62 producerIds.forEach(id => {
63 this.getJobsForProducer(id);
65 //this.dataSource = new MatTableDataSource();
66 this.dataSource.data = this.jobs;
67 this.dataSource.sort = this.sort;
68 console.log("datasource: "+this.dataSource.data);
70 this.rowCount = this.jobs.length;
73 private getJobsForProducer(id: string) {
74 console.log('Getting jobs for producer ID: ', id);
75 this.eiSvc.getJobsForProducer(id)//.pipe(delay(5000))
76 .subscribe(producerJobs => {
77 this.jobs = this.jobs.concat(producerJobs);
78 console.log("producerJobs: "+producerJobs);