Merge branch 'dev' into test
This commit is contained in:
parent
e52be911cf
commit
059a72a719
|
@ -8,7 +8,7 @@ module.exports = Self => {
|
|||
{
|
||||
arg: 'id',
|
||||
type: 'Number',
|
||||
description: 'Document id',
|
||||
description: 'The document id',
|
||||
http: {source: 'path'}
|
||||
}
|
||||
],
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
|
||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('getLeaves', {
|
||||
description: 'Returns the first shipped and landed possible for params',
|
||||
accepts: [{
|
||||
arg: 'zoneFk',
|
||||
type: 'Number',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'parentFk',
|
||||
type: 'Number',
|
||||
default: 1,
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
arg: 'filter',
|
||||
type: 'Object',
|
||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
||||
http: {source: 'query'}
|
||||
}],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/getLeaves`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getLeaves = async(zoneFk, parentFk = null, filter) => {
|
||||
let conn = Self.dataSource.connector;
|
||||
let stmts = [];
|
||||
|
||||
stmts.push(`DROP TEMPORARY TABLE IF EXISTS tmp.checkedChilds`);
|
||||
stmts.push(new ParameterizedSQL(
|
||||
`CREATE TEMPORARY TABLE tmp.checkedChilds (
|
||||
id INT,
|
||||
name VARCHAR(100),
|
||||
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(
|
||||
`SELECT * FROM (
|
||||
SELECT
|
||||
zg.id,
|
||||
zg.name,
|
||||
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 elements = nodes.filter(element => {
|
||||
return element.lft > parent.lft && element.rgt < parent.rgt
|
||||
&& element.depth === parent.depth + 1;
|
||||
});
|
||||
|
||||
return sortNodes(elements);
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
};
|
|
@ -1,57 +0,0 @@
|
|||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('getLeaves', {
|
||||
description: 'Returns the nodes for a zone',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'Number',
|
||||
http: {source: 'path'},
|
||||
required: true
|
||||
}, {
|
||||
arg: 'parentFk',
|
||||
type: 'Number',
|
||||
description: 'Get the children of the specified father',
|
||||
}, {
|
||||
arg: 'search',
|
||||
type: 'String',
|
||||
description: 'Filter nodes whose name starts with',
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: ['Object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/getLeaves`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getLeaves = async(id, parentFk = null, search) => {
|
||||
let [res] = await Self.rawSql(
|
||||
`CALL zone_getLeaves(?, ?, ?)`,
|
||||
[id, parentFk, search]
|
||||
);
|
||||
|
||||
let map = new Map();
|
||||
for (let node of res) {
|
||||
if (!map.has(node.parentFk))
|
||||
map.set(node.parentFk, []);
|
||||
map.get(node.parentFk).push(node);
|
||||
}
|
||||
|
||||
function setLeaves(nodes) {
|
||||
if (!nodes) return;
|
||||
for (let node of nodes) {
|
||||
node.childs = map.get(node.id);
|
||||
setLeaves(node.childs);
|
||||
}
|
||||
}
|
||||
|
||||
let leaves = map.get(parentFk);
|
||||
setLeaves(leaves);
|
||||
|
||||
return leaves || [];
|
||||
};
|
||||
};
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/zone-geo/getLeaves')(Self);
|
||||
};
|
|
@ -1,7 +1,6 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/zone/clone')(Self);
|
||||
require('../methods/zone/editPrices')(Self);
|
||||
require('../methods/zone/getLeaves')(Self);
|
||||
|
||||
Self.validatesPresenceOf('warehouseFk', {
|
||||
message: `Warehouse cannot be blank`
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="/api/Zones/{{$ctrl.$stateParams.id}}/getLeaves"
|
||||
auto-load="false">
|
||||
url="/agency/api/ZoneGeos/getLeaves"
|
||||
filter="::$ctrl.filter"
|
||||
params="{zoneFk: $ctrl.$stateParams.id}" auto-load="false">
|
||||
</vn-crud-model>
|
||||
<div class="main-with-right-menu">
|
||||
<vn-card compact pad-large>
|
||||
<vn-searchbar
|
||||
on-search="$ctrl.onSearch($params)"
|
||||
model="model"
|
||||
expr-builder="$ctrl.exprBuilder(param, value)"
|
||||
on-search="$ctrl.onSearch()"
|
||||
vn-focus>
|
||||
</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)"
|
||||
selectable="true">
|
||||
</vn-treeview>
|
||||
</vn-card>
|
||||
<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>
|
||||
</div>
|
|
@ -1,15 +1,18 @@
|
|||
import ngModule from '../module';
|
||||
|
||||
class Controller {
|
||||
constructor($, $http, $stateParams) {
|
||||
this.$ = $;
|
||||
this.$http = $http;
|
||||
constructor($scope, $http, $stateParams) {
|
||||
this.$stateParams = $stateParams;
|
||||
this.$scope = $scope;
|
||||
this.$http = $http;
|
||||
this.searchValue = '';
|
||||
this.filter = {};
|
||||
}
|
||||
|
||||
onSearch(params) {
|
||||
this.$.model.applyFilter(null, params);
|
||||
this.$.$applyAsync(() => this.$.treeview.refresh());
|
||||
onSearch() {
|
||||
this.$scope.$applyAsync(() => {
|
||||
this.$scope.treeview.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
exprBuilder(param, value) {
|
||||
|
|
|
@ -30,11 +30,10 @@ module.exports = Self => {
|
|||
JOIN vn.ticketState ts ON t.id = ts.ticketFk
|
||||
JOIN vn.agencyMode a ON t.agencyModeFk = a.id
|
||||
JOIN vn.warehouse w ON t.warehouseFk = w.id
|
||||
WHERE t.shipped >= CURDATE() AND t.clientFk = ?
|
||||
AND ts.alertLevel = 0 AND t.id <> ?
|
||||
WHERE t.shipped >= CURDATE() AND t.clientFk = ? AND ts.alertLevel = 0 AND t.id <> ?
|
||||
ORDER BY t.shipped
|
||||
LIMIT 5`;
|
||||
let tickets = await Self.rawSql(query, [params.clientFk, params.ticketFk]);
|
||||
return tickets;
|
||||
LIMIT 3`;
|
||||
|
||||
return Self.rawSql(query, [id, ticketId]);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -169,31 +169,6 @@ class Controller {
|
|||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets a zone from an agency
|
||||
*/
|
||||
onChangeWarehouse(warehouseId) {
|
||||
let params = {
|
||||
landed: this.ticket.landed,
|
||||
addressFk: this.ticket.addressFk,
|
||||
agencyModeFk: this.ticket.agencyModeFk,
|
||||
warehouseFk: warehouseId
|
||||
};
|
||||
|
||||
this.ticket.zoneFk = null;
|
||||
let query = `/api/Agencies/getShipped`;
|
||||
this.$http.get(query, {params}).then(res => {
|
||||
if (res.data)
|
||||
this.ticket.zoneFk = res.data.id;
|
||||
|
||||
if (!res.data) {
|
||||
this.vnApp.showMessage(
|
||||
this.$translate.instant('No delivery zone available for this parameters')
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async onStepChange() {
|
||||
if (this.isFormInvalid()) {
|
||||
return this.vnApp.showError(
|
||||
|
|
|
@ -2,4 +2,4 @@ Weekly tickets: Tickets programados
|
|||
Go to lines: Ir a lineas
|
||||
Not available: No disponible
|
||||
Payment on account...: Pago a cuenta...
|
||||
Closure: Cierre
|
||||
Closure: Cierre
|
Loading…
Reference in New Issue