aboutsummaryrefslogtreecommitdiff
path: root/admin/public/script.js
diff options
context:
space:
mode:
authorMarvin Borner2020-10-10 17:05:27 +0200
committerMarvin Borner2020-10-10 17:05:27 +0200
commit72f5731adeebf8d76c5c2dcc266f600ba57812d8 (patch)
tree4d774eb3d0464411a1bb09472c597298aa8965e8 /admin/public/script.js
parent167600b52eb03801bb7051a09dcb0e4f159cfb2a (diff)
Added basic admin interface
Diffstat (limited to 'admin/public/script.js')
-rw-r--r--admin/public/script.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/admin/public/script.js b/admin/public/script.js
new file mode 100644
index 0000000..ff6fa2b
--- /dev/null
+++ b/admin/public/script.js
@@ -0,0 +1,22 @@
+fetch("api/questions").then(questions => questions.json()).then(questions => {
+ fetch("api/answers").then(answers => answers.json()).then(answers => {
+ questions.forEach(question => question.answers = []);
+ answers.forEach(answer => questions[answer.question_id - 1].answers.push(answer));
+ render(questions);
+ });
+});
+
+function render(questions)
+{
+ console.log(questions);
+ const teacher = document.querySelector("ul#teacher");
+ const pupil = document.querySelector("ul#pupil");
+ questions.forEach(question => {
+ const list = question.type === "teacher" ? teacher : pupil;
+ let answers = "";
+ question.answers.forEach(answer => {
+ answers += `<li>${answer.name} ${answer.middlename ? answer.middlename + " " : ""}${answer.surname}: ${answer.count}</li>`
+ });
+ list.insertAdjacentHTML("beforeend", `<li>${question.question}<br><ol>${answers}</ol></li>`);
+ });
+}