Export with arbitrary date ranges to satisfy the users

This commit is contained in:
R. Tyler Croy 2018-10-27 14:33:12 -07:00
parent b319ae9eaf
commit 5fa6626c1f
No known key found for this signature in database
GPG Key ID: 1426C7DC3F51E16F
3 changed files with 23 additions and 39 deletions

View File

@ -22,19 +22,6 @@ export default (app) => {
const types : Array<Object> = await app.service('types').find();
const isAdmin : boolean = (grants.filter(g => g != '*').length > 0);
const months = [];
const today = new Date();
/*
* TODO: In the future this come from the first_Type table
*/
const firstDate = new Date('2018-09-01');
const nextDate = firstDate;
do {
nextDate.setUTCMonth(nextDate.getUTCMonth() + 1);
months.push(`${nextDate.getUTCFullYear()}-${nextDate.getUTCMonth()}-01`);
} while (nextDate < today);
app.service('events')
.find({
query: query,
@ -49,7 +36,6 @@ export default (app) => {
isAdmin: isAdmin,
grants: grants,
types: types,
months: months,
}))
.catch(next);
});

View File

@ -7,25 +7,21 @@ import authentication from '@feathersjs/authentication';
import cookieParser from 'cookie-parser';
export default (app) => {
app.get('/export/:type',
app.post('/export',
cookieParser(),
authentication.express.authenticate('jwt'),
(req, res, next) => {
const startDate = req.query.startDate;
const endDate = new Date(startDate)
endDate.setUTCMonth(endDate.getUTCMonth() + 1)
app.service('/events/bulk')
.find({
query: {
type: req.params.type,
startDate: startDate,
endDate: endDate,
type: req.body.type,
startDate: req.body.startDate,
endDate: req.body.endDate,
},
user: (req as any).user,
})
.then((result) => {
res.setHeader('Content-Disposition', `attachment; filename=${req.params.type}-${req.query.startDate}.json`);
res.setHeader('Content-Disposition', `attachment; filename=${req.body.type}-${req.body.startDate}.json`);
res.setHeader('Content-Type', 'application/json');
res.send(result);
res.end();

View File

@ -23,22 +23,24 @@ html(lang="en")
.container-fluid.text-light
if types.length > 0
h3 Export
table.table-dark.table.table-striped.table-borderd.table-hover
tr
th(scope='col').text-center Type
th(scope='col').text-center Month
th(scope='col')
tr
td.text-center
select(id='export-type', name='type')
each t in types
option(value=t.type) #{t.type}
td.text-center
select(id='export-date', name='startDate')
each month in months.reverse()
option(value='#{month}') #{month}
td.text-center
input(type='submit', onclick='return exportType()', value='Export')
form(action='/export', method='POST')
table.table-dark.table.table-striped.table-borderd.table-hover
tr
th(scope='col').text-center Type
th(scope='col').text-center Range Start
th(scope='col').text-center Range End
th(scope='col')
tr
td.text-center
select(id='export-type', name='type')
each t in types
option(value=t.type) #{t.type}
td.text-center
input(name='startDate', placeholder='2018-10-01')
td.text-center
input(name='endDate', placeholder='2018-10-15')
td.text-center
input(type='submit', value='Export')
.container-fluid.text-light
div.float-right.strong