Added calendar

master
Thomas Forgione 4 years ago
parent adab80734e
commit 5deb2662ce
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41

@ -0,0 +1,17 @@
extends ./total.pug
append css
link(rel='stylesheet', href=getStatic('fullcalendar/fullcalendar.css'))
block mistake
p.
If you think there is a mistake in this calendar, feel free to <a
href="mailto:thomas@forgione.fr">send me a mail</a> exaplaining what
are the problems so I can fix it. Thanks!
block extrajs
script.
window.CALENDAR_URL = "#{calendarUrl}";
script(src="/static/fullcalendar/fullcalendar.min.js")
script(src="/static/fullcalendar/locales-all.js")
script(src="/static/js/calendar.js")

@ -7,4 +7,6 @@ module.exports = [
url('/total-table-by-course', 'totalTableByCourse', 'totalTableByCourse'),
url('/histogram', 'histogram', 'histogram'),
url('/histogram-data', 'histogramData', 'histogramData'),
url('/calendar', 'calendar', 'calendar'),
url('/calendar-data', 'calendarData', 'calendarData'),
]

@ -3,6 +3,16 @@ const cal = require('calendar');
const redirectIfNotLogged = require('auth/views').redirectIfNotLogged;
const getUrl = require('create-url').getUrl;
function stdTimezoneOffset(date) {
var jan = new Date(date.getFullYear(), 0, 1);
var jul = new Date(date.getFullYear(), 6, 1);
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
}
function isDstObserved(date) {
return date.getTimezoneOffset() < stdTimezoneOffset(date);
}
function compareStrings(a, b) {
if (a < b)
return -1;
@ -193,3 +203,48 @@ module.exports.histogramData = function(req, res, render, next) {
});
}
module.exports.calendar = redirectIfNotLogged('/calendar', function(req, res, render) {
res.locals.calendarUrl = getUrl('calendarData');
render('calendar.pug');
});
module.exports.calendarData = function(req, res, render) {
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;
}
cal.getCalendar(req.session.user, new Date(2000, 1, 1), new Date(3000, 1, 1), (calendar) => {
let events = [];
for (let event of calendar.events) {
if (isDstObserved(event.startTime)) {
event.startTime.setTime(event.startTime.getTime() + (60 * 60 * 1000));
}
if (isDstObserved(event.finishTime)) {
event.finishTime.setTime(event.finishTime.getTime() + (60 * 60 * 1000));
}
events.push({
title: event.name,
start: event.startTime,
end: event.finishTime,
});
}
res.send(JSON.stringify(events));
});
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1,49 @@
var loadingDiv = document.getElementById('loading');
var errorDiv = document.getElementById('error');
var resultDiv = document.getElementById('result');
const timeout = 10000;
var emptyCoursesShown = false;
var calendar;
function getTable() {
// Send XHR to totalTable
loadingDiv.style.display = "";
errorDiv.style.display = "none";
let xhr = new XMLHttpRequest();
xhr.timeout = timeout;
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
let events = JSON.parse(xhr.responseText);
setData(events);
} else {
setError();
}
}
};
xhr.open('GET', CALENDAR_URL, true);
xhr.send();
}
function setData(events) {
console.log(events);
loadingDiv.style.display = "none";
errorDiv.style.display = "none";
calendar = new FullCalendar.Calendar(resultDiv, {
events: events,
defaultView: 'agendaWeek',
minTime: "07:00:00",
maxTime: "19:00:00",
timeZone: 'UTC',
});
calendar.render();
}
function setError() {
loadingDiv.style.display = "none";
errorDiv.style.display = "";
}
document.getElementById('tryAgain').addEventListener('click', getTable);
getTable();

@ -31,6 +31,8 @@ html
a.nav-link(href=getUrl("total")) Total
li.nav-item
a.nav-link(href=getUrl("totalByCourse")) Total by course
li.nav-item
a.nav-link(href=getUrl("calendar")) Calendar
li.nav-item
a.nav-link(href=getUrl("histogram")) Histogram
ul.navbar-nav.ml-auto

@ -7,16 +7,15 @@ var locale = require('os-locale').sync();
var cal = {};
function fromIcal(string) {
console.log(string);
return new Date(
parseInt(string.substr(0 , 4), 10),
parseInt(string.substr(4 , 2), 10),
parseInt(string.substr(4 , 2), 10) - 1,
parseInt(string.substr(6 , 2), 10),
parseInt(string.substr(9, 2), 10),
parseInt(string.substr(11, 2), 10),
parseInt(string.substr(13, 2), 10)
);
}
cal.Type = {

Loading…
Cancel
Save