From c9610a7c067ad9211785b00153377237f0df47a8 Mon Sep 17 00:00:00 2001 From: elinuxhenrik Date: Thu, 11 Feb 2021 09:30:15 +0100 Subject: [PATCH] Fix problem with double load of EI tables Change-Id: Ie847cedb77131aa0db902972895018a5c8b20fc8 Signed-off-by: elinuxhenrik Issue-ID: NONRTRIC-389 --- .../src/app/ei-coordinator/ei-job.datasource.ts | 17 ++++++----------- .../src/app/ei-coordinator/ei-producer.datasource.ts | 17 +++++------------ 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts b/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts index 5fc64fc..27a70c4 100644 --- a/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts +++ b/webapp-frontend/src/app/ei-coordinator/ei-job.datasource.ts @@ -31,10 +31,10 @@ import { EIService } from '../services/ei/ei.service'; export class EIJobDataSource { - private eiJobsSubject = new BehaviorSubject([]); + private jobs: Array = []; public eiJobs(): EIJob[] { - return this.eiJobsSubject.value; + return this.jobs; } private loadingSubject = new BehaviorSubject(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); - } } diff --git a/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.ts b/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.ts index 255c555..8dac859 100644 --- a/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.ts +++ b/webapp-frontend/src/app/ei-coordinator/ei-producer.datasource.ts @@ -31,10 +31,10 @@ import { EIService } from '../services/ei/ei.service'; export class EIProducerDataSource { - private producerSubject = new BehaviorSubject([]); + private producers: Array = []; public eiProducers(): EIProducer[] { - return this.producerSubject.value; + return this.producers; } private loadingSubject = new BehaviorSubject(false); @@ -49,7 +49,7 @@ export class EIProducerDataSource { loadProducers() { this.loadingSubject.next(true); - let producers: Array = []; + 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 -- 2.16.6