diff --git a/src/app/list-toggle/list-toggle.component.html b/src/app/list-toggle/list-toggle.component.html index 97e3beda3..51c58f0fb 100644 --- a/src/app/list-toggle/list-toggle.component.html +++ b/src/app/list-toggle/list-toggle.component.html @@ -1,4 +1,4 @@ - + Folders Devices \ No newline at end of file diff --git a/src/app/lists/device-list/device-list.component.html b/src/app/lists/device-list/device-list.component.html index 5cc013d38..f831c6d45 100644 --- a/src/app/lists/device-list/device-list.component.html +++ b/src/app/lists/device-list/device-list.component.html @@ -1,6 +1,6 @@ Filter - + diff --git a/src/app/lists/device-list/device-list.component.ts b/src/app/lists/device-list/device-list.component.ts index 26c5f600f..846e3a189 100644 --- a/src/app/lists/device-list/device-list.component.ts +++ b/src/app/lists/device-list/device-list.component.ts @@ -1,4 +1,4 @@ -import { AfterViewInit, Component, OnInit, ViewChild, ChangeDetectorRef } from '@angular/core'; +import { AfterViewInit, Component, OnInit, ViewChild, ChangeDetectorRef, OnDestroy } from '@angular/core'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; import { MatTable, MatTableDataSource } from '@angular/material/table'; @@ -7,18 +7,19 @@ import Device from '../../device'; import { SystemConfigService } from '../../services/system-config.service'; import { FilterService } from 'src/app/services/filter.service'; import { StType } from 'src/app/type'; +import { MatInput } from '@angular/material/input'; @Component({ selector: 'app-device-list', templateUrl: './device-list.component.html', styleUrls: ['./device-list.component.scss'] }) -export class DeviceListComponent implements AfterViewInit, OnInit { +export class DeviceListComponent implements AfterViewInit, OnInit, OnDestroy { @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; @ViewChild(MatTable) table: MatTable; + @ViewChild(MatInput) input: MatInput; dataSource: MatTableDataSource; - filterValue: string = ""; /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */ displayedColumns = ['id', 'name', 'state']; @@ -53,8 +54,11 @@ export class DeviceListComponent implements AfterViewInit, OnInit { this.table.dataSource = this.dataSource; const changeText = (text: string) => { + if (!text) + return; + this.dataSource.filter = text.trim().toLowerCase(); - this.filterValue = text; + this.input.value = text; this.cdr.detectChanges(); } @@ -62,11 +66,14 @@ export class DeviceListComponent implements AfterViewInit, OnInit { changeText(this.filterService.previousInputs.get(StType.Device)); // Listen for filter changes from other components - this.filterService.filterChanged$.subscribe( - input => { - if (input.type === StType.Device) { - changeText(input.text); - } - }); + this.filterService.filterChanged$ + .subscribe( + input => { + if (input.type === StType.Device) { + changeText(input.text); + } + }); } + + ngOnDestroy() { } } \ No newline at end of file diff --git a/src/app/lists/folder-list/folder-list.component.html b/src/app/lists/folder-list/folder-list.component.html index 476276877..aeee70087 100644 --- a/src/app/lists/folder-list/folder-list.component.html +++ b/src/app/lists/folder-list/folder-list.component.html @@ -1,6 +1,6 @@ Filter - +
diff --git a/src/app/lists/folder-list/folder-list.component.ts b/src/app/lists/folder-list/folder-list.component.ts index d5c08e4dd..3b344f1c4 100644 --- a/src/app/lists/folder-list/folder-list.component.ts +++ b/src/app/lists/folder-list/folder-list.component.ts @@ -1,4 +1,4 @@ -import { AfterViewInit, Component, OnInit, ViewChild, ChangeDetectorRef } from '@angular/core'; +import { AfterViewInit, Component, OnInit, ViewChild, ChangeDetectorRef, OnDestroy } from '@angular/core'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; import { MatTable, MatTableDataSource } from '@angular/material/table'; @@ -7,18 +7,19 @@ import Folder from '../../folder'; import { SystemConfigService } from '../../services/system-config.service'; import { FilterService } from 'src/app/services/filter.service'; import { StType } from 'src/app/type'; +import { MatInput } from '@angular/material/input'; @Component({ selector: 'app-folder-list', templateUrl: './folder-list.component.html', styleUrls: ['./folder-list.component.scss'] }) -export class FolderListComponent implements AfterViewInit, OnInit { +export class FolderListComponent implements AfterViewInit, OnInit, OnDestroy { @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; @ViewChild(MatTable) table: MatTable; + @ViewChild(MatInput) input: MatInput; dataSource: MatTableDataSource; - filterValue: string = ""; /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */ displayedColumns = ['id', 'label', 'path', 'state']; @@ -53,8 +54,11 @@ export class FolderListComponent implements AfterViewInit, OnInit { this.table.dataSource = this.dataSource; const changeText = (text: string) => { + if (!text) + return; + this.dataSource.filter = text.trim().toLowerCase(); - this.filterValue = text; + this.input.value = text; this.cdr.detectChanges(); } @@ -70,4 +74,6 @@ export class FolderListComponent implements AfterViewInit, OnInit { } }); } + + ngOnDestroy() { } } \ No newline at end of file diff --git a/src/app/services/filter.service.ts b/src/app/services/filter.service.ts index d66da853b..a30fe9a42 100644 --- a/src/app/services/filter.service.ts +++ b/src/app/services/filter.service.ts @@ -1,29 +1,26 @@ import { Injectable } from '@angular/core'; import { StType } from '../type'; -import { BehaviorSubject } from 'rxjs'; - -@Injectable({ - providedIn: 'root' -}) +import { Subject } from 'rxjs'; export interface FilterInput { type: StType; text: string } +@Injectable({ + providedIn: 'root' +}) export class FilterService { previousInputs = new Map( [ [StType.Folder, ""], [StType.Device, ""], ] - ) constructor() { } - private filterChangeSource = new BehaviorSubject({ type: StType.Folder, text: "" }); - + private filterChangeSource = new Subject(); filterChanged$ = this.filterChangeSource.asObservable(); changeFilter(input: FilterInput) {