From 90092a4f48307e89342b7e5635f89b8e29e9d47b Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 20 Feb 2019 12:31:08 +0100 Subject: [PATCH] fixed treeview order --- front/core/components/icon/icon.js | 2 +- front/core/components/icon/style.scss | 1 + front/core/components/treeview/index.js | 35 +++++-------------- .../agency/back/methods/zone-geo/getLeaves.js | 27 ++++++++------ 4 files changed, 26 insertions(+), 39 deletions(-) diff --git a/front/core/components/icon/icon.js b/front/core/components/icon/icon.js index 01087b0c7..1b78f4693 100644 --- a/front/core/components/icon/icon.js +++ b/front/core/components/icon/icon.js @@ -26,7 +26,7 @@ class Icon { Icon.$inject = ['$attrs']; ngModule.component('vnIcon', { - template: '{{::$ctrl.iconContent}}', + template: '{{::$ctrl.iconContent}}', controller: Icon, bindings: { icon: '@' diff --git a/front/core/components/icon/style.scss b/front/core/components/icon/style.scss index bed29630d..07a1584e3 100644 --- a/front/core/components/icon/style.scss +++ b/front/core/components/icon/style.scss @@ -2,6 +2,7 @@ vn-icon { display: inline-block; font-size: 18pt; text-align: center; + outline: 0; & > i, & > i.material-icons { diff --git a/front/core/components/treeview/index.js b/front/core/components/treeview/index.js index a71a3a342..0737bf8cb 100644 --- a/front/core/components/treeview/index.js +++ b/front/core/components/treeview/index.js @@ -23,28 +23,6 @@ export default class Treeview extends Component { }); } - /* hasCheckedChilds(node) { - if (!node.childs) return false; - - const childs = node.childs; - for (let i = 0; i < childs.length; i++) { - if (childs[i].selected || this.hasCheckedChilds(childs[i])) - return true; - } - - return false; - } - - hasCheckedParents(node) { - if (!node.parent) return false; - - const parent = node.parent; - if (parent.selected || this.hasCheckedParents(parent)) - return true; - - return false; - } */ - onSelection(item, value) { this.emit('selection', {item, value}); } @@ -67,12 +45,15 @@ export default class Treeview extends Component { } item.childs = newData.sort((a, b) => { - let priority = (b.isIncluded - a.isIncluded) - 1; + if (b.isIncluded !== a.isIncluded) { + if (a.isIncluded == null) + return 1; + if (b.isIncluded == null) + return -1; + return b.isIncluded - a.isIncluded; + } - if (b.name > a.name) - priority++; - - return priority; + return a.name.localeCompare(b.name); }); }); } diff --git a/modules/agency/back/methods/zone-geo/getLeaves.js b/modules/agency/back/methods/zone-geo/getLeaves.js index 631286465..64bb68318 100644 --- a/modules/agency/back/methods/zone-geo/getLeaves.js +++ b/modules/agency/back/methods/zone-geo/getLeaves.js @@ -116,16 +116,7 @@ module.exports = Self => { const parentNodes = nodes.filter(element => { return element.depth === minorDepth; }); - - const sortedLeaves = parentNodes.sort((a, b) => { - let priority = (b.isIncluded - a.isIncluded) - 1; - - if (b.name > a.name) - priority++; - - return priority; - }); - const leaves = Object.assign([], sortedLeaves); + const leaves = Object.assign([], sortNodes(parentNodes)); nestLeaves(leaves); @@ -143,9 +134,23 @@ module.exports = Self => { && element.depth === parent.depth + 1; }); - return elements; + return sortNodes(elements); } return leaves; }; + + function sortNodes(nodes) { + return nodes.sort((a, b) => { + if (b.isIncluded !== a.isIncluded) { + if (a.isIncluded == null) + return 1; + if (b.isIncluded == null) + return -1; + return b.isIncluded - a.isIncluded; + } + + return a.name.localeCompare(b.name); + }); + } };