diff options
author | joel <joel.h.kronqvist@gmail.com> | 2021-12-26 17:02:12 +0200 |
---|---|---|
committer | joel <joel.h.kronqvist@gmail.com> | 2021-12-26 17:02:12 +0200 |
commit | 8f711465194f6779271825bdb2413658880f4c18 (patch) | |
tree | 2670f98a205d1746eca4a7e163a307b5bb20caaf | |
parent | b05479c0d40040c52dbd82d36ad6e206acfdc7c6 (diff) | |
download | LYLLRuoka-8f711465194f6779271825bdb2413658880f4c18.tar.gz LYLLRuoka-8f711465194f6779271825bdb2413658880f4c18.zip |
Fixed bug in day validation & food searching
-rw-r--r-- | server.js | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -87,6 +87,7 @@ function openFile(path) async function buildMain(args) { + // get the passed arguments const path = args["path"]; const query = args["query"]; const foods = args["foods"]; @@ -97,14 +98,18 @@ async function buildMain(args) const data = await openFile(path); let data_string = data.toString("utf-8"); + // here are the things to replace in the html page let res = {}; + // get valid day const d = new Date(); let day = d.getDay(); - const actualDay = day; - day = +((day === 0) || (day === 6)) + (+(!(day === 0) && !(day === 6)) * day); - if ((typeof query.day === "string") && (parseInt(query.day).toString() === query.day) && (!isNaN(parseInt(query.day))) && (parseInt(query.day) > 0) && (parseInt(query.day) < 7)) + let actualDay = day; + day = +((day === 0) || (day === 6)) + (+(!(day === 0) && !(day === 6)) * day); // clamp the day between monday (1) and friday (5) (inclusive) + // make the day the passed day instead if the passed day is valid + if ((typeof query.day === "string") && (parseInt(query.day).toString() === query.day) && (!isNaN(parseInt(query.day))) && (parseInt(query.day) > 0) && (parseInt(query.day) < 6)) day = parseInt(query.day); + // set the day selected (must be done manually with this replacement system) data_string = data_string.replace(`<option value=\"${day}\">`, `<option value=\"${day}\" selected>`); // get the food shift to res["shift"] @@ -147,6 +152,8 @@ async function buildMain(args) data_string = data_string.replace('<div id="shift-result" class="float-block">', '<div id="shift-result" class="float-block" style="display: none;">'); // get the food + day += (day === 0) * 7; + actualDay += (actualDay === 0) * 7; let food; food = foods[ +(day < actualDay) ][day]; // test this out more if (food !== undefined) @@ -159,7 +166,7 @@ async function buildMain(args) res["food-header"] = weekdays[day]; res["food"] = "Päivälle ei löytynyt ruokaa"; } - res["food-header"] = `Päivän ${res["food-header"]} kouluruoka:`; + res["food-header"] = `Kouluruoka ${res["food-header"]}:`; data_string = build_replace(data_string, res); |