syncthing/src/app/lists/folder-list/folder-list.component.ts

65 lines
2.1 KiB
TypeScript
Raw Normal View History

import { AfterViewInit, Component, OnInit, ViewChild, ChangeDetectorRef } 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';
import Folder from '../../folder';
2020-03-25 14:41:22 +01:00
import { SystemConfigService } from '../../services/system-config.service';
import { FilterService } from 'src/app/services/filter.service';
import { StType } from 'src/app/type';
@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>;
2020-03-30 23:02:59 +02:00
dataSource: MatTableDataSource<Folder>;
filterValue: string = "";
2020-03-30 23:02:59 +02:00
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['id', 'label', 'path', 'state'];
constructor(
private systemConfigService: SystemConfigService,
private filterService: FilterService,
private cdr: ChangeDetectorRef,
) {
};
applyFilter(event: Event) {
const filterValue = (event.target as HTMLInputElement).value;
this.dataSource.filter = filterValue.trim().toLowerCase();
}
ngOnInit() {
2020-03-30 23:02:59 +02:00
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;
// Listen for filter changes from other components
this.filterService.filterChanged$
.subscribe(
input => {
if (input.type === StType.Folder) {
this.dataSource.filter = input.text.trim().toLowerCase();
this.filterValue = input.text;
this.cdr.detectChanges();
}
});
}
2020-03-30 23:02:59 +02:00
}