From e2024f250f844a286154dca4cc359d4b7f7a5de3 Mon Sep 17 00:00:00 2001 From: Miguel Martin Rojas Date: Wed, 27 Jun 2018 18:35:03 +0200 Subject: [PATCH] TSK-601 Bug Fix tree component filtering --- web/src/app/shared/tree/tree.component.ts | 30 ++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/web/src/app/shared/tree/tree.component.ts b/web/src/app/shared/tree/tree.component.ts index 9187961d0..fcac152fa 100644 --- a/web/src/app/shared/tree/tree.component.ts +++ b/web/src/app/shared/tree/tree.component.ts @@ -64,17 +64,13 @@ export class TaskanaTreeComponent implements OnInit, AfterViewChecked { this.unSelectActiveNode(); } - if (this.filterTextOld !== this.filterText) { - this.filterTextOld = this.filterText; - this.filterNodes(this.filterText); - this.manageTreeState(); - } - if (this.filterIconOld !== this.filterIcon) { + if (this.filterTextOld !== this.filterText || + this.filterIconOld !== this.filterIcon) { this.filterIconOld = this.filterIcon; - this.filterNodes(this.filterIcon); + this.filterTextOld = this.filterText; + this.filterNodes(this.filterText ? this.filterText : '', this.filterIcon); this.manageTreeState(); } - } onActivate(treeNode: any) { @@ -118,20 +114,26 @@ export class TaskanaTreeComponent implements OnInit, AfterViewChecked { this.expandParent(node.parent); } - private filterNodes(text) { + private filterNodes(text, iconText) { this.tree.treeModel.filterNodes((node) => { - return (node.data.name.toUpperCase().includes(text.toUpperCase()) - || node.data.key.toUpperCase().includes(text.toUpperCase()) - || node.data.category.toUpperCase().includes(text.toUpperCase())); + return this.checkNameAndKey(node, text) && + this.checkIcon(node, iconText); }); } + private checkNameAndKey(node: any, text: string): boolean { + return (node.data.name.toUpperCase().includes(text.toUpperCase()) + || node.data.key.toUpperCase().includes(text.toUpperCase())) + } + private checkIcon(node: any, iconText: string): boolean { + return (node.data.category.toUpperCase() === iconText.toUpperCase() + || iconText === '') + } + private manageTreeState() { if (this.filterText === '') { this.tree.treeModel.collapseAll(); } } - } -