From 322c62ec80fcd6c82f013b705e2c8d03e67e4e16 Mon Sep 17 00:00:00 2001 From: Turtle <104490184+CodingTurtle2@users.noreply.github.com> Date: Mon, 22 Dec 2025 13:26:45 +0100 Subject: [PATCH] g2.4 --- help/Example.html | 9 ++- help/data_xample.js | 82 ++++++++++++++++++++++ help/documentation.md | 32 ++++++--- lib/basic.css | 18 ++++- lib/basic.js | 99 +++++++++++++++++++++++++- login.html | 12 +--- prof/uebersicht.html | 158 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 387 insertions(+), 23 deletions(-) create mode 100644 help/data_xample.js diff --git a/help/Example.html b/help/Example.html index 9a19bcf..27f3748 100644 --- a/help/Example.html +++ b/help/Example.html @@ -34,6 +34,7 @@ test
test
test
test
test
test
test
test
test
test
+ diff --git a/help/data_xample.js b/help/data_xample.js new file mode 100644 index 0000000..301ee14 --- /dev/null +++ b/help/data_xample.js @@ -0,0 +1,82 @@ +async function createTemp() { + const couchDB = new CouchDB(); + await couchDB.set("users", { + "turtle": { + "password": "1234", + "level": 1, + "avatar": null, + "abilities": [], + "role": "student", + "courses": [ + "weiche_ware", + "bucket" + ] + }, + "dumble-door": { + "password": "bla", + "level": 10, + "avatar": "https://static.turtle-coding-gbr.de/profile-pic.png", + "abilities": [], + "role": "professor", + "courses": [ + "weiche_ware" + ] + }, + "narrator": { + "password": "stanley", + "level": 100, + "avatar": "https://static.turtle-coding-gbr.de/st", + "abilities": [], + "role": "professor", + "courses": [ + "bucket" + ] + } + }); + await couchDB.set("course:bucket", { + "title": "Bucket", + "description": "The end is never the end is never the end is never", + "owner": "narrator", + "questions": [ + { + "title": "What is comedic timing?", + "type": "text" + }, + { + "title": "How does it work?", + "type": "text" + }, + { + "title": "How long should it last?", + "type": "scala" + }, + { + "title": "How can it be used to effectively silence your political enemies?", + "type": "emoji" + } + ], + "result": [ + ["YES", "YES", 5, 2], + ["YES", "YES", 1, 3] + ] + }); + await couchDB.set("course:weiche_ware", { + "title": "Weiche Ware", + "description": "blabering", + "owner": "dumble-door", + "questions": [ + { + "title": "Wie fanden Sie die Vorlesung?", + "type": "text" + }, + { + "title": "Finden Sie, dass man Zauberei an lebendigen Schülern praktizieren sollte?", + "type": "scala" + } + ], + "result": [ + ["Gut, aber ...", 5], + ["Schlecht", 1] + ] + }); +} \ No newline at end of file diff --git a/help/documentation.md b/help/documentation.md index 5aa7d80..49163f6 100644 --- a/help/documentation.md +++ b/help/documentation.md @@ -7,11 +7,15 @@ ##Overlays ``` -//Erstelle ein element mit in html und vergebe eine id. Um das overlay anzuzeigen, rufe showOverlay mit der id auf -function showOverlay(string id); +//Erstelle ein element mit in html und vergebe eine id. Um das overlay anzuzeigen, rufe showOverlay mit der id auf +function showOverlay(string id) -> void; //Schließe das overlay mit der id -function hideOverlay(string id); +function hideOverlay(string id) -> void; + +//Rufe das overlay auf +function getOverlay(string id) -> div; + ``` ##CouchDB @@ -21,15 +25,17 @@ function hideOverlay(string id); //Erstelle eine neue CouchDB-Klasse mit new CouchDB(); class CouchDB { //Überprüfe, ob CouchDB online ist. (Wird sowieso automatisch gemacht, wenn get, set oder createDB verwendet wird) - async checkOnlineStatus(); + async checkOnlineStatus() -> bool; //Erstellt die Datenbank. (Wird auch automatisch gemacht, wenn man get oder set verwendet) - async createDB(); + async createDB() -> void; - //Bekomme das Objekt, was in der Datenbank unter der id gespeichert wurde - async get(string id); + //Bekomme das Objekt, was in der Datenbank unter der id gespeichert wurde (Gibt null zurück, wenn nicht vorhanden) + async get(string id) -> Map|null; //Setze ein Objekt, was in der Datenbank gespeichert wird (Bedenke: Du musst ein Objekt angeben, alles andere (string, array) wird nicht genommen) - async set(string id, object content, boolean replace = true); + async set(string id, object content, boolean replace = true) -> Map; + //Lösche ein Objekt, was in der Datenbank gespeichert ist + async delete(string id) -> Map; } ``` @@ -54,3 +60,13 @@ async function main() { } main(); ``` + +##User + +``` +//Gebe dir den Nutzer wieder +async function getUserData(couchDB) -> Map?; + +//Setze den Nutzer, welcher unter der Variable userData verfügbar sein wird +async function setUserData(couchDB) -> bool; +``` diff --git a/lib/basic.css b/lib/basic.css index 29ed1ad..db5e77b 100644 --- a/lib/basic.css +++ b/lib/basic.css @@ -77,7 +77,7 @@ overlay { backdrop-filter: blur(10px); border-radius: var(--border-radius); padding: 15px; - text-align: center; + text-align: left; overflow-x: hidden; overflow-y: auto; box-shadow: var(--def-shadow); @@ -168,4 +168,20 @@ content { top: 0; border-radius: 0; } +} + +/* ----------- custom ----------- */ + +.add_button { + width: 45px; + height: 45px; + border-radius: 50%; + padding: 0; + font-size: 25px; + background-color: white; + border: 1px solid black; +} +.add_button:hover { + border: 2px solid grey; + background-color: lightgray; } \ No newline at end of file diff --git a/lib/basic.js b/lib/basic.js index daa639f..c1b8faf 100644 --- a/lib/basic.js +++ b/lib/basic.js @@ -1,18 +1,48 @@ const getId = (id) => document.getElementById(id); +function getOverlay(id) { + const elms = document.getElementsByName(id); + if (elms.length == 0) return null; + return elms[0]; +} function showOverlay(id) { const elm = getId(id); + if (!elm) return; const overlay = document.createElement("div"); + + const computedStyles = getComputedStyle(elm); + const defaultStyles = getDefaultComputedStyle(elm); + let styleString = ""; + for (let style of computedStyles) { + if (style == "display") continue; + const computedValue = computedStyles.getPropertyValue(style); + const defaultValue = defaultStyles.getPropertyValue(style); + if (computedValue == defaultValue) continue; + styleString += `${style}: ${computedValue}; `; + } + overlay.classList.add("overlay"); overlay.setAttribute("name", id); overlay.innerHTML = `
-
+
${elm.innerHTML}
`; document.body.appendChild(overlay); + + const cb = elm.getAttribute("onopen"); + if (typeof cb == "string") { + try { + eval( + `const overlay = document.getElementsByClassName("${id}")[0]; ` + + cb + ); + } catch (err) { + console.error(err); + } + } } function _onOverlayDestroy(elm) { const ori_elm = getId(elm.getAttribute("name")); @@ -253,4 +283,71 @@ class CouchDB { }; } } + async delete(id) { + try { + var existingDoc = null; + try { + existingDoc = await this._get_db_data(id); + } catch (err) {} + if (!existingDoc) return { + type: "error", + message: "Not found!", + }; + + const res = await this._send_db_request( + "DELETE", + `${id}?rev=${existingDoc._rev}` + ); + return { + type: "success", + message: res, + }; + } catch (err) { + console.error(err); + return { + type: "error", + message: err, + }; + } + } } + + +//getuser + +function getURLArgsMap() { + let spl = location.href.split("?"); + if (spl.length != 2) return {}; + let _1 = spl[1].split(","); + const res = {}; + for (var i of _1) { + let _2 = i.split("="); + if (_2.length == 2) { + res[_2[0]] = _2[1]; + } else { + res[i] = null; + } + } + return res; +} +async function getUserData(couchDB) { + const username = getURLArgsMap()["user"]; + if (!username) return null; + const res = await couchDB.get("users"); + if (!res) return null; + const data = res[username]; + return !data ? null : { + ...data, + "name": username + }; +} +var userData = null; +async function setUserData(couchDB) { + const res = await getUserData(couchDB); + if (res == null) { + location.href = "../login.html"; + return false; + } + userData = res; + return true; +} \ No newline at end of file diff --git a/login.html b/login.html index b55ef5b..f5d7dde 100644 --- a/login.html +++ b/login.html @@ -25,7 +25,7 @@ async function getData() { async function login() { const data = await getData(); - const username = getId("username").value; + const username = getId("username").value.toLowerCase(); const password = getId("password").value; const user = data[username]; @@ -39,17 +39,9 @@ async function login() { return; } - location.href = "/uebersicht.html"; + location.href = "./prof/uebersicht.html?user=" + username; } -couchDB.set("users", { - turtle: { - password: "password", - level: 1, - isProf: true - } -}); - diff --git a/prof/uebersicht.html b/prof/uebersicht.html index e69de29..c42897a 100644 --- a/prof/uebersicht.html +++ b/prof/uebersicht.html @@ -0,0 +1,158 @@ + + + + + + + + +Übersicht + + + + + + + + + + + + +

+

+
+
+ +

+ +
+ + + + + \ No newline at end of file