From 897b4173c5cc190805a96aafe5f9258610332e39 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 10 Oct 2020 17:49:51 +0200 Subject: Added vote stats --- admin/public/index.html | 15 ++++++--------- admin/public/ranking.html | 32 ++++++++++++++++++++++++++++++++ admin/public/ranking.js | 26 ++++++++++++++++++++++++++ admin/public/script.js | 27 --------------------------- admin/public/style.css | 4 ++-- admin/public/votes.html | 28 ++++++++++++++++++++++++++++ admin/public/votes.js | 37 +++++++++++++++++++++++++++++++++++++ 7 files changed, 131 insertions(+), 38 deletions(-) create mode 100644 admin/public/ranking.html create mode 100644 admin/public/ranking.js delete mode 100644 admin/public/script.js create mode 100644 admin/public/votes.html create mode 100644 admin/public/votes.js diff --git a/admin/public/index.html b/admin/public/index.html index a611291..815b6aa 100644 --- a/admin/public/index.html +++ b/admin/public/index.html @@ -11,22 +11,19 @@ /> - Home + Admin
Home Logout
- -
- Welche/r Schüler/in... - - Welche/r Lehrer/in... - +

Admin

+
- - diff --git a/admin/public/ranking.html b/admin/public/ranking.html new file mode 100644 index 0000000..328f09a --- /dev/null +++ b/admin/public/ranking.html @@ -0,0 +1,32 @@ + + + + + + + + + Home + + +
+ Home + Logout +
+ + +
+ Welche/r Schüler/in... + + Welche/r Lehrer/in... + +
+ + + + diff --git a/admin/public/ranking.js b/admin/public/ranking.js new file mode 100644 index 0000000..4281e23 --- /dev/null +++ b/admin/public/ranking.js @@ -0,0 +1,26 @@ +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) { + 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}
  • `); + }); +} diff --git a/admin/public/script.js b/admin/public/script.js deleted file mode 100644 index d9fd30e..0000000 --- a/admin/public/script.js +++ /dev/null @@ -1,27 +0,0 @@ -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}
  • `); - }); -} diff --git a/admin/public/style.css b/admin/public/style.css index 77853bf..4e3cffc 100644 --- a/admin/public/style.css +++ b/admin/public/style.css @@ -12,7 +12,7 @@ body { position: absolute; max-height: 80%; overflow: auto; - width: 30%; + width: 40%; left: 50%; top: 50%; -webkit-transform: translate(-50%, -50%); @@ -26,7 +26,7 @@ div { background: white; } -@media only screen and (max-width: 600px) { +@media only screen and (max-width: 800px) { .card { width: calc(100% - 50px); } diff --git a/admin/public/votes.html b/admin/public/votes.html new file mode 100644 index 0000000..cd9563c --- /dev/null +++ b/admin/public/votes.html @@ -0,0 +1,28 @@ + + + + + + + + + Votes + + +
    + Home + Logout +
    +
    + +
    + + + + + diff --git a/admin/public/votes.js b/admin/public/votes.js new file mode 100644 index 0000000..3f1284c --- /dev/null +++ b/admin/public/votes.js @@ -0,0 +1,37 @@ +fetch("api/votes") + .then((response) => response.json()) + .then((response) => { + const ctx = document.getElementById("votes").getContext("2d"); + new Chart(ctx, { + type: "bar", + data: { + labels: response.map((v) => v.name), + datasets: [ + { + label: "# of Votes", + data: response.map((v) => v.votes || 0), + backgroundColor: () => "#" + (Math.random().toString(16) + "0000000").slice(2, 8), + borderWidth: 1, + }, + ], + }, + options: { + legend: { + display: false, + }, + tooltips: { + enabled: false, + }, + scales: { + yAxes: [ + { + ticks: { + beginAtZero: true, + precision: 0, + }, + }, + ], + }, + }, + }); + }); -- cgit v1.2.3