2017-09-20 14:31:06 +03:00
|
|
|
import { Component, OnDestroy } from '@angular/core';
|
2017-08-04 15:11:32 +03:00
|
|
|
import { NbThemeService } from '@nebular/theme';
|
2019-01-18 16:25:35 +03:00
|
|
|
import { Electricity, ElectricityChart, ElectricityData } from '../../../@core/data/electricity';
|
2019-01-08 16:17:20 +03:00
|
|
|
import { takeWhile } from 'rxjs/operators';
|
|
|
|
|
import { forkJoin } from 'rxjs';
|
2017-07-11 18:59:08 +03:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'ngx-electricity',
|
|
|
|
|
styleUrls: ['./electricity.component.scss'],
|
|
|
|
|
templateUrl: './electricity.component.html',
|
|
|
|
|
})
|
2017-09-20 14:31:06 +03:00
|
|
|
export class ElectricityComponent implements OnDestroy {
|
2017-07-11 18:59:08 +03:00
|
|
|
|
2019-01-08 16:17:20 +03:00
|
|
|
private alive = true;
|
|
|
|
|
|
|
|
|
|
listData: Electricity[];
|
|
|
|
|
chartData: ElectricityChart[];
|
2017-07-14 18:55:38 +03:00
|
|
|
|
2017-10-20 17:31:36 +03:00
|
|
|
type = 'week';
|
2017-07-24 19:10:59 +03:00
|
|
|
types = ['week', 'month', 'year'];
|
|
|
|
|
|
2017-08-04 15:11:32 +03:00
|
|
|
currentTheme: string;
|
2017-09-20 14:31:06 +03:00
|
|
|
themeSubscription: any;
|
2017-08-04 15:11:32 +03:00
|
|
|
|
2019-01-18 16:25:35 +03:00
|
|
|
constructor(private electricityService: ElectricityData,
|
2020-09-21 15:05:51 +00:00
|
|
|
private themeService: NbThemeService) {
|
2019-01-08 16:17:20 +03:00
|
|
|
this.themeService.getJsTheme()
|
|
|
|
|
.pipe(takeWhile(() => this.alive))
|
|
|
|
|
.subscribe(theme => {
|
|
|
|
|
this.currentTheme = theme.name;
|
2020-09-21 15:05:51 +00:00
|
|
|
});
|
2019-01-08 16:17:20 +03:00
|
|
|
|
2020-09-21 15:05:51 +00:00
|
|
|
forkJoin([
|
2019-01-08 16:17:20 +03:00
|
|
|
this.electricityService.getListData(),
|
2020-09-21 22:06:24 +00:00
|
|
|
this.electricityService.getChartData(),
|
2020-09-21 15:05:51 +00:00
|
|
|
])
|
2019-01-08 16:17:20 +03:00
|
|
|
.pipe(takeWhile(() => this.alive))
|
2020-09-21 15:05:51 +00:00
|
|
|
.subscribe(([listData, chartData]: [Electricity[], ElectricityChart[]]) => {
|
2019-01-08 16:17:20 +03:00
|
|
|
this.listData = listData;
|
|
|
|
|
this.chartData = chartData;
|
|
|
|
|
});
|
2017-07-14 18:55:38 +03:00
|
|
|
}
|
2017-09-20 14:31:06 +03:00
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
2019-01-08 16:17:20 +03:00
|
|
|
this.alive = false;
|
2017-09-20 14:31:06 +03:00
|
|
|
}
|
2017-07-11 18:59:08 +03:00
|
|
|
}
|