TSK-601 Bug Fix tree component filtering

This commit is contained in:
Martin Rojas Miguel Angel 2018-06-27 18:35:03 +02:00 committed by Holger Hagen
parent 14aa61bd7c
commit baaf53ec1c
1 changed files with 16 additions and 14 deletions

View File

@ -64,17 +64,13 @@ export class TaskanaTreeComponent implements OnInit, AfterViewChecked {
this.unSelectActiveNode(); this.unSelectActiveNode();
} }
if (this.filterTextOld !== this.filterText) { if (this.filterTextOld !== this.filterText ||
this.filterTextOld = this.filterText; this.filterIconOld !== this.filterIcon) {
this.filterNodes(this.filterText);
this.manageTreeState();
}
if (this.filterIconOld !== this.filterIcon) {
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(); this.manageTreeState();
} }
} }
onActivate(treeNode: any) { onActivate(treeNode: any) {
@ -118,20 +114,26 @@ export class TaskanaTreeComponent implements OnInit, AfterViewChecked {
this.expandParent(node.parent); this.expandParent(node.parent);
} }
private filterNodes(text) { private filterNodes(text, iconText) {
this.tree.treeModel.filterNodes((node) => { this.tree.treeModel.filterNodes((node) => {
return (node.data.name.toUpperCase().includes(text.toUpperCase()) return this.checkNameAndKey(node, text) &&
|| node.data.key.toUpperCase().includes(text.toUpperCase()) this.checkIcon(node, iconText);
|| node.data.category.toUpperCase().includes(text.toUpperCase()));
}); });
} }
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() { private manageTreeState() {
if (this.filterText === '') { if (this.filterText === '') {
this.tree.treeModel.collapseAll(); this.tree.treeModel.collapseAll();
} }
} }
} }