aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLarsVomMars2021-01-27 14:34:36 +0100
committerLarsVomMars2021-01-27 14:34:36 +0100
commit833a7316fce5dd2be52255da3d9bc0809ef74413 (patch)
treeddd2ca5a17c51973803045b15f717d3dcee21874
parent675a967c7b8d5003cbb497e0b014062becc2f71c (diff)
Profile characteristic
-rwxr-xr-xcli.js6
-rw-r--r--db.js6
-rw-r--r--drop.sql1
-rw-r--r--profile/index.js36
-rw-r--r--profile/public/style.css6
-rw-r--r--profile/public/user.html1
-rw-r--r--profile/public/user.js43
-rw-r--r--tables.sql13
-rw-r--r--zeitung/parts/studenttemplate.tex1
9 files changed, 111 insertions, 2 deletions
diff --git a/cli.js b/cli.js
index e3165d2..2a7e5d3 100755
--- a/cli.js
+++ b/cli.js
@@ -45,6 +45,12 @@ if ((idx = params.indexOf("-r")) > -1) {
.then(() => process.exit(0))
.catch(console.error);
break;
+ case "char":
+ db.resetCharacteristics()
+ .then(() => console.info("Reset char!"))
+ .then(() => process.exit(0))
+ .catch(console.error);
+ break;
default:
console.info("Nothing to do!");
process.exit(0);
diff --git a/db.js b/db.js
index cf0d251..2735257 100644
--- a/db.js
+++ b/db.js
@@ -205,6 +205,12 @@ class DB {
await this.initQuestions();
}
+ async resetCharacteristics() {
+ const tables = await this.getTables();
+ await this.query("DROP TABLE IF EXISTS profile_char");
+ await this.query(tables[15]);
+ }
+
async regenerateUser(uid) {
const pwd = nanoid.nanoid(8);
const password = await bcrypt.hash(pwd, 10);
diff --git a/drop.sql b/drop.sql
index a267b0f..421c9cd 100644
--- a/drop.sql
+++ b/drop.sql
@@ -10,6 +10,7 @@ DROP TABLE IF EXISTS profile_input_types;
DROP TABLE IF EXISTS question_answers;
DROP TABLE IF EXISTS question_options;
DROP TABLE IF EXISTS question_questions;
+DROP TABLE IF EXISTS profile_char;
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS types;
DROP TABLE IF EXISTS class;
diff --git a/profile/index.js b/profile/index.js
index ded1ec4..ee81632 100644
--- a/profile/index.js
+++ b/profile/index.js
@@ -179,4 +179,40 @@ app.delete("/api/comment", async (req, res) => {
}
});
+// Char API
+app.get("/api/char/:uid", async (req, res) => {
+ const uid = req.params.uid;
+ const char = await db.query(
+ "SELECT txt FROM profile_char WHERE profile_id = ? AND user_id = ?",
+ [uid, req.session.uid],
+ );
+ res.json(char.length > 0 ? char[0] : {});
+});
+
+app.post("/api/char/:uid", async (req, res) => {
+ const uid = req.params.uid;
+ const { char } = req.body;
+ if (!char || char.length > 255) return res.json({ success: false });
+ try {
+ await db.query("INSERT INTO profile_char (profile_id, user_id, txt) VALUE (?,?,?)", [uid, req.session.uid, char]);
+ res.json({ success: true });
+ } catch (e) {
+ console.error(e);
+ res.json({ success: false });
+ }
+});
+
+app.put("/api/char/:uid", async (req, res) => {
+ const uid = req.params.uid;
+ const { char } = req.body;
+ if (!char || char.length > 255) return res.json({ success: false });
+ try {
+ await db.query("UPDATE profile_char SET txt = ? WHERE profile_id = ? AND user_id = ?", [char, uid, req.session.uid]);
+ res.json({ success: true });
+ } catch (e) {
+ console.error(e);
+ res.json({ success: false });
+ }
+});
+
module.exports = app;
diff --git a/profile/public/style.css b/profile/public/style.css
index c417a7e..106e590 100644
--- a/profile/public/style.css
+++ b/profile/public/style.css
@@ -64,12 +64,14 @@ img {
}
#user h1:after,
-#comments h2:after {
+#comments h2:after,
+#char h2:after {
content: url(/feather/icons/chevron-up.svg);
}
#user h1.bananenkuchen:after,
-#comments h2.bananenkuchen:after {
+#comments h2.bananenkuchen:after,
+#char h2.bananenkuchen:after {
content: url(/feather/icons/chevron-down.svg);
}
diff --git a/profile/public/user.html b/profile/public/user.html
index 8a3e980..56464e1 100644
--- a/profile/public/user.html
+++ b/profile/public/user.html
@@ -21,6 +21,7 @@
<main>
<div id="user"></div>
<div id="comments"></div>
+ <div id="char"></div>
</main>
<script src="user.js" charset="utf-8"></script>
diff --git a/profile/public/user.js b/profile/public/user.js
index 76aedc8..ba6952e 100644
--- a/profile/public/user.js
+++ b/profile/public/user.js
@@ -1,6 +1,7 @@
const uid = new URL(window.location.href).searchParams.get("uid");
const userDiv = document.getElementById("user");
const commentsDiv = document.getElementById("comments");
+const charDiv = document.getElementById("char");
if (uid < 1 || uid > 119) window.location.assign("./users.html"); // Well
@@ -146,6 +147,44 @@ async function addComments(comments) {
commentsDiv.append(addDiv);
}
+function addChar(char) {
+ let method = "POST";
+ const h2 = document.createElement("h2");
+ h2.textContent = "Erkennungsmerkmal";
+ h2.addEventListener("click", (evt) => {
+ const divs = evt.target.parentElement.querySelectorAll("div");
+ divs.forEach(
+ (div) => (div.style.display = !div.style.display || div.style.display === "flex" ? "none" : "flex"),
+ );
+ if (h2.classList.contains("bananenkuchen")) h2.classList.remove("bananenkuchen");
+ else h2.classList.add("bananenkuchen");
+ });
+ const inp = document.createElement("input");
+ const btn = document.createElement("button");
+ btn.textContent = "Senden";
+
+ if (char.hasOwnProperty("txt")) {
+ method = "PUT";
+ inp.value = char.txt;
+ }
+
+ inp.maxLength = 255;
+
+ btn.addEventListener("click", async e => {
+ const char = inp.value;
+ const body = JSON.stringify({ char });
+ await fetch(`api/char/${uid}`, {
+ method,
+ headers: { "Content-Type": "application/json" },
+ body,
+ });
+ });
+ const div = document.createElement("div");
+ div.style.display = "flex";
+ div.append(inp, btn);
+ charDiv.append(h2, div);
+}
+
fetch(`api/user/${uid}`)
.then((response) => response.json())
.then(addUser);
@@ -153,3 +192,7 @@ fetch(`api/user/${uid}`)
fetch(`api/comments/${uid}`)
.then((response) => response.json())
.then(addComments);
+
+fetch(`api/char/${uid}`)
+ .then((response) => response.json())
+ .then(addChar); \ No newline at end of file
diff --git a/tables.sql b/tables.sql
index a929ead..9f98c45 100644
--- a/tables.sql
+++ b/tables.sql
@@ -162,4 +162,17 @@ CREATE TABLE IF NOT EXISTS question_answers
CONSTRAINT `fk_question_question` FOREIGN KEY (question_id) REFERENCES question_questions (id),
CONSTRAINT `fk_question_answer2` FOREIGN KEY (option_id) REFERENCES question_options (id)
) ENGINE = InnoDB
+ DEFAULT CHARSET = utf8;
+
+CREATE TABLE IF NOT EXISTS profile_char
+(
+ id INTEGER PRIMARY KEY AUTO_INCREMENT,
+ profile_id INTEGER NOT NULL, -- profile
+ user_id INTEGER NOT NULL, -- user who submitted
+ txt VARCHAR(255) NOT NULL,
+
+ UNIQUE KEY uk_answer (profile_id, user_id),
+ CONSTRAINT `fk_char_user` FOREIGN KEY (profile_id) REFERENCES users (id),
+ CONSTRAINT `fk_char_user2` FOREIGN KEY (user_id) REFERENCES users (id)
+) ENGINE = InnoDB
DEFAULT CHARSET = utf8; \ No newline at end of file
diff --git a/zeitung/parts/studenttemplate.tex b/zeitung/parts/studenttemplate.tex
index 8a9dc03..a0cbf45 100644
--- a/zeitung/parts/studenttemplate.tex
+++ b/zeitung/parts/studenttemplate.tex
@@ -5,6 +5,7 @@
%\includesvg[keepaspectratio=true, scale=0.2]{ring}
%\end{figure}
+\clearpage
\tikz[remember picture,overlay]
\node[inner sep=0pt] at (2, -5) {
\includegraphics[keepaspectratio=true, scale=1]{ring.png}