diff options
-rw-r--r-- | CLI.md | 13 | ||||
-rwxr-xr-x | cli.js | 20 | ||||
-rw-r--r-- | db.js | 12 | ||||
-rw-r--r-- | profile/public/user.js | 4 | ||||
-rw-r--r-- | tables.sql | 2 | ||||
-rw-r--r-- | zeitung/.gitignore | 3 | ||||
-rw-r--r-- | zeitung/parts/studentprofiles.tex | 6 | ||||
-rw-r--r-- | zeitung/parts/students/TGI13.1/.gitkeep (renamed from zeitung/parts/students/.gitkeep) | 0 | ||||
-rw-r--r-- | zeitung/parts/students/TGI13.2/.gitkeep | 0 | ||||
-rw-r--r-- | zeitung/parts/students/TGM13.1/.gitkeep | 0 | ||||
-rw-r--r-- | zeitung/parts/students/TGM13.2/.gitkeep | 0 | ||||
-rw-r--r-- | zeitung/parts/students/TGTM13.1/.gitkeep | 0 | ||||
-rw-r--r-- | zeitung/parts/studenttemplate.tex | 15 |
13 files changed, 64 insertions, 11 deletions
@@ -3,10 +3,17 @@ `node cli.js [option] [param]` ## -r -Recreates and reinitializes database tables: `node -r [all|motto|poll|profile|quote]` + +Recreates and reinitializes database tables: `node cli -r [all|motto|poll|profile|quote]` + +## -d + +Dump the database into a LaTeX-compatible format `node cli -d` (in the appropriate `zeitung` subdir) ## -U -Updates database values: `node -U [all|motto|poll|profile]` + +Updates database values: `node cli -U [all|motto|poll|profile]` ## --user -Regenerates user password: `node --user [user_id]`
\ No newline at end of file + +Regenerates user password: `node cli --user [user_id]` @@ -1,6 +1,7 @@ #!/usr/bin/env node require("dotenv").config(); const db = require("./db"); +const fs = require("fs"); const params = process.argv.slice(2); @@ -56,6 +57,25 @@ if ((idx = params.indexOf("-r")) > -1) { process.exit(0); break; } +} else if ((idx = params.indexOf("-d")) > -1) { + // TODO: More dumping + db.dump().then((data) => { + data.users.forEach((user) => { + const textex = `\\student\n\\studentimages{${user.username}}\n\\studentprofile{${user.name} ${ + user.middlename || "" + } ${ + user.surname + }}{18.12.2002}{Mathematik}{Schlafen}{Canadian Pop}{Herr Schwarz}{Gehirn}{Cogito ergo sum}\n\\studenttable{Meistens wunderhübsch}{Essen}`; + fs.writeFile( + __dirname + "/zeitung/parts/students/" + user.class + "/" + user.username + ".tex", + textex, + (err) => { + if (err) console.error(err); + }, + ); + }); + }); + console.log("Probably finished.. Async?"); } else if ((idx = params.indexOf("-U")) > -1) { // Update management (e.g.: add new poll options) const param = params[idx + 1]; @@ -185,7 +185,10 @@ class DB { const [q, a] = question.split(" - "); const { insertId } = await this.query("INSERT INTO question_questions (question) VALUE (?)", [q]); for (const answer of a.split(",")) { - await this.query("INSERT INTO question_options (answer_option, question_id) VALUE (?,?)", [answer, insertId]); + await this.query("INSERT INTO question_options (answer_option, question_id) VALUE (?,?)", [ + answer, + insertId, + ]); } } catch (e) { console.error(e); @@ -218,6 +221,13 @@ class DB { console.log(`New password for ${uid}: ${pwd}`); } + async dump() { + const users = await this.query( + "SELECT u.id, u.username, u.name, u.middlename, u.surname, c.name class, t.name type FROM users u INNER JOIN class c ON u.class_id = c.id INNER JOIN types t ON u.type_id = t.id WHERE t.name = 'pupil'", + ); + return { users }; + } + async query(query, params) { const conn = await this.connect(); try { diff --git a/profile/public/user.js b/profile/public/user.js index b0eb768..39d6713 100644 --- a/profile/public/user.js +++ b/profile/public/user.js @@ -171,7 +171,7 @@ function addChar(char) { inp.maxLength = 255; - btn.addEventListener("click", async e => { + btn.addEventListener("click", async (e) => { const char = inp.value; const body = JSON.stringify({ char }); await fetch(`api/char/${uid}`, { @@ -196,4 +196,4 @@ fetch(`api/comments/${uid}`) fetch(`api/char/${uid}`) .then((response) => response.json()) - .then(addChar);
\ No newline at end of file + .then(addChar); @@ -175,4 +175,4 @@ CREATE TABLE IF NOT EXISTS profile_char 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 + DEFAULT CHARSET = utf8; diff --git a/zeitung/.gitignore b/zeitung/.gitignore index 7f25e83..de1a9bd 100644 --- a/zeitung/.gitignore +++ b/zeitung/.gitignore @@ -1,5 +1,6 @@ build/ *.log svg-inkscape/ -parts/students/*.tex +parts/students/*/*.tex parts/students/figures/ +parts/test/ diff --git a/zeitung/parts/studentprofiles.tex b/zeitung/parts/studentprofiles.tex index dcb3cb6..67d69d0 100644 --- a/zeitung/parts/studentprofiles.tex +++ b/zeitung/parts/studentprofiles.tex @@ -2,4 +2,8 @@ \kant[1-3] \newpage -\inputall{parts/students/} +\inputall{parts/students/TGI13.1} +\inputall{parts/students/TGI13.2} +\inputall{parts/students/TGM13.1} +\inputall{parts/students/TGM13.2} +\inputall{parts/students/TGTM13.1} diff --git a/zeitung/parts/students/.gitkeep b/zeitung/parts/students/TGI13.1/.gitkeep index e69de29..e69de29 100644 --- a/zeitung/parts/students/.gitkeep +++ b/zeitung/parts/students/TGI13.1/.gitkeep diff --git a/zeitung/parts/students/TGI13.2/.gitkeep b/zeitung/parts/students/TGI13.2/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/zeitung/parts/students/TGI13.2/.gitkeep diff --git a/zeitung/parts/students/TGM13.1/.gitkeep b/zeitung/parts/students/TGM13.1/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/zeitung/parts/students/TGM13.1/.gitkeep diff --git a/zeitung/parts/students/TGM13.2/.gitkeep b/zeitung/parts/students/TGM13.2/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/zeitung/parts/students/TGM13.2/.gitkeep diff --git a/zeitung/parts/students/TGTM13.1/.gitkeep b/zeitung/parts/students/TGTM13.1/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/zeitung/parts/students/TGTM13.1/.gitkeep diff --git a/zeitung/parts/studenttemplate.tex b/zeitung/parts/studenttemplate.tex index 72e7763..2f3e3b0 100644 --- a/zeitung/parts/studenttemplate.tex +++ b/zeitung/parts/studenttemplate.tex @@ -2,6 +2,17 @@ \clearpage +% Returns a default file if not found +\providecommand\dfincludegraphics[2][]{ + \IfFileExists{#2} + { + \includegraphics[#1]{#2} + } + { + %\fbox{File not found} + } +} + \providecommand\studentimages[1]{% % Ring \def\ringx{50pt} @@ -12,7 +23,7 @@ \AddToShipoutPictureBG*{ \AtTextUpperLeft{ \put(-\ringx + \ringoffset, -\ringy + \ringoffset){ - \includegraphics[keepaspectratio=true, width=\ringimgwidth]{parts/students/figures/#1.jpg} + \dfincludegraphics[keepaspectratio=true, width=\ringimgwidth]{parts/students/figures/#1.jpg} } \put(-\ringx, -\ringy){ \includegraphics[keepaspectratio=true, width=\ringwidth]{ring.png} @@ -29,7 +40,7 @@ \AddToShipoutPictureBG*{ \AtTextLowerLeft{ \put(\textwidth - \framex + \frameoffset, \framey + \frameoffset){ - \includegraphics[keepaspectratio=true, width=\frameimgwidth]{parts/students/figures/#1_child.jpg} + \dfincludegraphics[keepaspectratio=true, width=\frameimgwidth]{parts/students/figures/#1_child.jpg} } \put(\textwidth - \framex, \framey){ \includegraphics[keepaspectratio=true, width=\framewidth]{rahmen.png} |