2017-09-26 11:49:03 +02:00
|
|
|
const config = require('settings/config');
|
2017-09-25 20:39:34 +02:00
|
|
|
const cal = require('calendar');
|
2017-09-26 11:42:31 +02:00
|
|
|
const redirectIfNotLogged = require('auth/views').redirectIfNotLogged;
|
2017-09-24 00:38:12 +02:00
|
|
|
|
2017-09-25 15:26:06 +02:00
|
|
|
function computeUserTable(user, callback) {
|
|
|
|
|
|
|
|
let result = {};
|
|
|
|
|
|
|
|
cal.getTotal(user, (table) => {
|
2017-09-24 00:38:12 +02:00
|
|
|
let courses = [];
|
|
|
|
let total = {
|
|
|
|
name: "Total",
|
2017-09-24 00:39:13 +02:00
|
|
|
type: "",
|
2017-09-24 00:38:12 +02:00
|
|
|
time: 0,
|
|
|
|
tdEquivalent: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let key in table) {
|
|
|
|
courses.push({
|
|
|
|
name: key,
|
|
|
|
type: table[key].type,
|
|
|
|
time: table[key].time,
|
|
|
|
tdEquivalent: table[key].tdEquivalent,
|
|
|
|
});
|
|
|
|
|
|
|
|
total.time += table[key].time;
|
|
|
|
total.tdEquivalent += table[key].tdEquivalent;
|
|
|
|
}
|
|
|
|
|
2017-09-25 15:26:06 +02:00
|
|
|
result.courses = courses;
|
|
|
|
result.total = total;
|
2017-09-24 00:38:12 +02:00
|
|
|
|
2017-09-25 15:26:06 +02:00
|
|
|
callback(result);
|
2017-09-24 00:38:12 +02:00
|
|
|
|
2017-09-25 15:26:06 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-26 11:42:31 +02:00
|
|
|
module.exports.total = redirectIfNotLogged('total', function(req, res, render) {
|
2017-09-25 15:26:06 +02:00
|
|
|
render('total.pug');
|
2017-09-26 11:42:31 +02:00
|
|
|
});
|
2017-09-25 15:26:06 +02:00
|
|
|
|
2017-09-26 11:49:03 +02:00
|
|
|
module.exports.totalTable = function(req, res, render, next) {
|
|
|
|
if (req.session.user === undefined) {
|
|
|
|
res.status(404);
|
|
|
|
|
|
|
|
res.setHeader('Content-Type', 'text/html');
|
|
|
|
|
|
|
|
res.render(config.BASE_DIR + '/templates/404.pug', res.locals, function(err, result) {
|
|
|
|
if (err)
|
|
|
|
console.log(err);
|
|
|
|
res.send(result);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-25 15:26:06 +02:00
|
|
|
computeUserTable(req.session.user, (result) => {
|
|
|
|
res.locals.courses = result.courses;
|
2017-09-25 17:17:24 +02:00
|
|
|
res.locals.total = result.total;
|
2017-09-25 15:26:06 +02:00
|
|
|
render('totalTable.pug');
|
2017-09-24 00:38:12 +02:00
|
|
|
});
|
|
|
|
}
|