Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/dev This commit looks good Details

This commit is contained in:
Gerard 2019-02-18 14:40:55 +01:00
commit 3101020220
2 changed files with 27 additions and 6 deletions

View File

@ -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) - 1;
if (b.name > a.name)
priority++;
return priority;
});
});
}

View File

@ -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) - 1;
if (b.name > a.name)
priority++;
return priority;
});
const leaves = Object.assign([], sortedLeaves);
nestLeaves(leaves);