From a315bb84a498d23b2e91c5e1682dab5bc1862379 Mon Sep 17 00:00:00 2001 From: Dietrich Date: Fri, 24 Jul 2020 21:43:05 +0200 Subject: [PATCH] Add style and prepare relationships --- .vscode/launch.json | 45 +++++++++ Cargo.toml | 10 +- database.sqlite | Bin 24576 -> 24576 bytes migrations/2020-07-18-191428_add_times/up.sql | 3 +- .../2020-07-19-113511_add_klassen/up.sql | 15 +-- .../2020-07-19-144907_rename_column/down.sql | 4 +- .../2020-07-19-144907_rename_column/up.sql | 4 +- .../2020-07-23-093057_add_vertretung/down.sql | 5 +- .../2020-07-23-093057_add_vertretung/up.sql | 21 +++-- src/main.rs | 6 +- src/models.rs | 14 ++- src/schema.rs | 4 +- static/style.css | 88 ++++++++++++++++++ templates/add_klasse_form.hbs | 2 +- templates/uebersicht.hbs | 2 +- 15 files changed, 189 insertions(+), 34 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 static/style.css diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5c1ca42 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,45 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'rocket_page'", + "cargo": { + "args": [ + "build", + "--bin=rocket_page", + "--package=rocket_page" + ], + "filter": { + "name": "rocket_page", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'rocket_page'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=rocket_page", + "--package=rocket_page" + ], + "filter": { + "name": "rocket_page", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index b8800c8..521e1ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,11 +8,11 @@ edition = "2018" [dependencies] rocket = "0.4.5" -diesel = { version = "1.4.0", features = ["sqlite"] } -serde_derive = "*" -serde = "*" +diesel = { version = "1.4", features = ["sqlite"] } +serde_derive = "1.0" +serde = "1.0" [dependencies.rocket_contrib] -version = "0.4.5" +version = "0.4" default-features = false -features = ["diesel_sqlite_pool", "handlebars_templates"] +features = ["diesel_sqlite_pool", "handlebars_templates", "serve"] diff --git a/database.sqlite b/database.sqlite index fae059e65a475e63426753ec726f39b7b5473148..8cd686ce0ac51ab226422fcafdc4f601079434ef 100644 GIT binary patch delta 121 zcmZoTz}Rqrae}mX%EWYY IpL~%609bb&p#T5? delta 110 zcmZoTz}Rqrae}m<2m=EH8v_FHPt-9M7h%wIKFrJigMpRDnt|^o|6)FK-X8Jk;~8f@;9 HFLD3?`%oFR diff --git a/migrations/2020-07-18-191428_add_times/up.sql b/migrations/2020-07-18-191428_add_times/up.sql index ef86edd..0f9740f 100644 --- a/migrations/2020-07-18-191428_add_times/up.sql +++ b/migrations/2020-07-18-191428_add_times/up.sql @@ -1,5 +1,6 @@ -- Your SQL goes here -CREATE TABLE stunden ( +CREATE TABLE stunden +( id Integer PRIMARY KEY NOT NULL, title Text NOT NULL, short Text NOT NULL, diff --git a/migrations/2020-07-19-113511_add_klassen/up.sql b/migrations/2020-07-19-113511_add_klassen/up.sql index 80f0ed7..87ece20 100644 --- a/migrations/2020-07-19-113511_add_klassen/up.sql +++ b/migrations/2020-07-19-113511_add_klassen/up.sql @@ -1,8 +1,11 @@ -- Your SQL goes here -CREATE TABLE klassen ( - id Integer PRIMARY KEY NOT NULL, - stufe Integer not null, - gruppe Text NOT NULL, - titel Text, - ordinal Integer NOT NULL + +CREATE TABLE klassen +( + id Integer PRIMARY KEY NOT NULL, + stufe Integer NOT NULL, + gruppe Text NOT NULL, + titel Text, + ordinal Integer NOT NULL ); + diff --git a/migrations/2020-07-19-144907_rename_column/down.sql b/migrations/2020-07-19-144907_rename_column/down.sql index efd2142..8ba6f7e 100644 --- a/migrations/2020-07-19-144907_rename_column/down.sql +++ b/migrations/2020-07-19-144907_rename_column/down.sql @@ -1,2 +1,4 @@ -- This file should undo anything in `up.sql` -Alter Table klassen Rename Column ordnung to ordinal; + +ALTER TABLE klassen RENAME COLUMN ordnung TO ordinal; + diff --git a/migrations/2020-07-19-144907_rename_column/up.sql b/migrations/2020-07-19-144907_rename_column/up.sql index 3074e59..baeec3c 100644 --- a/migrations/2020-07-19-144907_rename_column/up.sql +++ b/migrations/2020-07-19-144907_rename_column/up.sql @@ -1,2 +1,4 @@ -- Your SQL goes here -Alter Table klassen Rename Column ordinal to ordnung; + +ALTER TABLE klassen RENAME COLUMN ordinal TO ordnung; + diff --git a/migrations/2020-07-23-093057_add_vertretung/down.sql b/migrations/2020-07-23-093057_add_vertretung/down.sql index 291a97c..f4194de 100644 --- a/migrations/2020-07-23-093057_add_vertretung/down.sql +++ b/migrations/2020-07-23-093057_add_vertretung/down.sql @@ -1 +1,4 @@ --- This file should undo anything in `up.sql` \ No newline at end of file +-- This file should undo anything in `up.sql` + +DROP TABLE Vertretungen; + diff --git a/migrations/2020-07-23-093057_add_vertretung/up.sql b/migrations/2020-07-23-093057_add_vertretung/up.sql index 3af3d71..df6adef 100644 --- a/migrations/2020-07-23-093057_add_vertretung/up.sql +++ b/migrations/2020-07-23-093057_add_vertretung/up.sql @@ -1,11 +1,14 @@ -- Your SQL -CREATE TABLE Vertretungen ( - id Integer PRIMARY KEY NOT NULL, - klasse Integer not null, - stunde Integer not null, - fehlend Text NOT NULL, - vertretung Text NOT NULL, - kommentar Text NOT NULL, - FOREIGN KEY(klasse) REFERENCES klasse(id), - FOREIGN KEY(stunde) REFERENCES stunde(id) + +CREATE TABLE Vertretungen +( + id Integer PRIMARY KEY NOT NULL, + klassen_id Integer NOT NULL, + stunden_id Integer NOT NULL, + fehlend Text NOT NULL, + vertretung Text NOT NULL, + kommentar Text NOT NULL, + FOREIGN KEY(klasse_id) REFERENCES klasse(id), + FOREIGN KEY(stunde_id) REFERENCES stunde(id) ); + diff --git a/src/main.rs b/src/main.rs index 7bf13f3..cf083af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ use diesel::RunQueryDsl; use rocket::request::{Form, FromParam}; use rocket::response::Redirect; use rocket_contrib::databases; - +use rocket_contrib::serve::StaticFiles; use rocket_contrib::templates::Template; struct StundenByID(i32); @@ -86,6 +86,10 @@ fn main() { rocket::ignite() .attach(DbConn::fairing()) .attach(Template::fairing()) + .mount( + "/static", + StaticFiles::from(concat!(env!("CARGO_MANIFEST_DIR"), "/static")), + ) .mount("/", routes![index]) .mount("/admin/", routes![get_klasse_form]) .mount("/admin/", routes![post_klasse_form]) diff --git a/src/models.rs b/src/models.rs index d471e4a..add47fd 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,4 +1,4 @@ -use super::schema::klassen; +use super::schema::{klassen, vertretungen}; #[derive(Queryable, Debug, Serialize)] pub struct Stunden { @@ -8,17 +8,21 @@ pub struct Stunden { pub ordinal: i32, } -#[derive(Queryable, Debug, Serialize)] +#[derive(Identifiable, Queryable, Debug, Serialize, Associations)] +#[belongs_to(Klassen)] +#[belongs_to(Stunden)] +#[table_name = "vertretungen"] pub struct Vertretungen { pub id: i32, - pub klasse_link: i32, - pub stunde_link: i32, + pub klassen_id: i32, + pub stunden_id: i32, pub fehlend: String, pub vertretung: String, pub kommentar: String, } -#[derive(Queryable, Debug, Serialize)] +#[derive(Identifiable, Queryable, Debug, Serialize)] +#[table_name = "klassen"] pub struct Klassen { pub id: i32, pub stufe: i32, diff --git a/src/schema.rs b/src/schema.rs index 1a3c171..5972880 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -1,8 +1,8 @@ table! { vertretungen (id) { id -> Integer, - klasse -> Integer, - stunde -> Integer, + klassen_id -> Integer, + stunden_id -> Integer, fehlend -> Text, vertretung -> Text, kommentar -> Text, diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..bf508da --- /dev/null +++ b/static/style.css @@ -0,0 +1,88 @@ + + +body{ + background-color: #23272a; + max-width: 880px; + margin: auto; + color: white; +} + +h1 { + text-align: center; + font-size: 60px; +} + +a:hover { + color: #16e0b8; +} + +a:visited { + color: #fcb6b6; +} +.grid-container { + display: grid; + grid-template-columns: auto auto auto auto; + grid-gap: 30px; + padding: 10px; + background-color: #23272a; + align-items: stretch; +} + +.grid-item div { + display: table-cell; + border: 1px solid #ccc; + font-size: 48px; + box-shadow: 2px 2px 6px 0px rgba(0, 0, 0, 0.2); + max-width: 100%; + width: 215px; + height: 200px; + margin: auto; + text-align: center; + line-height: 200px; + background-color: #2c2f33; +} + +.grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); + grid-gap: 20px; + align-items: stretch; + max-width: 500px; + margin: auto; +} + +.grid div { + display: table-cell; + border: 3px solid #ccc; + font-size: 16px; + box-shadow: 2px 2px 6px 0px rgba(0, 0, 0, 0.5); + max-width: 100%; + width: 200px; + height: 100px; + margin: center; + text-align: center; + padding: 10px; + align-items: center; + font-size: 20px; + font-family: Helvetica; + font-weight: bold; + background-color: #2c2f33; +} + +div.Fach { + display: table-cell; + border: 3px solid #ccc; + font-size: 16px; + box-shadow: 2px 2px 6px 0px rgba(0, 0, 0, 0.5); + max-width: 100%; + width: 200px; + height: 100px; + margin: center; + text-align: center; + padding: 10px; + align-items: center; + font-size: 20px; + font-family: Helvetica; + font-weight: bold; + background-color: #081B33; +} diff --git a/templates/add_klasse_form.hbs b/templates/add_klasse_form.hbs index 08a34fb..d66f18b 100644 --- a/templates/add_klasse_form.hbs +++ b/templates/add_klasse_form.hbs @@ -1,5 +1,5 @@ {{#* inline "page"}} -

Login

+

Klasse hinzu fügen

diff --git a/templates/uebersicht.hbs b/templates/uebersicht.hbs index b7822ec..63fd880 100644 --- a/templates/uebersicht.hbs +++ b/templates/uebersicht.hbs @@ -1,5 +1,5 @@ {{#* inline "page"}} -

Stundenplan

+

Vertretungen

    {{#each klassen}}
  • {{this.id}}. {{this.stufe}}{{this.gruppe}}