This commit is contained in:
Dominic Grimm 2023-03-01 12:06:01 +01:00
parent df22d46260
commit 438920ece6
No known key found for this signature in database
GPG key ID: 6F294212DEAAC530
5 changed files with 217 additions and 240 deletions

View file

@ -48,9 +48,9 @@ pub mod keys {
#[serde(rename = "t")] #[serde(rename = "t")]
pub teachers: Option<Vec<String>>, pub teachers: Option<Vec<String>>,
#[serde(rename = "pr")] #[serde(rename = "pr")]
pub prev_room: Option<String>, pub prev_rooms: Vec<String>,
#[serde(rename = "r")] #[serde(rename = "r")]
pub room: Option<String>, pub rooms: Vec<String>,
#[serde(rename = "tx")] #[serde(rename = "tx")]
pub text: Option<String>, pub text: Option<String>,
} }

View file

@ -12,6 +12,7 @@ use std::io::Write;
use std::path::Path; use std::path::Path;
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use std::vec;
use crate::cache; use crate::cache;
use crate::config; use crate::config;
@ -84,7 +85,7 @@ async fn fetch_substitutions(
schoolyear_id, schoolyear_id,
date, date,
week_type, week_type,
queried_at: Utc::now().naive_utc(), queried_at: Local::now().naive_local(),
}) })
.returning(db::schema::substitution_queries::id) .returning(db::schema::substitution_queries::id)
.get_result::<i64>(db_conn)?; .get_result::<i64>(db_conn)?;
@ -315,41 +316,33 @@ fn cache_substitutions(
.order(db::schema::substitution_teachers::position.asc()) .order(db::schema::substitution_teachers::position.asc())
.load::<db::models::SubstitutionTeacher>(db_conn)?; .load::<db::models::SubstitutionTeacher>(db_conn)?;
let (prev_room, room) = if let Some(r) = db::schema::substitution_rooms::table let (prev_rooms, rooms) = {
let r: Vec<db::models::SubstitutionRoom> =
db::schema::substitution_rooms::table
.filter(db::schema::substitution_rooms::substitution_id.eq(s.id)) .filter(db::schema::substitution_rooms::substitution_id.eq(s.id))
.order(db::schema::substitution_rooms::position.asc()) .order(db::schema::substitution_rooms::position.asc())
.first::<db::models::SubstitutionRoom>(db_conn) .load::<db::models::SubstitutionRoom>(db_conn)?;
.optional()?
{ let prev_rooms = db::schema::rooms::table
let name = if let Some(id) = r.room_id {
Some(
db::schema::rooms::table
.select(db::schema::rooms::name) .select(db::schema::rooms::name)
.filter(db::schema::rooms::id.eq(id)) .filter(
.first::<String>(db_conn)?, db::schema::rooms::id
.eq_any(r.iter().flat_map(|x| x.original_id).collect::<Vec<i32>>()),
) )
} else { .load::<String>(db_conn)?;
None
}; 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::<Vec<i32>>()),
)
.load::<String>(db_conn)?;
match s.subst_type { match s.subst_type {
db::models::SubstitutionType::Cancel => (name, None), db::models::SubstitutionType::Cancel => (rooms, vec![]),
_ => ( _ => (prev_rooms, rooms),
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::<String>(db_conn)?,
)
} else {
None
},
name,
),
} }
} else {
(None, None)
}; };
let (prev_subject, subject) = { let (prev_subject, subject) = {
@ -406,9 +399,15 @@ fn cache_substitutions(
} }
} }
}, },
prev_room, prev_rooms,
room, rooms,
text: s.text, text: if s.text.is_none()
&& s.subst_type == db::models::SubstitutionType::RoomChange
{
Some("Raumänderung".to_string())
} else {
s.text
},
})) }))
} else { } else {
Ok(None) Ok(None)

View file

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="de-DE">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="generator" content="BVplan" />
<title>{% block title %}{% endblock %} | dergrimm.net</title>
<link rel="shortcut icon" href="/static/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png">
<link rel="manifest" href="/static/site.webmanifest">
{% block head %}{% endblock %}
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//matomo.dergrimm.net/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '6']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
</head>
<body>
{% block body %}{% endblock %}
</body>
</html>

View file

@ -1,18 +1,8 @@
<!DOCTYPE html> {% extends "base.html" %}
<html lang="de-DE">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="generator" content="BVplan" />
<title>BVplan | dergrimm.net</title>
<link rel="shortcut icon" href="/static/favicon.ico" /> {% block title %}BVplan{% endblock %}
<link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png">
<link rel="manifest" href="/static/site.webmanifest">
{% block head %}
<link rel="stylesheet" type="text/css" href="/static/css/bvplan.css" /> <link rel="stylesheet" type="text/css" href="/static/css/bvplan.css" />
<script id="data-element-count" type="application/json">{{ data.substitutions.len()|json|safe }}</script> <script id="data-element-count" type="application/json">{{ data.substitutions.len()|json|safe }}</script>
@ -23,24 +13,9 @@
crossorigin="anonymous" crossorigin="anonymous"
referrerpolicy="no-referrer" referrerpolicy="no-referrer"
></script> ></script>
{% endblock %}
<!-- Matomo --> {% block body %}
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//matomo.dergrimm.net/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '6']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
</head>
<body>
<header id="info"> <header id="info">
<div id="title-wrapper" class="column"> <div id="title-wrapper" class="column">
<h1 id="title">BVplan</h1> <h1 id="title">BVplan</h1>
@ -51,7 +26,7 @@
<br /> <br />
<span>Stand: {{ data.queried_at }}</span> <span>Stand: {{ data.queried_at }}</span>
<br /> <br />
<span>Untis: {{ data.last_import_time }}</span> <span>Vertretungsplan (offline): {{ data.last_import_time }}</span>
</div> </div>
</header> </header>
@ -115,20 +90,18 @@
{% endmatch %} {% endmatch %}
</td> </td>
<td> <td>
{% match subst.prev_room %} {% if subst.prev_rooms.is_empty() %}
{% when Some with (x) %}
{{ x }}
{% when None %}
--- ---
{% endmatch %} {% else %}
{{ subst.prev_rooms|join(", ") }}
{% endif %}
</td> </td>
<td> <td>
{% match subst.room %} {% if subst.rooms.is_empty() %}
{% when Some with (x) %}
{{ x }}
{% when None %}
--- ---
{% endmatch %} {% else %}
{{ subst.rooms|join(", ") }}
{% endif %}
</td> </td>
<td> <td>
{% match subst.text %} {% match subst.text %}
@ -167,5 +140,4 @@
</footer> </footer>
<script src="/static/js/bvplan.js"></script> <script src="/static/js/bvplan.js"></script>
</body> {% endblock %}
</html>

View file

@ -1,41 +1,10 @@
<!DOCTYPE html> {% extends "base.html" %}
<html lang="de-DE">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="generator" content="BVplan" />
<title>BVplan | dergrimm.net</title>
<link rel="shortcut icon" href="/static/favicon.ico" /> {% block title %}{{ status_code.as_str() }}{% endblock %}
<link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png">
<link rel="manifest" href="/static/site.webmanifest">
<style> {% block head %}{% endblock %}
body {
text-align: center;
}
</style>
<!-- Matomo --> {% block body %}
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//matomo.dergrimm.net/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '6']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
</head>
<body>
<h1>{{ status_code }}</h1> <h1>{{ status_code }}</h1>
{% match message %} {% match message %}
{% when Some with (x) %} {% when Some with (x) %}
@ -43,5 +12,5 @@
<p>{{ x }}</p> <p>{{ x }}</p>
{% when None %} {% when None %}
{% endmatch %} {% endmatch %}
</body> {% endblock %}
</html>