syncthing/src/app/list/device-list/device-list.component.ts

45 lines
1.4 KiB
TypeScript
Raw Normal View History

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';
import { Device } from '../../device';
import { SystemConfigService } from '../../system-config.service';
import { cardElevation } from '../../style';
@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;
elevation: string = cardElevation;
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['id', 'name'];
constructor(private systemConfigService: SystemConfigService) { };
ngOnInit() {
this.dataSource = new DeviceListDataSource(this.systemConfigService);
this.dataSource.data = [];
}
ngAfterViewInit() {
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
this.table.dataSource = this.dataSource;
this.systemConfigService.getDevices().subscribe(
data => {
this.dataSource.data = data;
}
);
}
}