aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auth/index.js4
-rw-r--r--quotes/public/script.js14
2 files changed, 11 insertions, 7 deletions
diff --git a/auth/index.js b/auth/index.js
index a64d582..d80e673 100644
--- a/auth/index.js
+++ b/auth/index.js
@@ -59,10 +59,10 @@ app.post("/api/password", checkUser, async (req, res) => {
app.get("/api/list", checkUser, async (req, res) => {
let users;
if (req.query.class === "all") {
- users = await db.query("SELECT id, name, middlename, surname FROM users ORDER BY name");
+ users = await db.query("SELECT id, name, middlename, surname, class_id FROM users ORDER BY class_id, name");
} else {
users = await db.query(
- "SELECT id, name, middlename, surname FROM users WHERE class_id = (SELECT class_id FROM users WHERE id = ?) AND id != ? ORDER BY name",
+ "SELECT id, name, middlename, surname, class_id FROM users WHERE class_id = (SELECT class_id FROM users WHERE id = ?) AND id != ? ORDER BY name",
[req.session.uid, req.session.uid],
);
}
diff --git a/quotes/public/script.js b/quotes/public/script.js
index 5f40a27..55eeb5f 100644
--- a/quotes/public/script.js
+++ b/quotes/public/script.js
@@ -1,14 +1,19 @@
const dropdown = document.getElementById("author");
+const classes = ["TGM13.1", "TGM13.2", "TGTM13.1", "TGI13.1", "TGI13.2", "Lehrer"];
dropdown.insertAdjacentHTML("beforeend", '<option selected="true" disabled>Author auswählen...</option>');
+dropdown.insertAdjacentHTML("beforeend", `<option disabled>--${classes[0]}--</option>`);
function appendOption(response) {
- response.forEach((elem) => {
+ response.forEach((elem, i) => {
dropdown.insertAdjacentHTML(
"beforeend",
- `<option value="${elem["id"]}">${elem["name"]} ${elem["middlename"] ? elem["middlename"] : " "}${
- elem["surname"]
- }</option>`,
+ (response[i - 1 < 0 ? 0 : i - 1]["class_id"] !== elem["class_id"]
+ ? `<option disabled>--${classes[elem["class_id"] - 1]}--</option>`
+ : "") +
+ `<option value="${elem["id"]}">${elem["name"]} ${elem["middlename"] ? elem["middlename"] : " "}${
+ elem["surname"]
+ }</option>`,
);
});
}
@@ -44,7 +49,6 @@ fetch("api/list")
.then((response) => response.json())
.then((response) => appendQuote(response));
-const classes = ["TGI13.1", "TGI13.2", "TGM13.1", "TGM13.2", "TGTM13.1", "teacher"];
classes.forEach((clazz) => {
document.getElementById("open_" + clazz).addEventListener("click", () => {
const ul = document.getElementById(clazz);