forked from external-repos/pa11y-dashboard
Add CSV download for results
This commit is contained in:
1
app.js
1
app.js
@@ -56,6 +56,7 @@ function initApp (config, callback) {
|
||||
require('./route/task/index')(app);
|
||||
require('./route/task/delete')(app);
|
||||
require('./route/result/index')(app);
|
||||
require('./route/result/download')(app);
|
||||
|
||||
// Error handling
|
||||
app.express.get('*', function (req, res) {
|
||||
|
42
route/result/download.js
Normal file
42
route/result/download.js
Normal file
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
var moment = require('moment');
|
||||
|
||||
module.exports = route;
|
||||
|
||||
// Route definition
|
||||
function route (app) {
|
||||
|
||||
app.express.get('/:id/:rid.csv', function (req, res, next) {
|
||||
app.webservice.task(req.params.id).get({}, function (err, task) {
|
||||
if (err) {
|
||||
return next();
|
||||
}
|
||||
app.webservice
|
||||
.task(req.params.id)
|
||||
.result(req.params.rid)
|
||||
.get({full: true}, function (err, result) {
|
||||
if (err) {
|
||||
return next();
|
||||
}
|
||||
var rows = ['"code", "message", "type"'];
|
||||
result.results.forEach(function (msg) {
|
||||
rows.push([
|
||||
JSON.stringify(msg.code),
|
||||
JSON.stringify(msg.message),
|
||||
JSON.stringify(msg.type)
|
||||
].join(', '));
|
||||
});
|
||||
res.attachment([
|
||||
'pa11y--',
|
||||
task.url.replace(/^https?:\/\//i, '').replace(/\/$/, '').replace(/[^a-z0-9\.\-\_]+/gi, '-') + '--',
|
||||
task.standard.toLowerCase() + '--',
|
||||
moment(result.date).format('YYYY-MM-DD'),
|
||||
'.csv'
|
||||
].join(''));
|
||||
res.send(rows.join('\n'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
@@ -87,7 +87,7 @@
|
||||
<div class="row">
|
||||
<!-- ########### Functionality to be done ############## -->
|
||||
<div class="col-md-12 col-sm-6 col-xs-12">
|
||||
<a class="btn-full-width btn btn-default">Download CSV <span class="glyphicon glyphicon-download"></span></a>
|
||||
<a href="{{mainResult.hrefCsv}}" class="btn-full-width btn btn-default">Download CSV <span class="glyphicon glyphicon-download"></span></a>
|
||||
</div>
|
||||
<!-- ##################### End ######################## -->
|
||||
<div class="col-md-12 col-sm-6 col-xs-12">
|
||||
|
Reference in New Issue
Block a user