aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--admin/index.js2
-rw-r--r--admin/public/prediction.html2
-rw-r--r--admin/public/prediction.js27
3 files changed, 26 insertions, 5 deletions
diff --git a/admin/index.js b/admin/index.js
index 7479a3e..37e5914 100644
--- a/admin/index.js
+++ b/admin/index.js
@@ -76,7 +76,7 @@ app.get("/api/participation", checkAdmin, async (req, res) => {
app.get("/api/prediction", checkAdmin, async (req, res) => {
const prediction = await db.query(
- "SELECT u.name uname, u.middlename umid, u.surname usur, t.name tname, t.middlename tmid, t.surname tsur FROM users u INNER JOIN teacher_prediction p ON u.id = p.user_id INNER JOIN users t ON t.id = p.teacher_id",
+ "SELECT u.name uname, u.middlename umid, u.surname usur, t.id tid, t.name tname, t.surname tsur, c.name class FROM users u INNER JOIN teacher_prediction p ON u.id = p.user_id INNER JOIN users t ON t.id = p.teacher_id INNER JOIN class c ON c.id = u.class_id",
);
res.json(prediction);
});
diff --git a/admin/public/prediction.html b/admin/public/prediction.html
index 99e35e3..c48f5cf 100644
--- a/admin/public/prediction.html
+++ b/admin/public/prediction.html
@@ -20,7 +20,7 @@
</div>
<div class="card">
<h2>Wo sieht mich mein Lehrer in 10 Jahren?</h2>
- <ul id="list"></ul>
+ <div id="list"></div>
</div>
<script src="prediction.js"></script>
diff --git a/admin/public/prediction.js b/admin/public/prediction.js
index 66afb06..914f910 100644
--- a/admin/public/prediction.js
+++ b/admin/public/prediction.js
@@ -4,8 +4,29 @@ fetch("api/prediction")
.then((r) => r.json())
.then((r) => {
r.forEach((d) => {
- const elem = document.createElement("li");
- elem.innerText = `${d.uname} ${d.umid || ""} ${d.usur}: ${d.tname} ${d.tmid || ""} ${d.tsur}`;
- list.appendChild(elem);
+ const teacherList = list.querySelector(`div[data-teacher="${d.tid}"]`);
+ if (teacherList) {
+ const ul = teacherList.querySelector("ul");
+ addLI(d, ul);
+ } else {
+ const div = document.createElement("div");
+ div.dataset.teacher = `${d.tid}`;
+ const h3 = document.createElement("h3");
+ const email = `${san(d.tname)}.${san(d.tsur)}@rbs-ulm.de`;
+ h3.textContent = `${d.tname} ${d.tsur}: ${email}`;
+ const ul = document.createElement("ul");
+ addLI(d, ul);
+ div.append(h3, ul);
+ list.appendChild(div);
+ }
});
});
+
+function addLI(d, ul) {
+ const li = document.createElement("li");
+ li.textContent = `${d.uname} ${d.umid || ""} ${d.usur} (${d.class})`;
+ ul.appendChild(li);
+}
+
+const san = (name) =>
+ name.toLowerCase().replace(/ß/g, "ss").replace(/ä/g, "ae").replace(/ü/g, "ue").replace(/ö/g, "oe");