Added total by course page
This commit is contained in:
@@ -43,4 +43,6 @@ block extracss
|
||||
}
|
||||
|
||||
block extrajs
|
||||
script.
|
||||
window.TABLE_URL = "#{tableUrl}";
|
||||
script(src="/static/js/totalTable.js")
|
||||
|
||||
27
controllers/total/templates/totalTableByCourse.pug
Normal file
27
controllers/total/templates/totalTableByCourse.pug
Normal file
@@ -0,0 +1,27 @@
|
||||
table.table.table-bordered.table-striped.table-hover
|
||||
thead
|
||||
tr
|
||||
th Course name
|
||||
each type in types
|
||||
th #{type}
|
||||
th Total TD equivalent
|
||||
tbody
|
||||
each course in courses
|
||||
tr
|
||||
td #{course.name}
|
||||
each type in types
|
||||
td #{course[type]}
|
||||
td #{course.totalTdEquivalent}
|
||||
tr.table-active
|
||||
td
|
||||
strong #{total.name}
|
||||
each type in types
|
||||
td
|
||||
strong #{total[type]}
|
||||
td
|
||||
strong #{total.totalTdEquivalent}
|
||||
|
||||
p.
|
||||
If you think there is a mistake in this table, feel free to
|
||||
<a href="https://github.com/tforgione/adejs/issues/new">open an issue</a>
|
||||
exaplaining what are the problem so we can fix it. Thanks!
|
||||
@@ -2,5 +2,7 @@ const url = require('create-url').url;
|
||||
|
||||
module.exports = [
|
||||
url('/total/', 'total', 'total'),
|
||||
url('/total-by-course/', 'totalByCourse', 'totalByCourse'),
|
||||
url('/total-table', 'totalTable', 'totalTable'),
|
||||
url('/total-table-by-course', 'totalTableByCourse', 'totalTableByCourse'),
|
||||
]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const config = require('settings/config');
|
||||
const cal = require('calendar');
|
||||
const redirectIfNotLogged = require('auth/views').redirectIfNotLogged;
|
||||
const getUrl = require('create-url').getUrl;
|
||||
|
||||
function computeUserTable(user, callback) {
|
||||
|
||||
@@ -35,7 +36,46 @@ function computeUserTable(user, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function computeUserTableByCourse(user, callback) {
|
||||
|
||||
let result = {};
|
||||
|
||||
cal.getTotalByCourse(user, (table) => {
|
||||
let courses = [];
|
||||
let total = { name: "Total" };
|
||||
for (let type in cal.Type) {
|
||||
total[type] = 0;
|
||||
}
|
||||
total.totalTdEquivalent = 0;
|
||||
|
||||
|
||||
for (let key in table) {
|
||||
let item = {};
|
||||
item.name = key;
|
||||
for (let type in cal.Type) {
|
||||
item[type] = table[key][type];
|
||||
total[type] += table[key][type];
|
||||
}
|
||||
item.totalTdEquivalent = table[key].totalTdEquivalent;
|
||||
total.totalTdEquivalent += table[key].totalTdEquivalent;
|
||||
courses.push(item);
|
||||
}
|
||||
|
||||
result.courses = courses;
|
||||
result.total = total;
|
||||
|
||||
callback(result);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.total = redirectIfNotLogged('total', function(req, res, render) {
|
||||
res.locals.tableUrl = getUrl('totalTable');
|
||||
render('total.pug');
|
||||
});
|
||||
|
||||
module.exports.totalByCourse = redirectIfNotLogged('totalByCourse', function(req, res, render) {
|
||||
res.locals.tableUrl = getUrl('totalTableByCourse');
|
||||
render('total.pug');
|
||||
});
|
||||
|
||||
@@ -59,3 +99,28 @@ module.exports.totalTable = function(req, res, render, next) {
|
||||
render('totalTable.pug');
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.totalTableByCourse = 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;
|
||||
}
|
||||
|
||||
computeUserTableByCourse(req.session.user, (result) => {
|
||||
res.locals.types = [];
|
||||
for (let type in cal.Type) {
|
||||
res.locals.types.push(type);
|
||||
}
|
||||
res.locals.courses = result.courses;
|
||||
res.locals.total = result.total;
|
||||
render('totalTableByCourse.pug');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user