Initial commit
This commit is contained in:
commit
d303232201
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
1362
Cargo.lock
generated
Normal file
1362
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
18
Cargo.toml
Normal file
18
Cargo.toml
Normal file
@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "rocket_page"
|
||||
version = "0.1.0"
|
||||
authors = ["Dietrich <dietrich@teilgedanken.de>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rocket = "0.4.5"
|
||||
diesel = { version = "1.4.0", features = ["sqlite"] }
|
||||
serde_derive = "*"
|
||||
serde = "*"
|
||||
|
||||
[dependencies.rocket_contrib]
|
||||
version = "0.4.5"
|
||||
default-features = false
|
||||
features = ["diesel_sqlite_pool", "handlebars_templates"]
|
10
Rocket.toml
Normal file
10
Rocket.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[global.databases]
|
||||
page_db = { url = "database.sqlite" }
|
||||
|
||||
[development]
|
||||
address = "localhost"
|
||||
port = 8000
|
||||
workers = 8
|
||||
keep_alive = 5
|
||||
log = "normal"
|
||||
limits = { forms = 32768 }
|
BIN
database.sqlite
Normal file
BIN
database.sqlite
Normal file
Binary file not shown.
5
diesel.toml
Normal file
5
diesel.toml
Normal file
@ -0,0 +1,5 @@
|
||||
# For documentation on how to configure this file,
|
||||
# see diesel.rs/guides/configuring-diesel-cli
|
||||
|
||||
[print_schema]
|
||||
file = "src/schema.rs"
|
0
migrations/.gitkeep
Normal file
0
migrations/.gitkeep
Normal file
2
migrations/2020-07-18-191428_add_times/down.sql
Normal file
2
migrations/2020-07-18-191428_add_times/down.sql
Normal file
@ -0,0 +1,2 @@
|
||||
-- This file should undo anything in `up.sql`
|
||||
Drop TABLE stunden;
|
7
migrations/2020-07-18-191428_add_times/up.sql
Normal file
7
migrations/2020-07-18-191428_add_times/up.sql
Normal file
@ -0,0 +1,7 @@
|
||||
-- Your SQL goes here
|
||||
CREATE TABLE stunden (
|
||||
id Integer PRIMARY KEY NOT NULL,
|
||||
title Text NOT NULL,
|
||||
short Text NOT NULL,
|
||||
ordinal Integer NOT NULL
|
||||
);
|
2
migrations/2020-07-19-113511_add_klassen/down.sql
Normal file
2
migrations/2020-07-19-113511_add_klassen/down.sql
Normal file
@ -0,0 +1,2 @@
|
||||
-- This file should undo anything in `up.sql`
|
||||
Drop TABLE Klassen;
|
8
migrations/2020-07-19-113511_add_klassen/up.sql
Normal file
8
migrations/2020-07-19-113511_add_klassen/up.sql
Normal file
@ -0,0 +1,8 @@
|
||||
-- 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
|
||||
);
|
2
migrations/2020-07-19-144907_rename_column/down.sql
Normal file
2
migrations/2020-07-19-144907_rename_column/down.sql
Normal file
@ -0,0 +1,2 @@
|
||||
-- This file should undo anything in `up.sql`
|
||||
Alter Table klassen Rename Column ordnung to ordinal;
|
2
migrations/2020-07-19-144907_rename_column/up.sql
Normal file
2
migrations/2020-07-19-144907_rename_column/up.sql
Normal file
@ -0,0 +1,2 @@
|
||||
-- Your SQL goes here
|
||||
Alter Table klassen Rename Column ordinal to ordnung;
|
1
migrations/2020-07-23-093057_add_vertretung/down.sql
Normal file
1
migrations/2020-07-23-093057_add_vertretung/down.sql
Normal file
@ -0,0 +1 @@
|
||||
-- This file should undo anything in `up.sql`
|
11
migrations/2020-07-23-093057_add_vertretung/up.sql
Normal file
11
migrations/2020-07-23-093057_add_vertretung/up.sql
Normal file
@ -0,0 +1,11 @@
|
||||
-- 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)
|
||||
);
|
93
src/main.rs
Normal file
93
src/main.rs
Normal file
@ -0,0 +1,93 @@
|
||||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
#[macro_use]
|
||||
extern crate rocket_contrib;
|
||||
#[macro_use]
|
||||
extern crate diesel;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
pub mod models;
|
||||
pub mod schema;
|
||||
use crate::models::Klassen;
|
||||
use crate::schema::klassen;
|
||||
use diesel::RunQueryDsl;
|
||||
use rocket::request::{Form, FromParam};
|
||||
use rocket::response::Redirect;
|
||||
use rocket_contrib::databases;
|
||||
|
||||
use rocket_contrib::templates::Template;
|
||||
|
||||
struct StundenByID(i32);
|
||||
#[derive(Debug)]
|
||||
enum WebError {
|
||||
I32NotParsed,
|
||||
}
|
||||
|
||||
impl<'a> FromParam<'_> for StundenByID {
|
||||
type Error = WebError;
|
||||
fn from_param(param: &rocket::http::RawStr) -> Result<Self, Self::Error> {
|
||||
if let Ok(n) = param.parse::<i32>() {
|
||||
Ok(StundenByID(n))
|
||||
} else {
|
||||
Err(WebError::I32NotParsed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[database("page_db")]
|
||||
struct DbConn(databases::diesel::SqliteConnection);
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct ListAllContext {
|
||||
klassen: Vec<Klassen>,
|
||||
parent: String,
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
fn index(conn: DbConn) -> Template {
|
||||
Template::render(
|
||||
"uebersicht",
|
||||
ListAllContext {
|
||||
klassen: klassen::dsl::klassen.load(&*conn).expect("database acess"),
|
||||
parent: "base".to_string(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[get("/add/klasse")]
|
||||
fn get_klasse_form() -> Template {
|
||||
Template::render("add_klasse_form", "")
|
||||
}
|
||||
|
||||
#[derive(FromForm, Insertable)]
|
||||
#[table_name = "klassen"]
|
||||
struct KlasseForm {
|
||||
stufe: i32,
|
||||
gruppe: String,
|
||||
titel: Option<String>,
|
||||
ordnung: i32,
|
||||
}
|
||||
|
||||
#[post("/add/klasse", data = "<klasse>")]
|
||||
fn post_klasse_form(klasse: Form<KlasseForm>, conn: DbConn) -> Result<Redirect, String> {
|
||||
match diesel::insert_into(schema::klassen::table)
|
||||
.values(klasse.into_inner())
|
||||
.execute(&*conn)
|
||||
{
|
||||
Ok(_) => Ok(Redirect::to("/admin/add/klasse")),
|
||||
Err(_) => Err("Klasse konnte nicht erstellt werden!".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
rocket::ignite()
|
||||
.attach(DbConn::fairing())
|
||||
.attach(Template::fairing())
|
||||
.mount("/", routes![index])
|
||||
.mount("/admin/", routes![get_klasse_form])
|
||||
.mount("/admin/", routes![post_klasse_form])
|
||||
.launch();
|
||||
}
|
37
src/models.rs
Normal file
37
src/models.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use super::schema::klassen;
|
||||
|
||||
#[derive(Queryable, Debug, Serialize)]
|
||||
pub struct Stunden {
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
pub short: String,
|
||||
pub ordinal: i32,
|
||||
}
|
||||
|
||||
#[derive(Queryable, Debug, Serialize)]
|
||||
pub struct Vertretungen {
|
||||
pub id: i32,
|
||||
pub klasse_link: i32,
|
||||
pub stunde_link: i32,
|
||||
pub fehlend: String,
|
||||
pub vertretung: String,
|
||||
pub kommentar: String,
|
||||
}
|
||||
|
||||
#[derive(Queryable, Debug, Serialize)]
|
||||
pub struct Klassen {
|
||||
pub id: i32,
|
||||
pub stufe: i32,
|
||||
pub gruppe: String,
|
||||
pub titel: Option<String>,
|
||||
pub ordnung: i32,
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[table_name = "klassen"]
|
||||
pub struct NewKlassen {
|
||||
pub stufe: i32,
|
||||
pub gruppe: String,
|
||||
pub titel: Option<String>,
|
||||
pub ordnung: i32,
|
||||
}
|
31
src/schema.rs
Normal file
31
src/schema.rs
Normal file
@ -0,0 +1,31 @@
|
||||
table! {
|
||||
vertretungen (id) {
|
||||
id -> Integer,
|
||||
klasse -> Integer,
|
||||
stunde -> Integer,
|
||||
fehlend -> Text,
|
||||
vertretung -> Text,
|
||||
kommentar -> Text,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
klassen (id) {
|
||||
id -> Integer,
|
||||
stufe -> Integer,
|
||||
gruppe -> Text,
|
||||
titel -> Nullable<Text>,
|
||||
ordnung -> Integer,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
stunden (id) {
|
||||
id -> Integer,
|
||||
title -> Text,
|
||||
short -> Text,
|
||||
ordinal -> Integer,
|
||||
}
|
||||
}
|
||||
|
||||
allow_tables_to_appear_in_same_query!(vertretungen, klassen, stunden,);
|
29
templates/add_klasse_form.hbs
Normal file
29
templates/add_klasse_form.hbs
Normal file
@ -0,0 +1,29 @@
|
||||
{{#* inline "page"}}
|
||||
<h1>Login</h1>
|
||||
<form action="/admin/add/klasse" method="post" accept-charset="utf-8">
|
||||
<table>
|
||||
<tr>
|
||||
<th>Stufe:</th>
|
||||
<td><input type="number" name="stufe"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Teil:</th>
|
||||
<td><input type="text" name="gruppe"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Titel:</th>
|
||||
<td><input type="text" name="titel"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Ordnung:</th>
|
||||
<td><input type="number" name="ordnung"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td><input type="submit" value="Klasse Erstellen"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
{{/inline}}
|
||||
{{! remove whitespaces with ~ }}
|
||||
{{~> (parent)~}}
|
17
templates/base.hbs
Normal file
17
templates/base.hbs
Normal file
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="/static/style.css" />
|
||||
<style>
|
||||
</style>
|
||||
<meta charset="utf-8">
|
||||
<title>Vertretungsplan Uhlandshöhe</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{{~> page}}
|
||||
<h3> End</h3>
|
||||
</body>
|
||||
|
||||
</html>
|
10
templates/uebersicht.hbs
Normal file
10
templates/uebersicht.hbs
Normal file
@ -0,0 +1,10 @@
|
||||
{{#* inline "page"}}
|
||||
<h1>Stundenplan</h1>
|
||||
<ul>
|
||||
{{#each klassen}}
|
||||
<li>{{this.id}}. {{this.stufe}}{{this.gruppe}}</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{/inline}}
|
||||
{{! remove whitespaces with ~ }}
|
||||
{{~> (parent)~}}
|
Loading…
Reference in New Issue
Block a user