Merge "Reroute Enrichment to gateway"
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / ei-coordinator / ei-job.datasource.ts
index 9e048b6..ef9e478 100644 (file)
@@ -36,7 +36,7 @@ import { NotificationService } from '../services/ui/notification.service';
 
 export class EIJobDataSource extends MatTableDataSource<EIJob> {
 
-    private eiJobSubject = new BehaviorSubject<EIJob[]>([]);
+    eiJobsSubject = new BehaviorSubject<EIJob[]>([]);
 
     private loadingSubject = new BehaviorSubject<boolean>(false);
 
@@ -50,9 +50,9 @@ export class EIJobDataSource extends MatTableDataSource<EIJob> {
         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);
@@ -60,18 +60,33 @@ export class EIJobDataSource extends MatTableDataSource<EIJob> {
                 }),
                 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();
     }
 }