Use promise.all in table component to sync the table loading

This commit is contained in:
Marcel Schwarz 2021-01-08 12:35:09 +01:00
parent abfc5424a3
commit 493cdd9ea7

View File

@ -26,8 +26,8 @@ export class TableComponent implements OnInit {
bikePoint: IDashboardCommonBikePoint; bikePoint: IDashboardCommonBikePoint;
maxStartDate: Date; maxStartDate: Date;
maxEndDate: Date; maxEndDate: Date;
isLoadingToSource: boolean; isLoadingToSource = true;
isLoadingFromSource: boolean; isLoadingFromSource = true;
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
@ -54,45 +54,49 @@ export class TableComponent implements OnInit {
this.selectionModel.clear(); this.selectionModel.clear();
this.map.removeOverlayOnMiniMap(); this.map.removeOverlayOnMiniMap();
const initDate = this.maxEndDate.toISOString().substring(0, 10); const initDate = this.maxEndDate.toISOString().substring(0, 10);
await this.service.fetchDashboardStationTo(this.bikePoint.id, initDate, initDate).then(source => {
const [stationTo, stationFrom] = await Promise.all([
this.service.fetchDashboardStationTo(this.bikePoint.id, initDate, initDate),
this.service.fetchDashboardStationFrom(this.bikePoint.id, initDate, initDate)
]);
this.isLoadingToSource = false; this.isLoadingToSource = false;
this.stationToSource = this.setBikePointColorToSource(source);
this.iterableToSource = source;
this.iterableToSource.forEach(bikePoint => {
bikePoint.polyLineColor = 'green';
});
});
this.service.fetchDashboardStationFrom(this.bikePoint.id, initDate, initDate).then(source => {
this.isLoadingFromSource = false; this.isLoadingFromSource = false;
this.stationFromSource = this.setBikePointColorFromSource(source);
this.iterableFromSource = source; this.stationToSource = this.setBikePointColorToSource(stationTo);
this.iterableFromSource.forEach(bikePoint => { this.iterableToSource = stationTo;
bikePoint.polyLineColor = 'red'; this.iterableToSource.forEach(bikePoint => bikePoint.polyLineColor = 'red');
});
}); this.stationFromSource = this.setBikePointColorFromSource(stationFrom);
this.iterableFromSource = stationFrom;
this.iterableFromSource.forEach(bikePoint => bikePoint.polyLineColor = 'green');
} }
async onSubmit(actualStartDate: string, actualEndDate: string): Promise<void> { async onSubmit(actualStartDate: string, actualEndDate: string): Promise<void> {
this.resetTableSourcesToDisplaySpinner(); this.resetTableSourcesToDisplaySpinner();
this.selectionModel.clear(); this.selectionModel.clear();
this.map.removeOverlayOnMiniMap(); this.map.removeOverlayOnMiniMap();
await this.service.fetchDashboardStationTo(this.bikePoint.id, actualStartDate, actualEndDate).then((source) => {
this.colors = ['black', 'gray', 'green', 'orange', 'purple', 'red']; this.isLoadingToSource = true;
this.isLoadingFromSource = true;
const [stationTo, stationFrom] = await Promise.all([
this.service.fetchDashboardStationTo(this.bikePoint.id, actualStartDate, actualEndDate),
this.service.fetchDashboardStationFrom(this.bikePoint.id, actualStartDate, actualEndDate)
]);
this.isLoadingToSource = false; this.isLoadingToSource = false;
this.stationToSource = this.setBikePointColorFromSource(source);
this.iterableToSource = source;
this.iterableToSource.forEach(bikePoint => {
bikePoint.polyLineColor = 'green';
});
});
this.service.fetchDashboardStationFrom(this.bikePoint.id, actualStartDate, actualEndDate).then((source) => {
this.isLoadingFromSource = false; this.isLoadingFromSource = false;
this.stationFromSource = this.setBikePointColorFromSource(source);
this.iterableFromSource = source; this.colors = ['black', 'gray', 'green', 'orange', 'purple', 'red'];
this.iterableFromSource.forEach(bikePoint => { this.stationToSource = this.setBikePointColorToSource(stationTo);
bikePoint.polyLineColor = 'red'; this.iterableToSource = stationTo;
}); this.iterableToSource.forEach(bikePoint => bikePoint.polyLineColor = 'green');
});
this.stationFromSource = this.setBikePointColorFromSource(stationFrom);
this.iterableFromSource = stationFrom;
this.iterableFromSource.forEach(bikePoint => bikePoint.polyLineColor = 'red');
} }
resetTableSourcesToDisplaySpinner(): void { resetTableSourcesToDisplaySpinner(): void {