diff options
author | JoelHMikael <joel.h.kronqvist@gmail.com> | 2021-12-06 14:59:09 +0200 |
---|---|---|
committer | JoelHMikael <joel.h.kronqvist@gmail.com> | 2021-12-06 14:59:09 +0200 |
commit | fbfdfaec51be5a7ead56a2888e4864c8b3470db5 (patch) | |
tree | cc6e294b037f534761afaf34a40b341011f862d8 | |
parent | ffef8333636fe6143aa675534f6ce7852199be20 (diff) | |
download | LYLLRuoka-fbfdfaec51be5a7ead56a2888e4864c8b3470db5.tar.gz LYLLRuoka-fbfdfaec51be5a7ead56a2888e4864c8b3470db5.zip |
Added a possibility to choose the weekday
-rw-r--r-- | index.html | 13 | ||||
-rw-r--r-- | server.js | 14 |
2 files changed, 22 insertions, 5 deletions
@@ -9,10 +9,21 @@ <h1>Food-app</h1> <p>\(result\)</p> <form method="GET"> - <label for="index">Abbreviation of teacher or course:</label> + <label for="index">Opettaja / kurssi:</label> <br> <input type="text" name="index" placeholder="sahe // ÄI1.2"> <br> + <label for="day">Päivä:</label> + <br> + <select name="day"> + <option value="1">ma</option> + <option value="2">ti</option> + <option value="3">ke</option> + <option value="4">to</option> + <option value="5">pe</option> + <option value="6" disabled>la</option> + <option value="0" disabled>su</option> + </select> <input type="submit"> </form> </body> @@ -80,11 +80,14 @@ async function buildMain(args) const DB = args["db"]; const data = await openFile(path); - const data_string = data.toString("utf-8"); - let res; + let data_string = data.toString("utf-8"); + let res; const d = new Date(); - const day = d.getDay(); + let day = d.getDay(); + + if ((typeof query.day === "string") && (parseInt(query.day).toString() === query.day) && (!isNaN(parseInt(query.day))) && (parseInt(query.day) > 0) && (parseInt(query.day) < 7)) + day = parseInt(query.day); if ((day === 0) || (day === 6)) res = `Maanantain ruoka: ${parse.get(day, query.index, DB)}`; @@ -95,7 +98,10 @@ async function buildMain(args) if (res === -1) res = "Kyseiselle kurssille/opettajalle ei löydy ruokailua päivältä!"; - return data_string.replace("\\(result\\)", res); + data_string = data_string.replace("\\(result\\)", res); + data_string = data_string.replace(`<option value=\"${day}\">`, `<option value=\"${day}\" selected>`); + + return data_string; } async function build404(path, attemptpath) |