From b2d9cf884f2aff3445d6619939186e48a683e5a9 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 10 Oct 2020 17:10:01 +0200 Subject: Welp, formatting :D --- admin/index.js | 6 ++++-- admin/public/index.html | 14 +++++++------- admin/public/script.js | 45 +++++++++++++++++++++++++-------------------- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/admin/index.js b/admin/index.js index 4cea14d..407bbcf 100644 --- a/admin/index.js +++ b/admin/index.js @@ -32,13 +32,15 @@ app.get("/api/all", checkAdmin, async (req, res) => { }); app.get("/api/questions", checkAdmin, async (req, res) => { - const questions = await db.query("SELECT q.id, question, t.name type FROM ranking_questions q INNER JOIN types t on type_id = t.id ORDER BY q.id"); + const questions = await db.query( + "SELECT q.id, question, t.name type FROM ranking_questions q INNER JOIN types t on type_id = t.id ORDER BY q.id", + ); res.json(questions); }); app.get("/api/answers", checkAdmin, async (req, res) => { const answers = await db.query( - "SELECT question_id, name, middlename, surname, count(*) count FROM ranking_questions q INNER JOIN ranking_answers a ON q.id = a.question_id INNER JOIN users u ON answer_id = u.id GROUP BY question_id, answer_id ORDER BY count DESC" + "SELECT question_id, name, middlename, surname, count(*) count FROM ranking_questions q INNER JOIN ranking_answers a ON q.id = a.question_id INNER JOIN users u ON answer_id = u.id GROUP BY question_id, answer_id ORDER BY count DESC", ); res.json(answers); }); diff --git a/admin/public/index.html b/admin/public/index.html index cf5d286..a611291 100644 --- a/admin/public/index.html +++ b/admin/public/index.html @@ -19,14 +19,14 @@ Logout - +
- Welche/r Schüler/in... - - Welche/r Lehrer/in... - -
+ Welche/r Schüler/in... + + Welche/r Lehrer/in... + + - + diff --git a/admin/public/script.js b/admin/public/script.js index ff6fa2b..d9fd30e 100644 --- a/admin/public/script.js +++ b/admin/public/script.js @@ -1,22 +1,27 @@ -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); - }); -}); +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 += `
  • ${answer.name} ${answer.middlename ? answer.middlename + " " : ""}${answer.surname}: ${answer.count}
  • ` - }); - list.insertAdjacentHTML("beforeend", `
  • ${question.question}
      ${answers}
  • `); - }); +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 += `
  • ${answer.name} ${answer.middlename ? answer.middlename + " " : ""}${answer.surname}: ${ + answer.count + }
  • `; + }); + list.insertAdjacentHTML("beforeend", `
  • ${question.question}
      ${answers}
  • `); + }); } -- cgit v1.2.3