diff options
author | Joel Kronqvist <work.joelkronqvist@gmail.com> | 2022-11-18 18:27:40 +0200 |
---|---|---|
committer | Joel Kronqvist <work.joelkronqvist@gmail.com> | 2022-11-18 18:27:40 +0200 |
commit | d10272298acb4d6e07fb5b73dd7af06d653afd7b (patch) | |
tree | 7031c0edd2a64edbfb69958e099fcbcf929bbf36 | |
parent | 5665f993de41b82ab24c4a546d442b18f0bda4d3 (diff) | |
download | LYLLRuoka-d10272298acb4d6e07fb5b73dd7af06d653afd7b.tar.gz LYLLRuoka-d10272298acb4d6e07fb5b73dd7af06d653afd7b.zip |
Updated exam/vacation/etc notifications.
Now they don't block the search field, which is more user friendly. They also appear only if the date searched for matches the notification, not if the current date matches the notification.
-rw-r--r-- | Functions/dateFuncs.js | 8 | ||||
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | server.js | 17 |
3 files changed, 18 insertions, 13 deletions
diff --git a/Functions/dateFuncs.js b/Functions/dateFuncs.js index 340b46e..caec1c9 100644 --- a/Functions/dateFuncs.js +++ b/Functions/dateFuncs.js @@ -5,14 +5,14 @@ function stringToDate(s) { } const isBetweenDates = (date, date1, date2) => { - date = approxDate(date); - date1 = approxDate(date1); - date2 = approxDate(date2); + date = floorDate(date); + date1 = floorDate(date1); + date2 = floorDate(date2); return ((date.getTime() >= date1.getTime()) && (date.getTime() <= date2.getTime())); }; -function approxDate(d) +function floorDate(d) { return new Date(`${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, "0")}-${d.getDate().toString().padStart(2, "0")}`); } @@ -134,14 +134,14 @@ If you need to troubleshoot the starting, you can find some logs in /tmp/slogs. # Adding cool data that isn't required for the server to run -## Notifying of unusual food shifts (eg. during exams) +## Notifying of unusual food shifts (eg. during exams or vacations) Currently the notifications have to be added manually to the MySQL database. Here's an example: ``` USE lyllruoka; -INSERT INTO exams VALUES ('2021-11-22', '2021-11-30', '<h2>Koeviikko</h2><br>22.11. - 30.11..<br>Kouluruokaa on tarjolla 10:45-11:30.'); +INSERT INTO exams VALUES ('2021-11-22', '2021-11-30', '<h2>Koeviikko</h2>22.11. - 30.11..<br>Kouluruokaa on tarjolla 10:45-11:30.'); ``` -The first value in the parenthesis is the start date of the notification, the second the end date of the notification and the third value is the message to display. HTML is supported. The message will override the food shift search. +The first value in the parenthesis is the start date of the notification, the second the end date of the notification and the third value is the message to display. HTML is supported. The message will override the food shift result. ## Updating the developer table @@ -182,7 +182,7 @@ async function buildMain(args) let day = d.getDay(); day = (day + +(day === 0) * 7) - 1; // converts from 0 = sunday to 0 = monday const actualDay = day; - day = +(!(day === 5) && !(day === 6)) * day; + day = +(!(day === 5) && !(day === 6)) * day; // resets day to monday if saturday or sunday if ((typeof query.day === "string") && (parseInt(query.day).toString() === query.day) && (!isNaN(parseInt(query.day))) && (parseInt(query.day) >= 0) && (parseInt(query.day) < 5)) day = parseInt(query.day); // set the day selected (must be done manually with this replacement system) @@ -239,16 +239,21 @@ async function buildMain(args) const examInfo = await SQLDB.query("SELECT * FROM exams"); for(let week = 0; week < examInfo.length; week++) { + // get the date of the requested day + const nextDate = new Date( + d.getFullYear(), + d.getMonth(), + d.getDate() + day - actualDay + (day < actualDay)*7 + ); + if (dateFuncs.between( - d, + nextDate, new Date(examInfo[week].start), new Date(examInfo[week].end) )) { - const message = "<div id=\"foodshift\">" + - `<div class="float-block">${examInfo[week].message}</div>` + - "</div"; - data_string = strFuncs.replaceElement(data_string, "div id=\"foodshift\"", message); + const message = `<div class="shift-result float-block">${examInfo[week].message}</div>`; + data_string = strFuncs.replaceElement(data_string, "div id=\"shift-result\" class=\"float-block\"", message); } } |