Fix problem with double load of EI tables 31/5631/1
authorelinuxhenrik <henrik.b.andersson@est.tech>
Thu, 11 Feb 2021 08:30:15 +0000 (09:30 +0100)
committerelinuxhenrik <henrik.b.andersson@est.tech>
Thu, 11 Feb 2021 08:30:19 +0000 (09:30 +0100)
Change-Id: Ie847cedb77131aa0db902972895018a5c8b20fc8
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Issue-ID: NONRTRIC-389

webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts
webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.ts

index 5fc64fc..27a70c4 100644 (file)
@@ -31,10 +31,10 @@ import { EIService } from '../services/ei/ei.service';
 
 export class EIJobDataSource {
 
-    private eiJobsSubject = new BehaviorSubject<EIJob[]>([]);
+    private jobs: Array<EIJob> = [];
 
     public eiJobs(): EIJob[] {
-        return this.eiJobsSubject.value;
+        return this.jobs;
     }
 
     private loadingSubject = new BehaviorSubject<boolean>(false);
@@ -49,25 +49,20 @@ export class EIJobDataSource {
 
     loadJobs() {
         this.loadingSubject.next(true);
+        this.jobs = [];
         this.eiSvc.getProducerIds()
             .subscribe((producerIds: string[]) => {
                 producerIds.forEach(id => {
                     this.getJobsForProducer(id);
                 });
             });
+        this.rowCount = this.jobs.length;
     }
 
     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;
+        this.eiSvc.getJobsForProducer(id).subscribe(producerJobs => {
+            this.jobs = this.jobs.concat(producerJobs);
         });
     }
-
-    private addJobsToSubject(jobs: EIJob[]) {
-        const currentValue = this.eiJobsSubject.value;
-        const updatedValue = [...currentValue, ...jobs];
-        this.eiJobsSubject.next(updatedValue);
-    }
 }
index 255c555..8dac859 100644 (file)
@@ -31,10 +31,10 @@ import { EIService } from '../services/ei/ei.service';
 
 export class EIProducerDataSource {
 
-    private producerSubject = new BehaviorSubject<EIProducer[]>([]);
+    private producers: Array<EIProducer> = [];
 
     public eiProducers(): EIProducer[] {
-        return this.producerSubject.value;
+        return this.producers;
     }
 
     private loadingSubject = new BehaviorSubject<boolean>(false);
@@ -49,7 +49,7 @@ export class EIProducerDataSource {
 
     loadProducers() {
         this.loadingSubject.next(true);
-        let producers: Array<EIProducer> = [];
+        this.producers = [];
         this.eiSvc.getProducerIds()
             .subscribe((prodIds: string[]) => {
                 console.log("ProducerIds: " + prodIds);
@@ -62,16 +62,9 @@ export class EIProducerDataSource {
                     this.eiSvc.getProducerStatus(id).subscribe(prodStatus => {
                         eiProducer.status = prodStatus.opState.toString();
                     });
-                    this.addProducerToSubject(eiProducer);
-                    producers.push(eiProducer);
+                    this.producers.push(eiProducer);
                 });
-                this.rowCount = this.producerSubject.value.length;
+                this.rowCount = this.producers.length;
             });
     }
-
-    private addProducerToSubject(producer: EIProducer) {
-        const currentValue = this.producerSubject.value;
-        const updatedValue = [...currentValue, producer];
-        this.producerSubject.next(updatedValue);
-    }
 }
\ No newline at end of file