First pass at a Hanging Protocol implementation and editor (LT-131)
This commit is contained in:
1 parent
dfcb33153f
commit
2e52d9e3c1
157 files changed
+8869
-23585
No files matched your search
Executable
+46
@@ -0,0 +1,46 @@
|
||||
Router.route('/protocol-export/:_id', function() {
|
||||
var protocolId = this.params._id;
|
||||
var protocol = HangingProtocols.findOne({
|
||||
id: protocolId
|
||||
});
|
||||
|
||||
if (!protocol) {
|
||||
this.response.writeHead(404);
|
||||
|
||||
// This will not actually respond with a 404 because of https://github.com/iron-meteor/iron-router/issues/1055
|
||||
this.response.end();
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the MongoDB _id
|
||||
delete protocol._id;
|
||||
|
||||
var protocolJSON = JSON.stringify(protocol, null, 2),
|
||||
currentDate = new Date(),
|
||||
filename = protocol.name + '-' + (currentDate.getTime().toString()) + '.json';
|
||||
|
||||
this.response.writeHead(200, {
|
||||
'Content-Type': 'application/x-download',
|
||||
'Content-Disposition': 'attachment; filename=' + filename,
|
||||
'Content-Length': protocolJSON.length
|
||||
});
|
||||
|
||||
this.response.end(protocolJSON);
|
||||
}, {
|
||||
where: 'server'
|
||||
});
|
||||
|
||||
Router.route('/protocol-import', {
|
||||
where: 'server'
|
||||
}).post(function() {
|
||||
try {
|
||||
var toImport = JSON.parse(this.request.body.protocol);
|
||||
HangingProtocols.insert(toImport);
|
||||
|
||||
this.response.writeHead(200);
|
||||
this.response.end(toImport.id);
|
||||
} catch(e) {
|
||||
this.response.writeHead(500);
|
||||
this.response.end('Failed to parse protocol JSON.');
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user