From f725752f3201b52645c6360cddbad5a6e5d2b45e Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Tue, 14 Nov 2023 12:33:29 +0100 Subject: [PATCH] #12168 fixed filter in service tree genealogy --- .../include/javascript/tree/TreeController.js | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index 4f850e32d5..06274600ed 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -1561,27 +1561,21 @@ var TreeController = { * Filter the tree based on a search criterion */ function _filterItems(rawTree, searched) { - console.log(rawTree); const ancestors = []; const father = []; const newTree = []; + const tmpTree = []; rawTree.map((raw, index) => { if (raw.type === "services") { if (raw.servicesChildren.length !== 0) { // search at parent level - let findedPadre = raw.description.indexOf(searched); + let descr = raw.description.toLowerCase(); + let sear = searched.toLowerCase(); + let findedPadre = descr.indexOf(sear); if (findedPadre === -1) { - // search for children - raw.servicesChildren.map(child => { - let finded = child.description.indexOf(searched); - if (finded === 0) { - //we keep the father of the child that contains it - ancestors.push(child.ancestor); - } else if (findedPadre === -1 && finded === -1) { - //we save the father - father.push(raw.id); - } - }); + father.push(raw.id); + } else if (findedPadre >= 0) { + ancestors.push(raw.id); } else { //we mark the father as found controller.finded = 1; @@ -1607,9 +1601,16 @@ var TreeController = { if (father.length >= 1) { let filterfather = [...new Set(father)]; - const newTree = rawTree.filter( - item => !filterfather.includes(item.id) - ); + + filterfather.map(father => { + tmpTree.push(rawTree.filter(raw => raw.id == father)); + }); + + let tree = [...new Set(tmpTree)]; + tree.map(item => { + let tmpItem = item[0]; + newTree.push(tmpItem); + }); return newTree; }