export class EIJobDataSource extends MatTableDataSource<EIJob> {
- private eiJobSubject = new BehaviorSubject<EIJob[]>([]);
+ eiJobsSubject = new BehaviorSubject<EIJob[]>([]);
private loadingSubject = new BehaviorSubject<boolean>(false);
super();
}
- loadTable() {
+ getJobs() {
this.loadingSubject.next(true);
- this.eiSvc.getEIJobs()
+ this.eiSvc.getProducerIds()
.pipe(
catchError((her: HttpErrorResponse) => {
this.notificationService.error('Failed to get EI jobs: ' + her.error);
}),
finalize(() => this.loadingSubject.next(false))
)
- .subscribe((instances: EIJob[]) => {
- this.rowCount = instances.length;
- this.eiJobSubject.next(instances);
+ .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<EIJob[]> {
- return this.eiJobSubject;
+ return this.eiJobsSubject;
}
disconnect(): void {
- this.eiJobSubject.complete();
+ this.eiJobsSubject.complete();
this.loadingSubject.complete();
}
}