4860-route.index_downloadZip #1259
|
@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
## [2304.01] - 2023-02-09
|
## [2304.01] - 2023-02-09
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
- (Rutas) Al descargar varias facturas se comprime en un zip
|
||||||
- (Trabajadores -> Nuevo trabajador) Nueva sección
|
- (Trabajadores -> Nuevo trabajador) Nueva sección
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
const JSZip = require('jszip');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('downloadZip', {
|
||||||
|
description: 'Download a zip file with multiple routes pdfs',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The routes ids',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'string',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'string',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/downloadZip',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.downloadZip = async function(ctx, id, options) {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const myOptions = {};
|
||||||
|
const zip = new JSZip();
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const ids = id.split(',');
|
||||||
|
for (let id of ids) {
|
||||||
|
ctx.args.id = id;
|
||||||
|
const routePdf = await models.Route.driverRoutePdf(ctx, id);
|
||||||
|
const fileName = extractFileName(routePdf[2]);
|
||||||
|
const body = routePdf[0];
|
||||||
|
|
||||||
|
zip.file(fileName, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
const stream = zip.generateNodeStream({streamFiles: true});
|
||||||
|
|
||||||
|
return [stream, 'application/zip', `filename="download.zip"`];
|
||||||
|
};
|
||||||
|
|
||||||
|
function extractFileName(str) {
|
||||||
|
const matches = str.match(/"(.*?)"/);
|
||||||
|
return matches ? matches[1] : str;
|
||||||
|
}
|
||||||
|
};
|
|
@ -13,6 +13,7 @@ module.exports = Self => {
|
||||||
require('../methods/route/driverRoutePdf')(Self);
|
require('../methods/route/driverRoutePdf')(Self);
|
||||||
require('../methods/route/driverRouteEmail')(Self);
|
require('../methods/route/driverRouteEmail')(Self);
|
||||||
require('../methods/route/sendSms')(Self);
|
require('../methods/route/sendSms')(Self);
|
||||||
|
require('../methods/route/downloadZip')(Self);
|
||||||
|
|
||||||
Self.validate('kmStart', validateDistance, {
|
Self.validate('kmStart', validateDistance, {
|
||||||
message: 'Distance must be lesser than 1000'
|
message: 'Distance must be lesser than 1000'
|
||||||
|
|
|
@ -34,12 +34,22 @@ export default class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
showRouteReport() {
|
showRouteReport() {
|
||||||
const routes = [];
|
const routesIds = [];
|
||||||
for (let route of this.checked)
|
for (let route of this.checked)
|
||||||
routes.push(route.id);
|
routesIds.push(route.id);
|
||||||
const routesId = routes.join(',');
|
const stringRoutesIds = routesIds.join(',');
|
||||||
|
|
||||||
this.vnReport.show(`Routes/${routesId}/driver-route-pdf`);
|
if (this.checked.length <= 1) {
|
||||||
|
const url = `api/Routes/${stringRoutesIds}/driver-route-pdf?access_token=${this.vnToken.token}`;
|
||||||
|
window.open(url, '_blank');
|
||||||
|
} else {
|
||||||
|
const serializedParams = this.$httpParamSerializer({
|
||||||
|
access_token: this.vnToken.token,
|
||||||
|
id: stringRoutesIds
|
||||||
|
});
|
||||||
|
const url = `api/Routes/downloadZip?${serializedParams}`;
|
||||||
|
window.open(url, '_blank');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
openClonationDialog() {
|
openClonationDialog() {
|
||||||
|
|
|
@ -44,17 +44,15 @@ describe('Component vnRouteIndex', () => {
|
||||||
|
|
||||||
describe('showRouteReport()', () => {
|
describe('showRouteReport()', () => {
|
||||||
it('should call to the vnReport show method', () => {
|
it('should call to the vnReport show method', () => {
|
||||||
controller.vnReport.show = jest.fn();
|
jest.spyOn(window, 'open').mockReturnThis();
|
||||||
|
|
||||||
const data = controller.$.model.data;
|
const data = controller.$.model.data;
|
||||||
data[0].checked = true;
|
data[0].checked = true;
|
||||||
data[2].checked = true;
|
data[2].checked = true;
|
||||||
|
|
||||||
const routeIds = '1,3';
|
|
||||||
|
|
||||||
controller.showRouteReport();
|
controller.showRouteReport();
|
||||||
|
|
||||||
expect(controller.vnReport.show).toHaveBeenCalledWith(`Routes/${routeIds}/driver-route-pdf`);
|
expect(window.open).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"module": "shelving",
|
"module": "shelving",
|
||||||
"name": "Shelvings",
|
"name": "Shelvings",
|
||||||
"icon" : "contact_support",
|
"icon" : "icon-inventory",
|
||||||
"dependencies": ["worker"],
|
"dependencies": ["worker"],
|
||||||
"validations" : true,
|
"validations" : true,
|
||||||
"menus": {
|
"menus": {
|
||||||
"main": [
|
"main": [
|
||||||
{"state": "shelving.index", "icon": "contact_support"}
|
{"state": "shelving.index", "icon": "icon-inventory"}
|
||||||
],
|
],
|
||||||
"card": [
|
"card": [
|
||||||
{"state": "shelving.card.basicData", "icon": "settings"},
|
{"state": "shelving.card.basicData", "icon": "settings"},
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
"abstract": true,
|
"abstract": true,
|
||||||
"component": "vn-shelving",
|
"component": "vn-shelving",
|
||||||
"description": "Shelvings"
|
"description": "Shelvings"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "/index?q",
|
"url": "/index?q",
|
||||||
"state": "shelving.index",
|
"state": "shelving.index",
|
||||||
|
@ -32,13 +32,13 @@
|
||||||
"state": "shelving.create",
|
"state": "shelving.create",
|
||||||
"component": "vn-shelving-create",
|
"component": "vn-shelving-create",
|
||||||
"description": "New shelving"
|
"description": "New shelving"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "/:id",
|
"url": "/:id",
|
||||||
"state": "shelving.card",
|
"state": "shelving.card",
|
||||||
"abstract": true,
|
"abstract": true,
|
||||||
"component": "vn-shelving-card"
|
"component": "vn-shelving-card"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "/summary",
|
"url": "/summary",
|
||||||
"state": "shelving.card.summary",
|
"state": "shelving.card.summary",
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
"params": {
|
"params": {
|
||||||
"shelving": "$ctrl.shelving"
|
"shelving": "$ctrl.shelving"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "/basic-data",
|
"url": "/basic-data",
|
||||||
"state": "shelving.card.basicData",
|
"state": "shelving.card.basicData",
|
||||||
|
@ -56,7 +56,7 @@
|
||||||
"params": {
|
"params": {
|
||||||
"shelving": "$ctrl.shelving"
|
"shelving": "$ctrl.shelving"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url" : "/log",
|
"url" : "/log",
|
||||||
"state": "shelving.card.log",
|
"state": "shelving.card.log",
|
||||||
|
@ -64,4 +64,4 @@
|
||||||
"description": "Log"
|
"description": "Log"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue