add station-link navigation in tables and add default start value in range-picker

This commit is contained in:
Tim Herbst 2020-12-28 11:45:53 +01:00
parent 3600f3a6e3
commit 1b82cd6b8f
3 changed files with 102 additions and 87 deletions

View File

@ -82,7 +82,7 @@
<ng-container matColumnDef="endStationName">
<th *matHeaderCellDef mat-header-cell> station of lend destination</th>
<td *matCellDef="let element" mat-cell><a
[routerLink]="['/dashboard/', element.id]">{{element.endStationName}}</a></td>
[routerLink]="['/dashboard/', element.stationId]">{{element.stationName}}</a></td>
</ng-container>
<ng-container matColumnDef="number">
@ -104,7 +104,7 @@
<ng-container matColumnDef="startStationName">
<th *matHeaderCellDef mat-header-cell> station of lend origin</th>
<td *matCellDef="let element" mat-cell><a
[routerLink]="['/dashboard/', element.id]"> {{element.startStationName}}</a></td>
[routerLink]="['/dashboard/', element.stationId]"> {{element.stationName}}</a></td>
</ng-container>
<ng-container matColumnDef="number">

View File

@ -1,10 +1,11 @@
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {ActivatedRoute, Router} from '@angular/router';
import {DashboardService} from '../service/dashboard.service';
import {IDashboardCommonBikePoint} from '../service/domain/dashboard-common-bike-point';
import {MatTableDataSource} from '@angular/material/table';
import {FormBuilder, FormControl, FormGroup} from '@angular/forms';
import {MapService} from '../service/map.service';
import 'humanize-duration/humanize-duration';
import {
ApexAxisChartSeries,
@ -68,6 +69,7 @@ export class DashboardComponent implements OnInit {
constructor(
private route: ActivatedRoute,
private router: Router,
private service: DashboardService,
private map: MapService,
private changeDetectorRefs: ChangeDetectorRef,
@ -109,15 +111,16 @@ export class DashboardComponent implements OnInit {
end: new FormControl()
})
});
this.service.fetchDashboardInit(this.route.snapshot.paramMap.get('id')).then(data => {
this.changeDetectorRefs.detectChanges();
this.route.params.subscribe(params => {
this.service.fetchDashboardInit(params.id).then(data => {
this.station = data;
this.maxStartDate = new Date(data.maxStartDate);
this.maxEndDate = new Date(data.maxEndDate);
this.initDashboard();
});
this.service.fetchBikePointForStatus(this.route.snapshot.paramMap.get('id')).then(data => {
this.service.fetchBikePointForStatus(params.id).then(data => {
this.bikePoint = data;
const NbBlockedDocks = data.status.NbDocks - data.status.NbBikes - data.status.NbEmptyDocks;
this.bikePointChartOptions = {
@ -197,10 +200,14 @@ export class DashboardComponent implements OnInit {
}
};
});
});
}
initDashboard(): void {
const initDate = this.maxEndDate.toISOString().substring(0, 10);
this.form.get('daterange').get('start').setValue(initDate);
this.form.get('daterange').get('end').setValue(initDate);
this.service.fetchDashboardStationTo(this.station.id, initDate, initDate).then((source) => {
this.stationToSource = source;
this.changeDetectorRefs.detectChanges();
@ -465,4 +472,8 @@ export class DashboardComponent implements OnInit {
};
});
}
routeToStation(stationId: string): void {
this.router.navigate(['/dashboard', stationId]);
}
}

View File

@ -42,6 +42,10 @@ export class MapService {
}
public initDashboardMap(lat: number, lon: number, zoom: number): void {
if(this.miniMap) {
this.miniMap.off();
this.miniMap.remove();
}
this.miniMap = L.map('minimap').setView([lat, lon], zoom);
this.miniMap.addLayer(new L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data <a href="https://openstreetmap.org">OpenStreetMap</a> contributors',