From 08fa4804de7716721d7b3de5ecaae4f301fe0ef4 Mon Sep 17 00:00:00 2001 From: dtheinert <dietmar.theinert@pta.de> Date: Thu, 1 Oct 2020 12:10:12 +0200 Subject: [PATCH] [SI-2944] - correct filtering for stations --- .../set-filter/set-filter.component.spec.ts | 2 +- .../set-filter/set-filter.component.ts | 24 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.spec.ts b/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.spec.ts index b0489dff..10982954 100644 --- a/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.spec.ts +++ b/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.spec.ts @@ -243,7 +243,7 @@ describe('SetFilterComponent', () => { component['_valueGetter'] = () => 'oncle tom'; component.setItems = { oncle: { checked: true } }; const returnValue = component.doesFilterPass({} as any); - expect(returnValue).toBeFalsy(); + expect(returnValue).toBeTruthy(); }); it('should set params via agInit()', () => { diff --git a/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.ts b/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.ts index e6db9164..1c0f9bba 100644 --- a/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.ts +++ b/projects/grid-failure-information-app/src/app/shared/filters/ag-grid/set-filter/set-filter.component.ts @@ -89,8 +89,28 @@ export class SetFilterComponent implements AgFilterComponent, OnDestroy { } doesFilterPass(params: IDoesFilterPassParams): boolean { - const itemKey = this._valueGetter(params.node); - return this.setItems[itemKey || null] !== undefined && this.setItems[itemKey || null].checked; + const nodeValue = this._valueGetter(params.node); + let passed: boolean = false; + + for (let itemKey in this.setItems) { + if (isNaN(nodeValue)) { + if (itemKey === 'null') { + passed = !nodeValue || nodeValue === ''; // nodeValue is falsy or empty string + } else { + passed = !!nodeValue && nodeValue.includes(itemKey); + } + } else { + // is numeric or null + if (!nodeValue) { + passed = nodeValue === null && itemKey === 'null'; + } else { + passed = nodeValue.toString() === itemKey; + } + } + passed = passed && this.setItems[itemKey].checked; + if (passed) return passed; + } + return passed; } getModel(): any { -- GitLab