From 0ea161ff19dd7d1f4727ff36f352b9834d50e70e Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 18 Feb 2019 13:23:24 +0100 Subject: [PATCH 1/3] fixed zoneLocation search --- front/core/components/treeview/index.js | 9 ++++++- .../agency/back/methods/zone-geo/getLeaves.js | 24 +++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/front/core/components/treeview/index.js b/front/core/components/treeview/index.js index f73bf3e38..ae7489147 100644 --- a/front/core/components/treeview/index.js +++ b/front/core/components/treeview/index.js @@ -66,7 +66,14 @@ export default class Treeview extends Component { }); } - item.childs = newData.sort((a, b) => b.isIncluded - a.isIncluded); + item.childs = newData.sort((a, b) => { + let priority = b.isIncluded - a.isIncluded; + + if (b.name > a.name) + priority++; + + return priority; + }); }); } diff --git a/modules/agency/back/methods/zone-geo/getLeaves.js b/modules/agency/back/methods/zone-geo/getLeaves.js index 9f819e83a..45ee3ca8d 100644 --- a/modules/agency/back/methods/zone-geo/getLeaves.js +++ b/modules/agency/back/methods/zone-geo/getLeaves.js @@ -36,8 +36,6 @@ module.exports = Self => { let conn = Self.dataSource.connector; let stmts = []; - let geo = await Self.findById(parentFk); - stmts.push(`DROP TEMPORARY TABLE IF EXISTS tmp.checkedChilds`); stmts.push(new ParameterizedSQL( `CREATE TEMPORARY TABLE tmp.checkedChilds ( @@ -77,7 +75,9 @@ module.exports = Self => { zg.sons, IF(ch.id = zg.id, isIncluded, null) isIncluded FROM zoneGeo zg - JOIN tmp.checkedChilds ch ON zg.lft <= ch.lft AND zg.rgt >= ch.rgt + JOIN tmp.checkedChilds ch + ON zg.lft <= ch.lft AND zg.rgt >= ch.rgt + AND zg.depth > 0 UNION ALL SELECT child.id, @@ -105,12 +105,26 @@ module.exports = Self => { const result = await Self.rawStmt(sql); const nodes = result[resultIndex]; + if (nodes.length == 0) + return nodes; + // Get parent nodes + const minorDepth = nodes.reduce((a, b) => { + return b < a ? b : a; + }).depth; + const parentNodes = nodes.filter(element => { - return element.depth === geo.depth + 1; + return element.depth === minorDepth; }); - const sortedLeaves = parentNodes.sort((a, b) => b.isIncluded - a.isIncluded); + const sortedLeaves = parentNodes.sort((a, b) => { + let priority = b.isIncluded - a.isIncluded; + + if (b.name > a.name) + priority++; + + return priority; + }); const leaves = Object.assign([], sortedLeaves); nestLeaves(leaves); From 813d7368f37c77c833390725ef0d582353e2812a Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 18 Feb 2019 13:37:36 +0100 Subject: [PATCH 2/3] fixed zoneLocation order --- modules/agency/back/methods/zone-geo/getLeaves.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/agency/back/methods/zone-geo/getLeaves.js b/modules/agency/back/methods/zone-geo/getLeaves.js index 45ee3ca8d..b7061ef26 100644 --- a/modules/agency/back/methods/zone-geo/getLeaves.js +++ b/modules/agency/back/methods/zone-geo/getLeaves.js @@ -118,13 +118,14 @@ module.exports = Self => { }); const sortedLeaves = parentNodes.sort((a, b) => { - let priority = b.isIncluded - a.isIncluded; + let priority = (b.isIncluded - a.isIncluded) - 1; if (b.name > a.name) priority++; return priority; }); + console.log(sortedLeaves); const leaves = Object.assign([], sortedLeaves); nestLeaves(leaves); From 75053618a2d12f8bce296ef49b33c09f0a8477be Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 18 Feb 2019 13:39:48 +0100 Subject: [PATCH 3/3] zoneLocation order --- front/core/components/treeview/index.js | 2 +- modules/agency/back/methods/zone-geo/getLeaves.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/front/core/components/treeview/index.js b/front/core/components/treeview/index.js index ae7489147..a71a3a342 100644 --- a/front/core/components/treeview/index.js +++ b/front/core/components/treeview/index.js @@ -67,7 +67,7 @@ export default class Treeview extends Component { } item.childs = newData.sort((a, b) => { - let priority = b.isIncluded - a.isIncluded; + let priority = (b.isIncluded - a.isIncluded) - 1; if (b.name > a.name) priority++; diff --git a/modules/agency/back/methods/zone-geo/getLeaves.js b/modules/agency/back/methods/zone-geo/getLeaves.js index b7061ef26..631286465 100644 --- a/modules/agency/back/methods/zone-geo/getLeaves.js +++ b/modules/agency/back/methods/zone-geo/getLeaves.js @@ -125,7 +125,6 @@ module.exports = Self => { return priority; }); - console.log(sortedLeaves); const leaves = Object.assign([], sortedLeaves); nestLeaves(leaves);