import { mergeMap, finalize, map, tap, concatMap, delay, skip, catchError } from "rxjs/operators";
import { ConsumerService } from "@services/ei/consumer.service";
import { UiService } from "@services/ui/ui.service";
-import { EmptyObservable } from 'rxjs/observable/EmptyObservable';
export interface Job {
jobId: string;
subscription: Subscription;
checked: boolean = false;
firstTime: boolean = true;
+ jobList: Job[] = [];
constructor(private consumerService: ConsumerService, private ui: UiService) {
this.jobForm = new FormGroup({
dataSubscription(): Subscription {
const jobsInfo$ = this.consumerService.getJobIds().pipe(
+ tap((_) => {
+ this.jobList = [] as Job[];
+ }),
mergeMap((jobIds) =>
forkJoin(jobIds.map((jobId) => {
return forkJoin([
}))
),
finalize(() => {
- this.loadingSubject$.next(false)
+ this.loadingSubject$.next(false);
+ this.jobsSubject$.next(this.jobList);
})
);
concatMap((value) => {
let pollCondition = value == 0 || this.checked;
return pollCondition ? refreshedJobs$ : EMPTY;
- }),
+ })
)
.subscribe();
}
private extractJobs(res: any) {
this.clearFilter();
- let jobList = [];
res.forEach(element => {
if(element[1] != -1 && element[2] != -1){
let jobObj = <Job>{};
jobObj.targetUri = element[1].job_result_uri;
jobObj.typeId = element[1].info_type_id;
jobObj.prodIds = (element[2].producers) ? element[2].producers : ["No Producers"];
- jobList = jobList.concat(jobObj);
+ this.jobList = this.jobList.concat(jobObj);
}
});
- this.jobsSubject$.next(jobList);
- if (this.firstTime && jobList.length > 0) {
- this.polling$.next(jobList.length);
+ if (this.firstTime && this.jobList.length > 0) {
+ this.polling$.next(this.jobList.length);
this.firstTime = false;
}
- return jobList;
+ return this.jobList;
}
refreshDataClick() {
this.refresh$.next("");
}
+
+ hasJobs(): boolean {
+ return this.jobs().length > 0;
+ }
+
}
it('should contain data after initialization', async () => {
setServiceSpy();
- component.ngOnInit();
const expectedProducerRows = [
expectedProducer1Row,
{ id: 'producer2', types: 'type2,type3', status: 'DISABLED' }
producerServiceSpy.getProducer.and.returnValues(of({} as ProducerRegistrationInfo));
producerServiceSpy.getProducerStatus.and.returnValues(of({} as ProducerStatus));
- component.ngOnInit();
const expectedProducerRow = { id: 'producer1', types: '< No types >', status: '< No status >' };
+
let producersTable = await loader.getHarness(MatTableHarness.with({ selector: '#producersTable' }));
let producerRows = await producersTable.getRows();
expect(await producerRows[0].getCellTextByColumnName()).toEqual(expectedProducerRow);
it('filtering', async () => {
setServiceSpy();
- component.ngOnInit();
let producersTable = await loader.getHarness(MatTableHarness.with({ selector: '#producersTable' }));
let idFilterInput = await loader.getHarness(MatInputHarness.with({ selector: '#producerIdFilter' }));
])
})
)),
- finalize(() => this.loadingSubject.next(false)),
+ finalize(() => {
+ this.loadingSubject.next(false);
+ this.producerSubject.next(producers);
+ })
).subscribe(result => {
producers = result.map(producer => {
let producerObj = <Producer>{};
}
return producerObj;
});
- this.producerSubject.next(producers);
}, err => {
console.error("Subscribe function error:" + err);
});
}
+
+ hasProducers(): boolean {
+ return this.producers().length > 0;
+ }
+
}
})
)
),
- finalize(() => this.loadingSubject$.next(false))
+ finalize(() => {
+ this.loadingSubject$.next(false);
+ this.policyInstanceSubject.next(this.policyInstances);
+ })
)
.subscribe((res) => {
this.policyInstances = res.map((policy) => {
policyInstance.lastModified = policy[1].last_modified;
return policyInstance;
});
- this.policyInstanceSubject.next(this.policyInstances);
});
}
}
instanceCount(): number {
- return this.policyInstances.length;
+ return this.instanceDataSource.data.length;
}
toLocalTime(utcTime: string): string {