Extract common code for table loading

Preselect dashboard station in table selection model
This commit is contained in:
Marcel Schwarz 2021-01-08 14:56:18 +01:00
parent b6b02f2c01
commit 860d351323

View File

@ -16,8 +16,8 @@ import {ActivatedRoute} from '@angular/router';
export class TableComponent implements OnInit {
displayedColumnsTo: string[] = ['select', 'endStationName', 'number', 'avgDuration', 'marker'];
displayedColumnsFrom: string[] = ['select', 'startStationName', 'number', 'avgDuration', 'marker'];
stationToSource = new MatTableDataSource<IDashboardCommonBikePoint>();
stationToSource = new MatTableDataSource<IDashboardCommonBikePoint>();
iterableToSource: any[];
stationFromSource = new MatTableDataSource<IDashboardCommonBikePoint>();
iterableFromSource: any[];
@ -37,8 +37,6 @@ export class TableComponent implements OnInit {
}
ngOnInit(): void {
this.isLoadingToSource = true;
this.isLoadingFromSource = true;
this.route.params.subscribe(params => {
this.colors = ['black', 'gray', 'green', 'orange', 'purple', 'red'];
this.service.fetchDashboardInit(params.id).then(data => {
@ -50,33 +48,30 @@ export class TableComponent implements OnInit {
});
}
async initTable(): Promise<void> {
initTable(): void {
this.selectionModel.clear();
this.map.removeOverlayOnMiniMap();
const initDate = this.maxEndDate.toISOString().substring(0, 10);
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.isLoadingFromSource = false;
this.stationToSource = this.setBikePointColorToSource(stationTo);
this.iterableToSource = stationTo;
this.iterableToSource.forEach(bikePoint => bikePoint.polyLineColor = 'red');
this.stationFromSource = this.setBikePointColorFromSource(stationFrom);
this.iterableFromSource = stationFrom;
this.iterableFromSource.forEach(bikePoint => bikePoint.polyLineColor = 'green');
this.loadData(initDate, initDate);
}
async onSubmit(actualStartDate: string, actualEndDate: string): Promise<void> {
onSubmit(actualStartDate: string, actualEndDate: string): void {
this.resetTableSourcesToDisplaySpinner();
this.selectionModel.clear();
this.map.removeOverlayOnMiniMap();
this.loadData(actualStartDate, actualEndDate);
}
resetTableSourcesToDisplaySpinner(): void {
this.isLoadingToSource = true;
this.isLoadingFromSource = true;
this.stationToSource = null;
this.stationFromSource = null;
this.iterableToSource = [];
this.iterableFromSource = [];
}
async loadData(actualStartDate: string, actualEndDate: string): Promise<void> {
this.isLoadingToSource = true;
this.isLoadingFromSource = true;
@ -97,15 +92,8 @@ export class TableComponent implements OnInit {
this.iterableFromSource = stationFrom;
this.iterableFromSource.forEach(bikePoint => bikePoint.polyLineColor = 'red');
}
resetTableSourcesToDisplaySpinner(): void {
this.isLoadingToSource = true;
this.isLoadingFromSource = true;
this.stationToSource = null;
this.stationFromSource = null;
this.iterableToSource = [];
this.iterableFromSource = [];
this.selectionModel.select(...this.iterableFromSource.filter(bikePoint => bikePoint.stationId === this.bikePoint.id));
this.selectionModel.select(...this.iterableToSource.filter(bikePoint => bikePoint.stationId === this.bikePoint.id));
}
public drawIconInTable(bikePoint: any): string {
@ -137,9 +125,7 @@ export class TableComponent implements OnInit {
changePolyLineColorForDuplicateBikePoints(array: any[]): any[] {
const id = array.map(item => item.stationId);
const duplicates = id.filter((value, index) => {
return id.indexOf(value) !== index;
});
const duplicates = id.filter((value, index) => id.indexOf(value) !== index);
duplicates.forEach(stationId => {
array.forEach(bikePoint => {
if (bikePoint.stationId === stationId) {