From f7ff1bbb376de861394b3f77baf7bd3b90740961 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 4 Oct 2017 11:25:59 +0200 Subject: [PATCH] Able to show and hide null-courses --- .../total/templates/totalTableByCourse.pug | 16 ++++++------ controllers/total/views.js | 12 ++++++++- static/js/totalTable.js | 25 ++++++++++++++++--- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/controllers/total/templates/totalTableByCourse.pug b/controllers/total/templates/totalTableByCourse.pug index df83a9c..db19b2b 100644 --- a/controllers/total/templates/totalTableByCourse.pug +++ b/controllers/total/templates/totalTableByCourse.pug @@ -13,13 +13,15 @@ table.table.table-bordered.table-striped.table-hover td #{course[type]} td #{course.totalTdEquivalent} tr#extend - td - a(href="#") ... - each type in types - td - a(href="#") ... - td - a(href="#") ... + td(colspan=2+types.length) + a#extendText(href="#") ... + + each course in noCourses + tr.no-courses + td #{course.name} + each type in types + td #{course[type]} + td #{course.totalTdEquivalent} tr.table-active td diff --git a/controllers/total/views.js b/controllers/total/views.js index 725482c..e11e700 100644 --- a/controllers/total/views.js +++ b/controllers/total/views.js @@ -119,7 +119,17 @@ module.exports.totalTableByCourse = function(req, res, render, next) { for (let type in cal.Type) { res.locals.types.push(type); } - res.locals.courses = result.courses; + res.locals.courses = []; + res.locals.noCourses = []; + + for (let course of result.courses) { + if (course.totalTdEquivalent > 0) { + res.locals.courses.push(course); + } else { + res.locals.noCourses.push(course); + } + } + res.locals.total = result.total; render('totalTableByCourse.pug'); }); diff --git a/static/js/totalTable.js b/static/js/totalTable.js index 725b6ad..cbfa909 100644 --- a/static/js/totalTable.js +++ b/static/js/totalTable.js @@ -2,6 +2,7 @@ var loadingDiv = document.getElementById('loading'); var errorDiv = document.getElementById('error'); var resultDiv = document.getElementById('result'); const timeout = 10000; +var emptyCoursesShown = false; function getTable() { // Send XHR to totalTable @@ -27,32 +28,50 @@ function setData(text) { loadingDiv.style.display = "none"; errorDiv.style.display = "none"; resultDiv.innerHTML = text; + emptyCoursesShown = false; var emptyCourses = document.getElementsByClassName('no-courses'); if (emptyCourses.length === 0) { showEmptyCourses(); + document.getElementById('extend').style.display = "none"; } else { hideEmptyCourses(); document.getElementById('extend').addEventListener('click', function() { - showEmptyCourses(); + switchEmptyCourses(); }); } + updateExtendText(); } function showEmptyCourses() { + emptyCoursesShown = true; var emptyCourses = document.getElementsByClassName('no-courses'); for (var i = 0; i < emptyCourses.length; i++) { emptyCourses[i].style.display = ""; } - document.getElementById('extend').style.display = "none"; } function hideEmptyCourses() { + emptyCoursesShown = false; var emptyCourses = document.getElementsByClassName('no-courses'); for (var i = 0; i < emptyCourses.length; i++) { emptyCourses[i].style.display = "none"; } - document.getElementById('extend').style.display = ""; +} + +function switchEmptyCourses() { + if (emptyCoursesShown) { + hideEmptyCourses(); + } else { + showEmptyCourses(); + } + updateExtendText(); +} + +function updateExtendText() { + document.getElementById('extendText').innerHTML = + "Courses with null TD equivalent " + (emptyCoursesShown ? "(hide)" : "(show)"); + } function setError() {