Merge pull request '4860-route.index_downloadZip' (!1259) from 4860-route.index_downloadZip into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #1259 Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
commit
2c9445293a
|
@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
## [2304.01] - 2023-02-09
|
||||
|
||||
### Added
|
||||
- (Rutas) Al descargar varias facturas se comprime en un zip
|
||||
- (Trabajadores -> Nuevo trabajador) Nueva sección
|
||||
|
||||
### 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/driverRouteEmail')(Self);
|
||||
require('../methods/route/sendSms')(Self);
|
||||
require('../methods/route/downloadZip')(Self);
|
||||
|
||||
Self.validate('kmStart', validateDistance, {
|
||||
message: 'Distance must be lesser than 1000'
|
||||
|
|
|
@ -34,12 +34,22 @@ export default class Controller extends Section {
|
|||
}
|
||||
|
||||
showRouteReport() {
|
||||
const routes = [];
|
||||
const routesIds = [];
|
||||
for (let route of this.checked)
|
||||
routes.push(route.id);
|
||||
const routesId = routes.join(',');
|
||||
routesIds.push(route.id);
|
||||
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() {
|
||||
|
|
|
@ -44,17 +44,15 @@ describe('Component vnRouteIndex', () => {
|
|||
|
||||
describe('showRouteReport()', () => {
|
||||
it('should call to the vnReport show method', () => {
|
||||
controller.vnReport.show = jest.fn();
|
||||
jest.spyOn(window, 'open').mockReturnThis();
|
||||
|
||||
const data = controller.$.model.data;
|
||||
data[0].checked = true;
|
||||
data[2].checked = true;
|
||||
|
||||
const routeIds = '1,3';
|
||||
|
||||
controller.showRouteReport();
|
||||
|
||||
expect(controller.vnReport.show).toHaveBeenCalledWith(`Routes/${routeIds}/driver-route-pdf`);
|
||||
expect(window.open).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"module": "shelving",
|
||||
"name": "Shelvings",
|
||||
"icon" : "contact_support",
|
||||
"icon" : "icon-inventory",
|
||||
"dependencies": ["worker"],
|
||||
"validations" : true,
|
||||
"menus": {
|
||||
"main": [
|
||||
{"state": "shelving.index", "icon": "contact_support"}
|
||||
{"state": "shelving.index", "icon": "icon-inventory"}
|
||||
],
|
||||
"card": [
|
||||
{"state": "shelving.card.basicData", "icon": "settings"},
|
||||
|
|
Loading…
Reference in New Issue