2018-08-08 16:45:31 +03:00
|
|
|
import { Component, OnDestroy } from '@angular/core';
|
2019-01-18 16:25:35 +03:00
|
|
|
import { TrafficList, TrafficListData } from '../../../@core/data/traffic-list';
|
|
|
|
|
import { TrafficBarData, TrafficBar } from '../../../@core/data/traffic-bar';
|
2018-08-08 16:45:31 +03:00
|
|
|
import { takeWhile } from 'rxjs/operators';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'ngx-traffic-reveal-card',
|
|
|
|
|
styleUrls: ['./traffic-reveal-card.component.scss'],
|
|
|
|
|
templateUrl: './traffic-reveal-card.component.html',
|
|
|
|
|
})
|
|
|
|
|
export class TrafficRevealCardComponent implements OnDestroy {
|
|
|
|
|
|
|
|
|
|
private alive = true;
|
|
|
|
|
|
|
|
|
|
trafficBarData: TrafficBar;
|
2021-10-17 04:15:43 +03:00
|
|
|
trafficListData: TrafficList[];
|
2018-08-08 16:45:31 +03:00
|
|
|
revealed = false;
|
|
|
|
|
period: string = 'week';
|
|
|
|
|
|
2019-01-18 16:25:35 +03:00
|
|
|
constructor(private trafficListService: TrafficListData,
|
|
|
|
|
private trafficBarService: TrafficBarData) {
|
2018-08-08 16:45:31 +03:00
|
|
|
this.getTrafficFrontCardData(this.period);
|
|
|
|
|
this.getTrafficBackCardData(this.period);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleView() {
|
|
|
|
|
this.revealed = !this.revealed;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-08 16:17:20 +03:00
|
|
|
setPeriodAngGetData(value: string): void {
|
|
|
|
|
this.period = value;
|
|
|
|
|
|
2018-08-08 16:45:31 +03:00
|
|
|
this.getTrafficFrontCardData(value);
|
|
|
|
|
this.getTrafficBackCardData(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getTrafficBackCardData(period: string) {
|
|
|
|
|
this.trafficBarService.getTrafficBarData(period)
|
|
|
|
|
.pipe(takeWhile(() => this.alive ))
|
|
|
|
|
.subscribe(trafficBarData => {
|
|
|
|
|
this.trafficBarData = trafficBarData;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getTrafficFrontCardData(period: string) {
|
|
|
|
|
this.trafficListService.getTrafficListData(period)
|
2019-07-02 16:18:09 +03:00
|
|
|
.pipe(takeWhile(() => this.alive))
|
2018-08-08 16:45:31 +03:00
|
|
|
.subscribe(trafficListData => {
|
|
|
|
|
this.trafficListData = trafficListData;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
|
this.alive = false;
|
|
|
|
|
}
|
|
|
|
|
}
|