Files
syncthing/src/app/lists/folder-list/folder-list.component.ts
2020-03-31 20:40:36 -04:00

46 lines
1.5 KiB
TypeScript

import { AfterViewInit, Component, OnInit, ViewChild, Input } from '@angular/core';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { MatTable, MatTableDataSource } from '@angular/material/table';
import Folder from '../../folder';
import { SystemConfigService } from '../../services/system-config.service';
@Component({
selector: 'app-folder-list',
templateUrl: './folder-list.component.html',
styleUrls: ['./folder-list.component.scss']
})
export class FolderListComponent implements AfterViewInit, OnInit {
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
@ViewChild(MatTable) table: MatTable<Folder>;
dataSource: MatTableDataSource<Folder>;
applyFilter(event: Event) {
const filterValue = (event.target as HTMLInputElement).value;
this.dataSource.filter = filterValue.trim().toLowerCase();
}
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['id', 'label', 'path', 'state'];
constructor(private systemConfigService: SystemConfigService) { };
ngOnInit() {
this.dataSource = new MatTableDataSource();
this.dataSource.data = [];
this.systemConfigService.getFolders().subscribe(
data => {
this.dataSource.data = data;
}
);
}
ngAfterViewInit() {
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
this.table.dataSource = this.dataSource;
}
}