Merge with master
gitea/salix/test This commit looks good
Details
gitea/salix/test This commit looks good
Details
This commit is contained in:
commit
3efc1e766e
|
@ -1,28 +1,24 @@
|
||||||
|
|
||||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('getLeaves', {
|
Self.remoteMethod('getLeaves', {
|
||||||
description: 'Returns the first shipped and landed possible for params',
|
description: 'Returns the nodes for a zone',
|
||||||
accepts: [{
|
accepts: [
|
||||||
|
{
|
||||||
arg: 'zoneFk',
|
arg: 'zoneFk',
|
||||||
type: 'Number',
|
type: 'Number',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
arg: 'parentFk',
|
arg: 'parentFk',
|
||||||
type: 'Number',
|
type: 'Number',
|
||||||
default: 1,
|
description: 'Get the children of the specified father',
|
||||||
required: false,
|
}, {
|
||||||
},
|
arg: 'search',
|
||||||
{
|
type: 'String',
|
||||||
arg: 'filter',
|
description: 'Filter nodes whose name starts with',
|
||||||
type: 'Object',
|
}
|
||||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
],
|
||||||
http: {source: 'query'}
|
|
||||||
}],
|
|
||||||
returns: {
|
returns: {
|
||||||
type: ['object'],
|
type: ['Object'],
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
|
@ -31,125 +27,30 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getLeaves = async(zoneFk, parentFk = null, filter) => {
|
Self.getLeaves = async(zoneFk, parentFk = null, search) => {
|
||||||
let conn = Self.dataSource.connector;
|
let [res] = await Self.rawSql(
|
||||||
let stmts = [];
|
`CALL zoneGeo_getLeaves(?, ?, ?)`,
|
||||||
|
[zoneFk, parentFk, search]
|
||||||
|
);
|
||||||
|
|
||||||
stmts.push(`DROP TEMPORARY TABLE IF EXISTS tmp.checkedChilds`);
|
let map = new Map();
|
||||||
stmts.push(new ParameterizedSQL(
|
for (let node of res) {
|
||||||
`CREATE TEMPORARY TABLE tmp.checkedChilds (
|
if (!map.has(node.parentFk))
|
||||||
id INT,
|
map.set(node.parentFk, []);
|
||||||
name VARCHAR(100),
|
map.get(node.parentFk).push(node);
|
||||||
lft INT,
|
|
||||||
rgt INT,
|
|
||||||
depth BIGINT(22),
|
|
||||||
sons DECIMAL(10, 0),
|
|
||||||
isIncluded TINYINT
|
|
||||||
) ENGINE = MEMORY`));
|
|
||||||
|
|
||||||
if (!parentFk) {
|
|
||||||
stmts.push(new ParameterizedSQL(
|
|
||||||
`INSERT INTO tmp.checkedChilds
|
|
||||||
SELECT
|
|
||||||
zg.id,
|
|
||||||
zg.name,
|
|
||||||
zg.lft,
|
|
||||||
zg.rgt,
|
|
||||||
zg.depth,
|
|
||||||
zg.sons,
|
|
||||||
zi.isIncluded
|
|
||||||
FROM zoneGeo zg
|
|
||||||
JOIN zoneIncluded zi ON zi.geoFk = zg.id
|
|
||||||
AND zoneFk = ?`, [zoneFk]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let stmt = new ParameterizedSQL(
|
function setLeaves(nodes) {
|
||||||
`SELECT * FROM (
|
if (!nodes) return;
|
||||||
SELECT
|
for (let node of nodes) {
|
||||||
zg.id,
|
node.childs = map.get(node.id);
|
||||||
zg.name,
|
setLeaves(node.childs);
|
||||||
zg.lft,
|
|
||||||
zg.rgt,
|
|
||||||
zg.depth,
|
|
||||||
zg.sons,
|
|
||||||
IF(ch.id = zg.id, isIncluded, null) selected
|
|
||||||
FROM zoneGeo zg
|
|
||||||
JOIN tmp.checkedChilds ch
|
|
||||||
ON zg.lft <= ch.lft AND zg.rgt >= ch.rgt
|
|
||||||
UNION ALL
|
|
||||||
SELECT
|
|
||||||
zg.id,
|
|
||||||
zg.name,
|
|
||||||
zg.lft,
|
|
||||||
zg.rgt,
|
|
||||||
zg.depth,
|
|
||||||
zg.sons,
|
|
||||||
zi.isIncluded AS selected
|
|
||||||
FROM zoneGeo zg
|
|
||||||
LEFT JOIN zoneIncluded zi ON zi.geoFk = zg.id
|
|
||||||
AND zi.zoneFk = ?
|
|
||||||
WHERE (? IS NULL AND zg.parentFk IS NULL)
|
|
||||||
OR (? IS NOT NULL AND zg.parentFk = ?)) AS nst`,
|
|
||||||
[zoneFk, parentFk, parentFk, parentFk]);
|
|
||||||
|
|
||||||
// Get nodes from depth greather than Origin
|
|
||||||
stmt.merge(conn.makeSuffix(filter));
|
|
||||||
stmt.merge('GROUP BY nst.id');
|
|
||||||
|
|
||||||
const resultIndex = stmts.push(stmt) - 1;
|
|
||||||
|
|
||||||
const sql = ParameterizedSQL.join(stmts, ';');
|
|
||||||
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 === minorDepth;
|
|
||||||
});
|
|
||||||
const leaves = Object.assign([], sortNodes(parentNodes));
|
|
||||||
|
|
||||||
nestLeaves(leaves);
|
|
||||||
|
|
||||||
function nestLeaves(elements) {
|
|
||||||
elements.forEach(element => {
|
|
||||||
let childs = Object.assign([], getLeaves(element));
|
|
||||||
if (childs.length > 0) {
|
|
||||||
element.childs = childs;
|
|
||||||
nestLeaves(element.childs);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLeaves(parent) {
|
let leaves = map.get(parentFk);
|
||||||
let elements = nodes.filter(element => {
|
setLeaves(leaves);
|
||||||
return element.lft > parent.lft && element.rgt < parent.rgt
|
|
||||||
&& element.depth === parent.depth + 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
return sortNodes(elements);
|
|
||||||
}
|
|
||||||
|
|
||||||
return leaves;
|
return leaves;
|
||||||
};
|
};
|
||||||
|
|
||||||
function sortNodes(nodes) {
|
|
||||||
return nodes.sort((a, b) => {
|
|
||||||
if (b.selected !== a.selected) {
|
|
||||||
if (a.selected == null)
|
|
||||||
return 1;
|
|
||||||
if (b.selected == null)
|
|
||||||
return -1;
|
|
||||||
return b.selected - a.selected;
|
|
||||||
}
|
|
||||||
|
|
||||||
return a.name.localeCompare(b.name);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,22 +2,25 @@
|
||||||
vn-id="model"
|
vn-id="model"
|
||||||
url="/agency/api/ZoneGeos/getLeaves"
|
url="/agency/api/ZoneGeos/getLeaves"
|
||||||
filter="::$ctrl.filter"
|
filter="::$ctrl.filter"
|
||||||
params="{zoneFk: $ctrl.$stateParams.id}" auto-load="false">
|
params="{zoneFk: $ctrl.$stateParams.id}"
|
||||||
|
auto-load="false">
|
||||||
</vn-crud-model>
|
</vn-crud-model>
|
||||||
<div class="main-with-right-menu">
|
<div class="main-with-right-menu">
|
||||||
<vn-card compact pad-large>
|
<vn-card compact pad-large>
|
||||||
<vn-searchbar
|
<vn-searchbar
|
||||||
model="model"
|
on-search="$ctrl.onSearch($params)"
|
||||||
expr-builder="$ctrl.exprBuilder(param, value)"
|
|
||||||
on-search="$ctrl.onSearch()"
|
|
||||||
vn-focus>
|
vn-focus>
|
||||||
</vn-searchbar>
|
</vn-searchbar>
|
||||||
<vn-treeview vn-id="treeview" model="model" acl-role="deliveryBoss"
|
<vn-treeview
|
||||||
|
vn-id="treeview"
|
||||||
|
model="model"
|
||||||
|
acl-role="deliveryBoss"
|
||||||
on-selection="$ctrl.onSelection(item, value)"
|
on-selection="$ctrl.onSelection(item, value)"
|
||||||
selectable="true">
|
selectable="true">
|
||||||
</vn-treeview>
|
</vn-treeview>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
<vn-side-menu side="right">
|
<vn-side-menu side="right">
|
||||||
<vn-zone-location-calendar zone="::$ctrl.zone"></vn-zone-location-calendar>
|
<vn-zone-location-calendar zone="::$ctrl.zone">
|
||||||
|
</vn-zone-location-calendar>
|
||||||
</vn-side-menu>
|
</vn-side-menu>
|
||||||
</div>
|
</div>
|
|
@ -1,18 +1,17 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
|
|
||||||
class Controller {
|
class Controller {
|
||||||
constructor($scope, $http, $stateParams) {
|
constructor($, $http, $stateParams) {
|
||||||
this.$stateParams = $stateParams;
|
this.$stateParams = $stateParams;
|
||||||
this.$scope = $scope;
|
this.$ = $;
|
||||||
this.$http = $http;
|
this.$http = $http;
|
||||||
this.searchValue = '';
|
this.searchValue = '';
|
||||||
this.filter = {};
|
this.filter = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
onSearch() {
|
onSearch(params) {
|
||||||
this.$scope.$applyAsync(() => {
|
this.$.model.applyFilter(null, params);
|
||||||
this.$scope.treeview.refresh();
|
this.$.$applyAsync(() => this.$.treeview.refresh());
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exprBuilder(param, value) {
|
exprBuilder(param, value) {
|
||||||
|
|
Loading…
Reference in New Issue