From 438920ece6982c368785f608564ebe123c8d7092 Mon Sep 17 00:00:00 2001 From: Dominic Grimm Date: Wed, 1 Mar 2023 12:06:01 +0100 Subject: [PATCH] Update --- bvplan/src/cache.rs | 4 +- bvplan/src/worker/get_substitutions.rs | 69 +++--- bvplan/templates/base.html | 37 ++++ bvplan/templates/bvplan.html | 290 +++++++++++-------------- bvplan/templates/status_code.html | 57 ++--- 5 files changed, 217 insertions(+), 240 deletions(-) create mode 100644 bvplan/templates/base.html diff --git a/bvplan/src/cache.rs b/bvplan/src/cache.rs index 9eec57e..64012f5 100644 --- a/bvplan/src/cache.rs +++ b/bvplan/src/cache.rs @@ -48,9 +48,9 @@ pub mod keys { #[serde(rename = "t")] pub teachers: Option>, #[serde(rename = "pr")] - pub prev_room: Option, + pub prev_rooms: Vec, #[serde(rename = "r")] - pub room: Option, + pub rooms: Vec, #[serde(rename = "tx")] pub text: Option, } diff --git a/bvplan/src/worker/get_substitutions.rs b/bvplan/src/worker/get_substitutions.rs index 061273c..c6b291e 100644 --- a/bvplan/src/worker/get_substitutions.rs +++ b/bvplan/src/worker/get_substitutions.rs @@ -12,6 +12,7 @@ use std::io::Write; use std::path::Path; use std::thread; use std::time::Duration; +use std::vec; use crate::cache; use crate::config; @@ -84,7 +85,7 @@ async fn fetch_substitutions( schoolyear_id, date, week_type, - queried_at: Utc::now().naive_utc(), + queried_at: Local::now().naive_local(), }) .returning(db::schema::substitution_queries::id) .get_result::(db_conn)?; @@ -315,41 +316,33 @@ fn cache_substitutions( .order(db::schema::substitution_teachers::position.asc()) .load::(db_conn)?; - let (prev_room, room) = if let Some(r) = db::schema::substitution_rooms::table - .filter(db::schema::substitution_rooms::substitution_id.eq(s.id)) - .order(db::schema::substitution_rooms::position.asc()) - .first::(db_conn) - .optional()? - { - let name = if let Some(id) = r.room_id { - Some( - db::schema::rooms::table - .select(db::schema::rooms::name) - .filter(db::schema::rooms::id.eq(id)) - .first::(db_conn)?, + let (prev_rooms, rooms) = { + let r: Vec = + db::schema::substitution_rooms::table + .filter(db::schema::substitution_rooms::substitution_id.eq(s.id)) + .order(db::schema::substitution_rooms::position.asc()) + .load::(db_conn)?; + + let prev_rooms = db::schema::rooms::table + .select(db::schema::rooms::name) + .filter( + db::schema::rooms::id + .eq_any(r.iter().flat_map(|x| x.original_id).collect::>()), ) - } else { - None - }; + .load::(db_conn)?; + + let rooms = db::schema::rooms::table + .select(db::schema::rooms::name) + .filter( + db::schema::rooms::id + .eq_any(r.iter().flat_map(|x| x.room_id).collect::>()), + ) + .load::(db_conn)?; match s.subst_type { - db::models::SubstitutionType::Cancel => (name, None), - _ => ( - if let Some(id) = r.original_id { - Some( - db::schema::rooms::table - .select(db::schema::rooms::name) - .filter(db::schema::rooms::id.eq(id)) - .first::(db_conn)?, - ) - } else { - None - }, - name, - ), + db::models::SubstitutionType::Cancel => (rooms, vec![]), + _ => (prev_rooms, rooms), } - } else { - (None, None) }; let (prev_subject, subject) = { @@ -406,9 +399,15 @@ fn cache_substitutions( } } }, - prev_room, - room, - text: s.text, + prev_rooms, + rooms, + text: if s.text.is_none() + && s.subst_type == db::models::SubstitutionType::RoomChange + { + Some("Raumänderung".to_string()) + } else { + s.text + }, })) } else { Ok(None) diff --git a/bvplan/templates/base.html b/bvplan/templates/base.html new file mode 100644 index 0000000..d047e50 --- /dev/null +++ b/bvplan/templates/base.html @@ -0,0 +1,37 @@ + + + + + + + + {% block title %}{% endblock %} | dergrimm.net + + + + + + + + {% block head %}{% endblock %} + + + + + + + {% block body %}{% endblock %} + + diff --git a/bvplan/templates/bvplan.html b/bvplan/templates/bvplan.html index 49e9b70..a7e5200 100644 --- a/bvplan/templates/bvplan.html +++ b/bvplan/templates/bvplan.html @@ -1,171 +1,143 @@ - - - - - - - - BVplan | dergrimm.net +{% extends "base.html" %} - - - - - +{% block title %}BVplan{% endblock %} - +{% block head %} + - + - + +{% endblock %} - - - - - -
-
-

BVplan

- dergrimm.net -
-
- {{ data.tenant }}, {{ data.schoolyear }} -
- Stand: {{ data.queried_at }} -
- Untis: {{ data.last_import_time }} -
-
+{% block body %} +
+
+

BVplan

+ dergrimm.net +
+
+ {{ data.tenant }}, {{ data.schoolyear }} +
+ Stand: {{ data.queried_at }} +
+ Vertretungsplan (offline): {{ data.last_import_time }} +
+
-
- - +
+
- {{ data.date }}, Woche {{ data.week_type }} -
+ - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - {% for subst in data.substitutions %} - - - - - - - - - - - {% endfor %} - -
+ {{ data.date }}, Woche {{ data.week_type }} +
StundeKlasse(n)(Fach)FachVertreter(Raum)RaumText
StundeKlasse(n)(Fach)FachVertreter(Raum)RaumText
{{ subst.period }}{{ subst.classes|join(", ") }} - {% match subst.prev_subject %} - {% when Some with (x) %} - {{ x }} - {% when None %} - --- - {% endmatch %} - - {% match subst.subject %} - {% when Some with (x) %} - {{ x }} - {% when None %} - --- - {% endmatch %} - - {% match subst.teachers %} - {% when Some with (x) %} - {{ x|join(", ") }} - {% when None %} - --- - {% endmatch %} - - {% match subst.prev_room %} - {% when Some with (x) %} - {{ x }} - {% when None %} - --- - {% endmatch %} - - {% match subst.room %} - {% when Some with (x) %} - {{ x }} - {% when None %} - --- - {% endmatch %} - - {% match subst.text %} - {% when Some with (x) %} - {{ x }} - {% when None %} - {% endmatch %} -
-
+ + {% for subst in data.substitutions %} + + {{ subst.period }} + {{ subst.classes|join(", ") }} + + {% match subst.prev_subject %} + {% when Some with (x) %} + {{ x }} + {% when None %} + --- + {% endmatch %} + + + {% match subst.subject %} + {% when Some with (x) %} + {{ x }} + {% when None %} + --- + {% endmatch %} + + + {% match subst.teachers %} + {% when Some with (x) %} + {{ x|join(", ") }} + {% when None %} + --- + {% endmatch %} + + + {% if subst.prev_rooms.is_empty() %} + --- + {% else %} + {{ subst.prev_rooms|join(", ") }} + {% endif %} + + + {% if subst.rooms.is_empty() %} + --- + {% else %} + {{ subst.rooms|join(", ") }} + {% endif %} + + + {% match subst.text %} + {% when Some with (x) %} + {{ x }} + {% when None %} + {% endmatch %} + + + {% endfor %} + + + - - - - + +{% endblock %} diff --git a/bvplan/templates/status_code.html b/bvplan/templates/status_code.html index d65d26d..8bd04b7 100644 --- a/bvplan/templates/status_code.html +++ b/bvplan/templates/status_code.html @@ -1,47 +1,16 @@ - - - - - - - - BVplan | dergrimm.net +{% extends "base.html" %} - - - - - +{% block title %}{{ status_code.as_str() }}{% endblock %} - +{% block head %}{% endblock %} + +{% block body %} +

{{ status_code }}

+ {% match message %} + {% when Some with (x) %} +
+

{{ x }}

+ {% when None %} + {% endmatch %} +{% endblock %} - - - - - -

{{ status_code }}

- {% match message %} - {% when Some with (x) %} -
-

{{ x }}

- {% when None %} - {% endmatch %} - -