2020-03-11 21:00:59 +01:00
|
|
|
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core';
|
|
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
|
|
import { MatSort } from '@angular/material/sort';
|
|
|
|
import { MatTable } from '@angular/material/table';
|
|
|
|
|
|
|
|
import { DeviceListDataSource } from './device-list-datasource';
|
2020-03-16 17:11:27 +01:00
|
|
|
import { Device } from '../../device';
|
|
|
|
import { SystemConfigService } from '../../system-config.service';
|
2020-03-16 18:53:07 +01:00
|
|
|
import { cardElevation } from '../../style';
|
2020-03-11 21:00:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-device-list',
|
|
|
|
templateUrl: './device-list.component.html',
|
|
|
|
styleUrls: ['./device-list.component.scss']
|
|
|
|
})
|
|
|
|
export class DeviceListComponent implements AfterViewInit, OnInit {
|
|
|
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
|
|
|
@ViewChild(MatSort) sort: MatSort;
|
|
|
|
@ViewChild(MatTable) table: MatTable<Device>;
|
|
|
|
dataSource: DeviceListDataSource;
|
2020-03-16 18:53:07 +01:00
|
|
|
elevation: string = cardElevation;
|
2020-03-11 21:00:59 +01:00
|
|
|
|
|
|
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
|
|
|
displayedColumns = ['id', 'name'];
|
|
|
|
|
|
|
|
constructor(private systemConfigService: SystemConfigService) { };
|
|
|
|
|
|
|
|
ngOnInit() {
|
2020-03-14 03:09:48 +01:00
|
|
|
this.dataSource = new DeviceListDataSource(this.systemConfigService);
|
|
|
|
this.dataSource.data = [];
|
2020-03-11 21:00:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
|
|
|
this.dataSource.sort = this.sort;
|
|
|
|
this.dataSource.paginator = this.paginator;
|
|
|
|
this.table.dataSource = this.dataSource;
|
2020-03-14 03:09:48 +01:00
|
|
|
|
|
|
|
this.systemConfigService.getDevices().subscribe(
|
|
|
|
data => {
|
|
|
|
this.dataSource.data = data;
|
|
|
|
}
|
|
|
|
);
|
2020-03-11 21:00:59 +01:00
|
|
|
}
|
2020-03-14 03:09:48 +01:00
|
|
|
}
|