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';
|
2020-03-30 23:02:59 +02:00
|
|
|
import { MatTable, MatTableDataSource } from '@angular/material/table';
|
2020-03-11 21:00:59 +01:00
|
|
|
|
2020-03-25 21:08:07 +01:00
|
|
|
import Device from '../../device';
|
2020-03-25 14:41:22 +01:00
|
|
|
import { SystemConfigService } from '../../services/system-config.service';
|
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>;
|
2020-03-30 23:02:59 +02:00
|
|
|
dataSource: MatTableDataSource<Device>;
|
2020-03-11 21:00:59 +01:00
|
|
|
|
|
|
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
2020-04-01 01:24:36 +02:00
|
|
|
displayedColumns = ['id', 'name', 'state'];
|
2020-03-11 21:00:59 +01:00
|
|
|
|
|
|
|
constructor(private systemConfigService: SystemConfigService) { };
|
|
|
|
|
2020-04-01 02:36:56 +02:00
|
|
|
applyFilter(event: Event) {
|
|
|
|
const filterValue = (event.target as HTMLInputElement).value;
|
|
|
|
this.dataSource.filter = filterValue.trim().toLowerCase();
|
|
|
|
}
|
|
|
|
|
2020-03-11 21:00:59 +01:00
|
|
|
ngOnInit() {
|
2020-03-30 23:02:59 +02:00
|
|
|
this.dataSource = new MatTableDataSource();
|
2020-03-14 03:09:48 +01:00
|
|
|
this.dataSource.data = [];
|
|
|
|
|
|
|
|
this.systemConfigService.getDevices().subscribe(
|
|
|
|
data => {
|
|
|
|
this.dataSource.data = data;
|
|
|
|
}
|
|
|
|
);
|
2020-03-11 21:00:59 +01:00
|
|
|
}
|
2020-03-18 02:10:31 +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
|
|
|
}
|