2020-04-02 02:43:54 +02:00
|
|
|
import { AfterViewInit, Component, OnInit, ViewChild, ChangeDetectorRef } from '@angular/core';
|
2020-03-11 21:00:59 +01:00
|
|
|
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-20 00:01:45 +01:00
|
|
|
import Folder from '../../folder';
|
2020-03-25 14:41:22 +01:00
|
|
|
import { SystemConfigService } from '../../services/system-config.service';
|
2020-04-02 02:43:54 +02:00
|
|
|
import { FilterService } from 'src/app/services/filter.service';
|
|
|
|
import { StType } from 'src/app/type';
|
2020-03-11 21:00:59 +01:00
|
|
|
|
|
|
|
@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>;
|
2020-04-02 02:43:54 +02:00
|
|
|
filterValue: string = "";
|
2020-03-30 23:02:59 +02:00
|
|
|
|
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', 'label', 'path', 'state'];
|
2020-03-11 21:00:59 +01:00
|
|
|
|
2020-04-02 02:43:54 +02:00
|
|
|
constructor(
|
|
|
|
private systemConfigService: SystemConfigService,
|
|
|
|
private filterService: FilterService,
|
|
|
|
private cdr: ChangeDetectorRef,
|
|
|
|
) {
|
|
|
|
};
|
2020-03-11 21:00:59 +01:00
|
|
|
|
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 = [];
|
|
|
|
|
2020-03-18 02:10:31 +01:00
|
|
|
this.systemConfigService.getFolders().subscribe(
|
|
|
|
data => {
|
|
|
|
this.dataSource.data = 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-04-02 02:43:54 +02:00
|
|
|
|
|
|
|
// 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-11 21:00:59 +01:00
|
|
|
}
|
2020-03-30 23:02:59 +02:00
|
|
|
}
|