Reports ported to ReactJS and Knex
Note that the interface for the custom JS code inside a report template has changed. It now offers promise-based interface and exposes knex.
This commit is contained in:
parent
6d95fa515e
commit
d63eed9ca9
27 changed files with 649 additions and 953 deletions
26
routes/reports.js
Normal file
26
routes/reports.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
'use strict';
|
||||
|
||||
const passport = require('../lib/passport');
|
||||
const _ = require('../lib/translate')._;
|
||||
const reports = require('../models/reports');
|
||||
const fileHelpers = require('../lib/file-helpers');
|
||||
|
||||
const router = require('../lib/router-async').create();
|
||||
|
||||
router.getAsync('/download/:id', passport.loggedIn, async (req, res) => {
|
||||
const report = await reports.getByIdWithTemplate(req.params.id);
|
||||
|
||||
if (report.state == reports.ReportState.FINISHED) {
|
||||
const headers = {
|
||||
'Content-Disposition': 'attachment;filename=' + fileHelpers.nameToFileName(report.name) + '.csv',
|
||||
'Content-Type': report.mime_type
|
||||
};
|
||||
|
||||
res.sendFile(fileHelpers.getReportContentFile(report), {headers: headers});
|
||||
|
||||
} else {
|
||||
return res.status(404).send(_('Report not found'));
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
Loading…
Add table
Add a link
Reference in a new issue