Hide empty courses, click to show them

Fixes #7
This commit is contained in:
Thomas Forgione 2017-10-03 14:17:26 +02:00
parent fabbae223e
commit 64e1316b1e
No known key found for this signature in database
GPG Key ID: C75CD416BD1FFCE1
4 changed files with 79 additions and 30 deletions

View File

@ -7,11 +7,20 @@ table.table.table-bordered.table-striped.table-hover
th Total TD equivalent th Total TD equivalent
tbody tbody
each course in courses each course in courses
tr tr(class=course.totalTdEquivalent === 0 ? "no-courses" : "")
td #{course.name} td #{course.name}
each type in types each type in types
td #{course[type]} td #{course[type]}
td #{course.totalTdEquivalent} td #{course.totalTdEquivalent}
tr#extend
td
a(href="#") ...
each type in types
td
a(href="#") ...
td
a(href="#") ...
tr.table-active tr.table-active
td td
strong #{total.name} strong #{total.name}
@ -25,3 +34,4 @@ p.
If you think there is a mistake in this table, feel free to 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> <a href="https://github.com/tforgione/adejs/issues/new">open an issue</a>
exaplaining what are the problem so we can fix it. Thanks! exaplaining what are the problem so we can fix it. Thanks!

View File

@ -61,7 +61,7 @@ function computeUserTableByCourse(user, callback) {
courses.push(item); courses.push(item);
} }
result.courses = courses; result.courses = courses.sort((a,b) => -(a.totalTdEquivalent - b.totalTdEquivalent));
result.total = total; result.total = total;
callback(result); callback(result);

View File

@ -1,6 +1,6 @@
let loadingDiv = document.getElementById('loading'); var loadingDiv = document.getElementById('loading');
let errorDiv = document.getElementById('error'); var errorDiv = document.getElementById('error');
let resultDiv = document.getElementById('result'); var resultDiv = document.getElementById('result');
const timeout = 10000; const timeout = 10000;
function getTable() { function getTable() {
@ -27,6 +27,32 @@ function setData(text) {
loadingDiv.style.display = "none"; loadingDiv.style.display = "none";
errorDiv.style.display = "none"; errorDiv.style.display = "none";
resultDiv.innerHTML = text; resultDiv.innerHTML = text;
var emptyCourses = document.getElementsByClassName('no-courses');
if (emptyCourses.length === 0) {
showEmptyCourses();
} else {
hideEmptyCourses();
document.getElementById('extend').addEventListener('click', function() {
showEmptyCourses();
});
}
}
function showEmptyCourses() {
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() {
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 setError() { function setError() {

View File

@ -20,22 +20,27 @@ function fromIcal(string) {
} }
cal.Type = { cal.Type = {
TD: 1, CM: 1,
TP: 2, CTD: 2,
BE: 3, TD: 3,
CTD: 4, TP: 4,
CM: 5, Other: {
Other: 6, BE: 5,
Examen: 6,
},
Unkown: 7,
} }
cal.getTypeName = function(type) { cal.getTypeName = function(type) {
switch (type) { switch (type) {
case cal.Type.TD: return "TD"; case cal.Type.TD: return "TD";
case cal.Type.TP: return "TP"; case cal.Type.TP: return "TP";
case cal.Type.CTD: return "CTD"; case cal.Type.CTD: return "CTD";
case cal.Type.CM: return "CM"; case cal.Type.CM: return "CM";
case cal.Type.BE: return "BE"; case cal.Type.Other.BE:
default: return "Other"; case cal.Type.Other.Examen:
return "Other";
default: return "Unknown";
} }
} }
@ -43,7 +48,8 @@ cal.getFactor = function(type) {
switch (type) { switch (type) {
case cal.Type.TD: case cal.Type.TD:
case cal.Type.TP: case cal.Type.TP:
case cal.Type.BE: case cal.Type.Other.BE:
case cal.Type.Other.Examen:
return 1; return 1;
case cal.Type.CTD: return 1.25; case cal.Type.CTD: return 1.25;
case cal.Type.CM: return 1.5; case cal.Type.CM: return 1.5;
@ -51,6 +57,23 @@ cal.getFactor = function(type) {
} }
} }
cal.getTypeFromName = function(name) {
if (name.indexOf("CTD") !== -1) {
return cal.Type.CTD;
} else if (name.indexOf("TP") !== -1) {
return cal.Type.TP;
} else if (name.indexOf("TD") !== -1) {
return cal.Type.TD;
} else if (name.indexOf("CM") !== -1) {
return cal.Type.CM;
} else if (name.indexOf("BE") !== -1) {
return cal.Type.Other.BE;
} else if (name.indexOf("Examen") !== -1) {
return cal.Type.Other.Examen;
}
}
cal.Event = class { cal.Event = class {
constructor(content, firstLineIndex = 0) { constructor(content, firstLineIndex = 0) {
@ -58,24 +81,14 @@ cal.Event = class {
this.finishTime = undefined; this.finishTime = undefined;
this.name = undefined; this.name = undefined;
this.location = undefined; this.location = undefined;
this.type = cal.Type.Other; this.type = cal.Type.Unkown;
if (content !== undefined) if (content !== undefined)
this.setFromContent(content, firstLineIndex); this.setFromContent(content, firstLineIndex);
} }
guessTypeFromName() { guessTypeFromName() {
if (this.name.indexOf("CTD") !== -1) { this.type = cal.getTypeFromName(this.name);
this.type = cal.Type.CTD;
} else if (this.name.indexOf("TP") !== -1) {
this.type = cal.Type.TP;
} else if (this.name.indexOf("TD") !== -1) {
this.type = cal.Type.TD;
} else if (this.name.indexOf("CM") !== -1) {
this.type = cal.Type.CM;
} else if (this.name.indexOf("BE") !== -1) {
this.type = cal.Type.BE;
}
} }
getDurationInHours() { getDurationInHours() {