Store last filtered value between toggling of lists

This commit is contained in:
Jesse Lucas 2020-04-02 11:50:57 -04:00
parent d76f1fe356
commit a9b6801b22
7 changed files with 39 additions and 12 deletions

View File

@ -1,4 +1,4 @@
<mat-button-toggle-group class="tui-button-toggle" name="fontStyle" aria-label="Font Style" value="{{toggleValue}}"> <mat-button-toggle-group class="tui-button-toggle" name="fontStyle" aria-label="Font Style">
<mat-button-toggle value="folders" (click)="onSelect(listType.Folder)">Folders</mat-button-toggle> <mat-button-toggle value="folders" (click)="onSelect(listType.Folder)">Folders</mat-button-toggle>
<mat-button-toggle value="devices" (click)="onSelect(listType.Device)">Devices</mat-button-toggle> <mat-button-toggle value="devices" (click)="onSelect(listType.Device)">Devices</mat-button-toggle>
</mat-button-toggle-group> </mat-button-toggle-group>

View File

@ -1,5 +1,6 @@
import { Component, EventEmitter, OnInit, Output } from '@angular/core'; import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core';
import { StType } from '../type'; import { StType } from '../type';
import { MatButtonToggleGroup } from '@angular/material/button-toggle';
@ -10,8 +11,9 @@ import { StType } from '../type';
}) })
export class ListToggleComponent implements OnInit { export class ListToggleComponent implements OnInit {
@ViewChild(MatButtonToggleGroup) group: MatButtonToggleGroup;
public listType = StType; public listType = StType;
public toggleValue: string = "folders"; // public toggleValue: string = "folders";
@Output() listTypeEvent = new EventEmitter<StType>(); @Output() listTypeEvent = new EventEmitter<StType>();
constructor() { } constructor() { }

View File

@ -30,7 +30,9 @@ export class DeviceListComponent implements AfterViewInit, OnInit {
) { }; ) { };
applyFilter(event: Event) { applyFilter(event: Event) {
// Set previous filter value
const filterValue = (event.target as HTMLInputElement).value; const filterValue = (event.target as HTMLInputElement).value;
this.filterService.previousInputs.set(StType.Device, filterValue);
this.dataSource.filter = filterValue.trim().toLowerCase(); this.dataSource.filter = filterValue.trim().toLowerCase();
} }
@ -50,13 +52,20 @@ export class DeviceListComponent implements AfterViewInit, OnInit {
this.dataSource.paginator = this.paginator; this.dataSource.paginator = this.paginator;
this.table.dataSource = this.dataSource; this.table.dataSource = this.dataSource;
const changeText = (text: string) => {
this.dataSource.filter = text.trim().toLowerCase();
this.filterValue = text;
this.cdr.detectChanges();
}
// Set previous value
changeText(this.filterService.previousInputs.get(StType.Device));
// Listen for filter changes from other components // Listen for filter changes from other components
this.filterService.filterChanged$.subscribe( this.filterService.filterChanged$.subscribe(
input => { input => {
if (input.type === StType.Device) { if (input.type === StType.Device) {
this.dataSource.filter = input.text.trim().toLowerCase(); changeText(input.text);
this.filterValue = input.text;
this.cdr.detectChanges();
} }
}); });
} }

View File

@ -32,6 +32,7 @@ export class FolderListComponent implements AfterViewInit, OnInit {
applyFilter(event: Event) { applyFilter(event: Event) {
const filterValue = (event.target as HTMLInputElement).value; const filterValue = (event.target as HTMLInputElement).value;
this.filterService.previousInputs.set(StType.Folder, filterValue);
this.dataSource.filter = filterValue.trim().toLowerCase(); this.dataSource.filter = filterValue.trim().toLowerCase();
} }
@ -51,14 +52,21 @@ export class FolderListComponent implements AfterViewInit, OnInit {
this.dataSource.paginator = this.paginator; this.dataSource.paginator = this.paginator;
this.table.dataSource = this.dataSource; this.table.dataSource = this.dataSource;
const changeText = (text: string) => {
this.dataSource.filter = text.trim().toLowerCase();
this.filterValue = text;
this.cdr.detectChanges();
}
// Set previous value
changeText(this.filterService.previousInputs.get(StType.Folder));
// Listen for filter changes from other components // Listen for filter changes from other components
this.filterService.filterChanged$ this.filterService.filterChanged$
.subscribe( .subscribe(
input => { input => {
if (input.type === StType.Folder) { if (input.type === StType.Folder) {
this.dataSource.filter = input.text.trim().toLowerCase(); changeText(input.text);
this.filterValue = input.text;
this.cdr.detectChanges();
} }
}); });
} }

View File

@ -27,10 +27,10 @@ export class StatusListComponent {
switch (input.type) { switch (input.type) {
case StType.Folder: case StType.Folder:
this.toggle.toggleValue = "folders"; this.toggle.group.value = "folders";
break; break;
case StType.Device: case StType.Device:
this.toggle.toggleValue = "devices"; this.toggle.group.value = "devices";
break; break;
} }
}); });

View File

@ -12,6 +12,13 @@ export interface FilterInput {
} }
export class FilterService { export class FilterService {
previousInputs = new Map<StType, string>(
[
[StType.Folder, ""],
[StType.Device, ""],
]
)
constructor() { } constructor() { }
@ -20,6 +27,7 @@ export class FilterService {
filterChanged$ = this.filterChangeSource.asObservable(); filterChanged$ = this.filterChangeSource.asObservable();
changeFilter(input: FilterInput) { changeFilter(input: FilterInput) {
this.previousInputs.set(input.type, input.text)
this.filterChangeSource.next(input); this.filterChangeSource.next(input);
} }
} }

View File

@ -88,7 +88,7 @@ html, body {
a { a {
text-decoration: underline; text-decoration: underline;
color: mat-color($tech-ui-primary); color: #000000;
} }
.tui-card { .tui-card {