aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.html13
-rw-r--r--server.js14
2 files changed, 22 insertions, 5 deletions
diff --git a/index.html b/index.html
index 1240145..c31df04 100644
--- a/index.html
+++ b/index.html
@@ -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>
diff --git a/server.js b/server.js
index 86ed81e..6274ba2 100644
--- a/server.js
+++ b/server.js
@@ -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)