feat(data): update data module, add new mock data (#1960)

This commit is contained in:
Denis Strigo 2019-01-08 16:17:20 +03:00 committed by GitHub
parent 773c14e74a
commit 47d232b606
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 635 additions and 256 deletions

View file

@ -1,7 +1,9 @@
import { Component, OnDestroy } from '@angular/core';
import { NbThemeService } from '@nebular/theme';
import { ElectricityService } from '../../../@core/data/electricity.service';
import { Electricity, ElectricityChart, ElectricityService } from '../../../@core/data/electricity.service';
import { takeWhile } from 'rxjs/operators';
import { forkJoin } from 'rxjs';
@Component({
selector: 'ngx-electricity',
@ -10,7 +12,10 @@ import { ElectricityService } from '../../../@core/data/electricity.service';
})
export class ElectricityComponent implements OnDestroy {
data: Array<any>;
private alive = true;
listData: Electricity[];
chartData: ElectricityChart[];
type = 'week';
types = ['week', 'month', 'year'];
@ -18,15 +23,26 @@ export class ElectricityComponent implements OnDestroy {
currentTheme: string;
themeSubscription: any;
constructor(private eService: ElectricityService, private themeService: NbThemeService) {
this.data = this.eService.getData();
this.themeSubscription = this.themeService.getJsTheme().subscribe(theme => {
this.currentTheme = theme.name;
constructor(private electricityService: ElectricityService,
private themeService: NbThemeService) {
this.themeService.getJsTheme()
.pipe(takeWhile(() => this.alive))
.subscribe(theme => {
this.currentTheme = theme.name;
});
forkJoin(
this.electricityService.getListData(),
this.electricityService.getChartData(),
)
.pipe(takeWhile(() => this.alive))
.subscribe(([listData, chartData]) => {
this.listData = listData;
this.chartData = chartData;
});
}
ngOnDestroy() {
this.themeSubscription.unsubscribe();
this.alive = false;
}
}