From e4ef8f59a730763efc1314f44be1be83ff8ee8bc Mon Sep 17 00:00:00 2001 From: Max Ehrlicher-Schmidt Date: Thu, 19 Nov 2020 01:07:50 +0100 Subject: [PATCH] Add unsaved rows filter --- .../pages/tables/bikes/bikes.component.html | 16 ++++++- src/app/pages/tables/bikes/bikes.component.ts | 42 +++++++++++++++++-- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/app/pages/tables/bikes/bikes.component.html b/src/app/pages/tables/bikes/bikes.component.html index 73d3047..4af4d67 100644 --- a/src/app/pages/tables/bikes/bikes.component.html +++ b/src/app/pages/tables/bikes/bikes.component.html @@ -30,11 +30,25 @@ Filter + + + nur ungespeicherte Elemente anzeigen + { + const a = !filter.onlyUnsaved || data.newObject || data.isLockedByMe; + const b = + !filter.includesString || + Object.keys(data).some( + (k) => + data[k] != null && + data[k] + .toString() + .toLowerCase() + .includes(filter.includesString.toLowerCase()) + ); + return a && b; + }; + this.columnInfo.forEach((column) => this.displayedColumns.push(column.name) ); @@ -300,6 +316,16 @@ export class BikesComponent { this.bikesService.lockBike({ id: row.id }); } + countUnsavedRows():number { + let unsavedCount = 0; + for(const row of this.data.data) { + if (row.isLockedByMe || row.newObject) { + unsavedCount++; + } + } + return unsavedCount; + } + save(row: CargoBikeResult) { const deepenRow = this.schemaService.filterObject( this.tableDataGQLUpdateInputType, @@ -354,12 +380,20 @@ export class BikesComponent { : this.data.data.forEach((row) => this.selection.select(row)); } + showOnlyUnsavedElements(value: boolean) { + this.filter.onlyUnsaved = value; + this.applyFilter(); + } + applyFilter() { - this.data.filter = this.filterValue.trim().toLowerCase(); + this.data.filter = ({ + ...this.filter, + includesString: this.filter.includesString.trim().toLowerCase(), + } as unknown) as string; } resetFilter() { - this.filterValue = ''; + this.filter = this.initialFilter; this.applyFilter(); }