import { Component, AfterViewInit } from '@angular/core'; import { Title } from '@angular/platform-browser'; import { TdLoadingService, TdDigitsPipe } from '@covalent/core'; import { ItemsService, UsersService, ProductsService, AlertsService } from '../../services/'; import { multi } from './data'; @Component({ selector: 'qs-dashboard', templateUrl: './dashboard.component.html', styleUrls: ['./dashboard.component.scss'], viewProviders: [ ItemsService, UsersService, ProductsService, AlertsService ], }) export class DashboardComponent implements AfterViewInit { items: Object[]; users: Object[]; products: Object[]; alerts: Object[]; // Chart single: any[]; multi: any[]; view: any[] = [700, 400]; // options showXAxis: boolean = true; showYAxis: boolean = true; gradient: boolean = false; showLegend: boolean = false; showXAxisLabel: boolean = true; xAxisLabel: string = ''; showYAxisLabel: boolean = true; yAxisLabel: string = 'Sales'; colorScheme: any = { domain: ['#1565C0', '#2196F3', '#81D4FA', '#FF9800', '#EF6C00'], }; // line, area autoScale: boolean = true; constructor(private _titleService: Title, private _itemsService: ItemsService, private _usersService: UsersService, private _alertsService: AlertsService, private _productsService: ProductsService, private _loadingService: TdLoadingService) { // Chart this.multi = multi.map((group: any) => { group.series = group.series.map((dataItem: any) => { dataItem.name = new Date(dataItem.name); return dataItem; }); return group; }); } ngAfterViewInit(): void { this._titleService.setTitle( 'Covalent Quickstart' ); this._loadingService.register('items.load'); this._itemsService.query().subscribe((items: Object[]) => { this.items = items; setTimeout(() => { this._loadingService.resolve('items.load'); }, 750); }, (error: Error) => { this._itemsService.staticQuery().subscribe((items: Object[]) => { this.items = items; setTimeout(() => { this._loadingService.resolve('items.load'); }, 750); }); }); this._loadingService.register('alerts.load'); this._alertsService.query().subscribe((alerts: Object[]) => { this.alerts = alerts; setTimeout(() => { this._loadingService.resolve('alerts.load'); }, 750); }); this._loadingService.register('products.load'); this._productsService.query().subscribe((products: Object[]) => { this.products = products; setTimeout(() => { this._loadingService.resolve('products.load'); }, 750); }); this._loadingService.register('favorites.load'); this._productsService.query().subscribe((products: Object[]) => { this.products = products; setTimeout(() => { this._loadingService.resolve('favorites.load'); }, 750); }); this._loadingService.register('users.load'); this._usersService.query().subscribe((users: Object[]) => { this.users = users; setTimeout(() => { this._loadingService.resolve('users.load'); }, 750); }, (error: Error) => { this._usersService.staticQuery().subscribe((users: Object[]) => { this.users = users; setTimeout(() => { this._loadingService.resolve('users.load'); }, 750); }); }); } // ngx transform using covalent digits pipe axisDigits(val: any): any { return new TdDigitsPipe().transform(val); } }