aboutsummaryrefslogtreecommitdiff
path: root/admin/public
diff options
context:
space:
mode:
authorMarvin Borner2021-01-26 13:12:41 +0100
committerMarvin Borner2021-01-26 13:12:41 +0100
commit39652bd9c908247139d177b02f1126cb5e07c119 (patch)
treee6e42a16249e9d15dececd451ec923c56837be15 /admin/public
parent40035bd9cea21c4173f6727ba54d94f4fde44a9c (diff)
Some minor changes lol
Diffstat (limited to 'admin/public')
-rw-r--r--admin/public/index.html1
-rw-r--r--admin/public/questions.html31
-rw-r--r--admin/public/questions.js57
-rw-r--r--admin/public/votes.js2
4 files changed, 90 insertions, 1 deletions
diff --git a/admin/public/index.html b/admin/public/index.html
index d88d38d..55bb54b 100644
--- a/admin/public/index.html
+++ b/admin/public/index.html
@@ -23,6 +23,7 @@
<div class="pure-menu">
<ul class="pure-menu-list">
<li class="pure-menu-item"><a href="ranking.html" class="pure-menu-link">Ranking</a></li>
+ <li class="pure-menu-item"><a href="questions.html" class="pure-menu-link">Fragen</a></li>
<li class="pure-menu-item"><a href="votes.html" class="pure-menu-link">Votes</a></li>
<li class="pure-menu-item"><a href="participation.html" class="pure-menu-link">Teilnahme</a></li>
</ul>
diff --git a/admin/public/questions.html b/admin/public/questions.html
new file mode 100644
index 0000000..23332b8
--- /dev/null
+++ b/admin/public/questions.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <link
+ rel="stylesheet"
+ href="https://unpkg.com/purecss@2.0.3/build/pure-min.css"
+ integrity="sha384-cg6SkqEOCV1NbJoCu11+bm0NvBRc8IYLRGXkmNrqUBfTjmMYwNKPWBTIKyw9mHNJ"
+ crossorigin="anonymous"
+ />
+ <link rel="stylesheet" href="style.css" type="text/css" media="all" />
+
+ <title>Fragen</title>
+ </head>
+ <body>
+ <div class="pure-menu pure-menu-horizontal">
+ <a href="/" class="pure-menu-item pure-menu-link">Home</a>
+ <a href="/auth/api/logout" class="pure-menu-item pure-menu-link">Logout</a>
+ </div>
+ <div class="card">
+ <button class="pure-button" id="switch">Switch</button>
+ <br />
+ <h2 id="question"></h2>
+ <canvas id="questions" width="400" height="400"></canvas>
+ </div>
+
+ <script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.bundle.min.js"></script>
+ <script src="questions.js"></script>
+ </body>
+</html>
diff --git a/admin/public/questions.js b/admin/public/questions.js
new file mode 100644
index 0000000..32e48bf
--- /dev/null
+++ b/admin/public/questions.js
@@ -0,0 +1,57 @@
+let chart;
+const data = [];
+let question_index = 0;
+
+const label = document.getElementById("question");
+
+fetch("/admin/api/percentages")
+ .then((response) => response.json())
+ .then((response) => {
+ response.forEach((e) => {
+ if (!data[e.id - 1]) data[e.id - 1] = [];
+ data[e.id - 1].push(e);
+ });
+ render(question_index);
+ });
+
+function render(index) {
+ const ctx = document.getElementById("questions").getContext("2d");
+ const q = data[question_index];
+ label.innerText = q[0].question;
+ chart = new Chart(ctx, {
+ type: "pie",
+ data: {
+ labels: [...new Set(q.map((a) => a.option))],
+ datasets: [
+ {
+ label: "# of Votes",
+ data: q.map((a) => a.count || 0),
+ backgroundColor: () => "#" + (Math.random().toString(16) + "0000000").slice(2, 8),
+ borderWidth: 1,
+ },
+ ],
+ },
+ options: {
+ legend: {
+ display: false,
+ },
+ scales: {
+ yAxes: [
+ {
+ ticks: {
+ beginAtZero: true,
+ precision: 0,
+ },
+ },
+ ],
+ },
+ },
+ });
+}
+
+document.getElementById("switch").addEventListener("click", () => {
+ chart.destroy();
+ render(++question_index);
+ if (question_index + 1 < data.length) question_index++;
+ else question_index = 0;
+});
diff --git a/admin/public/votes.js b/admin/public/votes.js
index 1bde08b..39a379f 100644
--- a/admin/public/votes.js
+++ b/admin/public/votes.js
@@ -1,4 +1,4 @@
-let date;
+let data;
let chart;
fetch("/admin/api/votes")