- this.eiSvc.getProducerIds()
- .pipe(
- catchError((her: HttpErrorResponse) => {
- this.notificationService.error('Failed to get EI jobs: ' + her.error);
- return of([]);
- }),
- finalize(() => this.loadingSubject.next(false))
- )
- .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);
+ this.jobs = [];
+ this.eiSvc.getProducerIds().pipe(
+ mergeMap(prodIds =>
+ forkJoin(prodIds.map(id => this.eiSvc.getJobsForProducer(id)))),
+ mergeMap(result => result),
+ finalize(() => this.loadingSubject.next(false))
+ ).subscribe(result => {
+ this.jobs = this.jobs.concat(result);
+ this.jobsSubject.next(this.jobs);
+ } );
+ this.rowCount = this.jobs.length;