Files
old-confighub/web/client/confighub.js
Edin Dazdarevic 701f0844a6 bunch of stuff
2015-05-28 17:06:59 +02:00

93 lines
2.1 KiB
JavaScript

// pages
// / => home
// /:machineName => machineDetails
// .
Machines = new Mongo.Collection("machines");
Router.route('/', function() {
this.render('Home')
});
Router.route('machine/:machineId', function() {
this.render('machinePage', {
data: function() {
return Machines.findOne({
machineId: this.params.machineId
});
}
});
});
Router.route('/machine/:machineId/config/:configId', function() {
this.render('configPage', {
data: function() {
// var config = Machines.findOne({
// // "machineId": this.params.machineId,
// "configurations._id": this.params.configId
// }, {
// 'configurations.$': 1
// });
var machine = Machines.findOne({
machineId: this.params.machineId
});
if (machine) {
var config;
for (var i = 0; i < machine.configurations.length; i++) {
if (machine.configurations[i]._id === this.params.configId) {
config = machine.configurations[i];
break;
}
}
return {
machine: machine,
config: config
};
}
// return config;
}
});
});
// this.render('Post', {
// // we don't really need this since we set the data context for the
// // the entire layout above. But this demonstrates how you can set
// // a new data context for each specific region.
// data: function () { return Posts.findOne({_id: this.params._id})
// });
if (Meteor.isServer) {
Meteor.startup(function() {
// code to run on server at startup
// Global API configuration
Restivus.configure({
prettyJson: true
});
Restivus.addRoute('machines', {
authRequired: false
}, {
get: function() {
var allMaMachines = Machines.find({});
return {
data: allMaMachines
};
// var post = Posts.findOne(this.urlParams.id);
// if (post) {
// return {status: 'success', data: post};
// }
// return {
// statusCode: 404,
// body: {status: 'fail', message: 'Post not found'}
// };
}
});
});
}