From f98ca428f2b3e72fe7b660806ae9772fdeec84d8 Mon Sep 17 00:00:00 2001 From: Max Ehrlicher-Schmidt Date: Mon, 14 Dec 2020 21:36:49 +0100 Subject: [PATCH] Add filter from router param --- src/app/components/table/table.component.ts | 16 +++++++++++----- src/app/pages/dataPages/bike/bike.component.ts | 7 ++----- .../lending-station/lending-station.component.ts | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/app/components/table/table.component.ts b/src/app/components/table/table.component.ts index 7ec5b1e..645a3d0 100644 --- a/src/app/components/table/table.component.ts +++ b/src/app/components/table/table.component.ts @@ -23,6 +23,7 @@ import { ActivatedRoute } from '@angular/router'; import { Subject } from 'rxjs'; import { debounceTime } from 'rxjs/internal/operators/debounceTime'; import { SelectObjectDialogComponent } from '../select-object-dialog/select-object-dialog.component'; +import { filter } from 'rxjs/operators'; @Component({ selector: 'app-table', @@ -109,11 +110,7 @@ export class TableComponent implements AfterViewInit { public dialog: MatDialog, private activatedroute: ActivatedRoute, private cdRef: ChangeDetectorRef - ) { - /*this.filter.includesString = - this.activatedroute.snapshot.queryParamMap.get('filter') || '';*/ - //TODO: add filter from url - } + ) {} ngOnInit() { this.addColumnPropertiesFromGQLSchemaToColumnInfo(); @@ -127,6 +124,15 @@ export class TableComponent implements AfterViewInit { ); this.resetFilters(); + + const routeFilter = this.activatedroute.snapshot.queryParams; + for (const filterName of Object.keys(routeFilter)) { + if (this.filters.columnFilters[filterName]) { + this.filters.columnFilters[filterName].value = routeFilter[filterName]; + this.filters.columnFilters[filterName].isSet = true; + this.filters.columnFilters[filterName].options.exact = true; + } + } } ngAfterViewInit(): void { diff --git a/src/app/pages/dataPages/bike/bike.component.ts b/src/app/pages/dataPages/bike/bike.component.ts index 145c3be..b98d408 100644 --- a/src/app/pages/dataPages/bike/bike.component.ts +++ b/src/app/pages/dataPages/bike/bike.component.ts @@ -270,9 +270,6 @@ export class BikeComponent implements OnInit { ); }, linkToTable: (element) => '/table/equipments', - linkToTableParams: (bike) => { - return { filter: bike.name }; - }, propertyNameOfUpdateInput: 'equipmentIds', }, { @@ -291,7 +288,7 @@ export class BikeComponent implements OnInit { editableReferences: false, linkToTable: () => '/table/timeFrames', linkToTableParams: (bike) => { - return { filter: bike.name }; + return { "cargoBike.name": bike.name}; }, }, { @@ -324,7 +321,7 @@ export class BikeComponent implements OnInit { editableReferences: false, linkToTable: () => '/table/engagements', linkToTableParams: (bike) => { - return { filter: bike.name }; + return { "cargoBike.name": bike.name}; }, }, ]; diff --git a/src/app/pages/dataPages/lending-station/lending-station.component.ts b/src/app/pages/dataPages/lending-station/lending-station.component.ts index a0eb8c4..4ba7477 100644 --- a/src/app/pages/dataPages/lending-station/lending-station.component.ts +++ b/src/app/pages/dataPages/lending-station/lending-station.component.ts @@ -184,7 +184,7 @@ export class LendingStationComponent implements OnInit { editableReferences: false, linkToTable: () => '/table/timeFrames', linkToTableParams: (lendingStation) => { - return { filter: lendingStation.name }; + return { "lendingStation.name": lendingStation.name}; }, }, ];