Slider now has defined time range

This commit is contained in:
Claudio Maggioni 2019-11-04 11:56:48 +01:00
parent ac68a46c40
commit 7008405987

30
app.js
View file

@ -30,7 +30,8 @@ function roomStatus(room, callback) {
end.setSeconds(0); end.setSeconds(0);
parsed.push({ parsed.push({
title: lesson.getAttribute('title'), title: lesson.getAttribute('title').
replace(/\s*S[PA] \d\d\d\d-\d\d\d\d\s*/g, ''),
start: start, start: start,
end: end end: end
}); });
@ -126,30 +127,27 @@ function setTimePreview(date) {
function setupTimeMachine() { function setupTimeMachine() {
const slider = document.getElementById('timemachine'); const slider = document.getElementById('timemachine');
slider.min = 0; slider.min = 8 * 60 + 30;
// Remaining minutes until 23:59 slider.max = 19 * 60 + 30;
// 24 * 60 - [current hours * 60] - [current minutes] - [1 min to midnight]
slider.max = 1440 - (NOW.getHours() * 60) - NOW.getMinutes() - 1;
slider.addEventListener("input", (e) => { slider.addEventListener("input", (e) => {
const hours = Math.floor(slider.value / 60); const date = new Date();
const mins = slider.value % 60; date.setHours(0);
date.setMinutes(slider.value);
let newDate = new Date();
newDate.setHours(newDate.getHours() + hours);
newDate.setMinutes(newDate.getMinutes() + mins);
const node = getRoomNode(); const node = getRoomNode();
setTimePreview(newDate) setTimePreview(date);
ROOMS.forEach((roomTitle) => { ROOMS.forEach((roomTitle) => {
colorRoom(roomTitle, node, newDate); colorRoom(roomTitle, node, date);
}); });
}); });
// 10 mins into the future by default const date = new Date();
slider.value = 10; const mins = date.getHours() * 60 + date.getMinutes();
setTimePreview(new Date(NOW.getTime() + 600000)); slider.value = mins < slider.min ? slider.min :
mins > slider.max ? slider.max : mins;
setTimePreview(date);
} }
(async function() { (async function() {