Skip to content
This repository has been archived by the owner on Aug 20, 2020. It is now read-only.

Commit

Permalink
Button for Shawna
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Hobden committed Mar 20, 2016
1 parent c9df5a2 commit 7728f9e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/routers/api/session.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var middleware = require("../../middleware"),
alert = require("../../alert"),
communication = require("../../communication"),
csv_stringify = require("csv-stringify"),
Promise = require('bluebird');

module.exports = function (db, redis) {
Expand Down Expand Up @@ -177,6 +178,40 @@ module.exports = function (db, redis) {
});
});

router.route("/:id/emergencyinfo")
.get(middleware.admin, function (req, res) {
db.Session.findOne({
where: { id: req.params.id },
attributes: ["id"],
include: [{
model: db.Member,
attributes: ["name", "medicalNumber", "contactName", "contactPhone", "allergies", "conditions"],
}],
order: ["name"]
}).then(function (session) {
var members = [];
for (var i=0; i < session.Members.length; i++) {
members.push(session.Members[i].toJSON());
}
return new Promise(function (resolve, reject) {
csv_stringify(members, { header: true, escape: true }, function (err, out) {
if (err) {
return reject(err);
} else {
return resolve(out);
}
});
});
}).then(function (data) {
res.contentType("text/csv");
res.setHeader('Content-disposition', 'attachment; filename=members.csv');
res.send(data);
}).catch(function (error) {
console.log(error);
res.status(401).json({ error: error.message });
});
});

router.route("/:id/remove/:member")
.get(function (req, res) {
Promise.join(
Expand Down
5 changes: 4 additions & 1 deletion views/workshops/id.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
<div class="col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{{datetime start}}-{{time end}} @ {{venue}}</span>
<h3 class="panel-title">
{{datetime start}}-{{time end}} @ {{venue}}
<a class="btn btn-xs btn-default" href="/api/session/{{id}}/emergencyinfo"><i class="fa fa-print"></i></a>
</h3>
</div>
<div class="panel-body row">
<div class="row">
Expand Down

0 comments on commit 7728f9e

Please sign in to comment.