timers3000
Version:
Provides a graphical interface in your browser to create and manage incremental timers for your daily tasks.
92 lines (81 loc) • 3.28 kB
JavaScript
var timersController = require('../controller/timerscontroller.js')
, groupsController = require('../controller/groupscontroller.js')
, sessionscontroller = require('../controller/sessionscontroller.js')
, pjson = require('../../package.json');
/**
* Get all group and timer records and render the timers page
* @param {Object} req The request-object
* @param {Object} res The response-object
*/
exports.timers = function(req, res){
timersController.getTimers(function(timers){
groupsController.getGroups(function(groups){
//Sum up times for groups
for (var i = 0; i < groups.length; i++) {
groupstime = 0;
for (var j = 0; j < timers.length; j++) {
if(timers[j].group === groups[i]._id)
groupstime += timers[j].time;
};
groups[i].time = groupstime;
};
//Render the page
res.render('timers', { version: pjson.version, title: 'My Timers', timers: timers,
groups: groups, flash: req.flash()}
);
});
});
};
/**
* Get all session records and render the statistics page
* @param {Object} req The request-object
* @param {Object} res The response-object
*/
exports.timerStatistics = function(req, res){
timersController.getTimer(req.params.id, function(err, timer){
sessionscontroller.getAllForTimer(req.params.id, function(err,sessions){
if(err) console.log(err);
res.render('statistics', { version: pjson.version, title: 'Timerstats', timer:timer, sessions:sessions, flash: req.flash()});
});
});
};
/**
* Gets all timers of the specified group and rendes the group-statistics page
* @param {Object} req The request-object
* @param {Object} res The response-object
*/
exports.groupStatistics = function(req, res){
groupsController.getGroup(req.params.id, function(err, group){
timersController.getTimers(function(timers){
var result = [];
for (var i = 0; i < timers.length; i++) {
if(timers[i].group === req.params.id){
result.push(timers[i]);
}
};
res.render('groupstatistics', { version: pjson.version, title: 'Groupstats',
timers:result, group:group, flash: req.flash()});
});
});
}
/**
* Shows the preferences page
* @param {Object} req The request-object
* @param {Object} res The response-object
*/
exports.preferences = function(req, res){
res.render('preferences', { version: pjson.version,
dbpath: process.env.TIMERDB,
sortingkey : process.env.TIMERSORTINGKEY,
port: process.env.TIMERPORT,
title: 'preferences',
flash: req.flash()});
};
/**
* Shows the changelog page
* @param {Object} req The request-object
* @param {Object} res The response-object
*/
exports.changelog = function(req, res){
res.render('changelog', { version: pjson.version, title: 'changelog', flash: req.flash()});
};