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")]
pub teachers: Option<Vec<String>>,
#[serde(rename = "pr")]
pub prev_room: Option<String>,
pub prev_rooms: Vec<String>,
#[serde(rename = "r")]
pub room: Option<String>,
pub rooms: Vec<String>,
#[serde(rename = "tx")]
pub text: Option<String>,
}

View file

@ -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::<i64>(db_conn)?;
@ -315,41 +316,33 @@ fn cache_substitutions(
.order(db::schema::substitution_teachers::position.asc())
.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))
.order(db::schema::substitution_rooms::position.asc())
.first::<db::models::SubstitutionRoom>(db_conn)
.optional()?
{
let name = if let Some(id) = r.room_id {
Some(
db::schema::rooms::table
.load::<db::models::SubstitutionRoom>(db_conn)?;
let prev_rooms = db::schema::rooms::table
.select(db::schema::rooms::name)
.filter(db::schema::rooms::id.eq(id))
.first::<String>(db_conn)?,
.filter(
db::schema::rooms::id
.eq_any(r.iter().flat_map(|x| x.original_id).collect::<Vec<i32>>()),
)
} else {
None
};
.load::<String>(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::<Vec<i32>>()),
)
.load::<String>(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::<String>(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)

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>
<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>
{% extends "base.html" %}
<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 title %}BVplan{% endblock %}
{% block head %}
<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>
@ -23,24 +13,9 @@
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
{% 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 %}
<header id="info">
<div id="title-wrapper" class="column">
<h1 id="title">BVplan</h1>
@ -51,7 +26,7 @@
<br />
<span>Stand: {{ data.queried_at }}</span>
<br />
<span>Untis: {{ data.last_import_time }}</span>
<span>Vertretungsplan (offline): {{ data.last_import_time }}</span>
</div>
</header>
@ -115,20 +90,18 @@
{% endmatch %}
</td>
<td>
{% match subst.prev_room %}
{% when Some with (x) %}
{{ x }}
{% when None %}
{% if subst.prev_rooms.is_empty() %}
---
{% endmatch %}
{% else %}
{{ subst.prev_rooms|join(", ") }}
{% endif %}
</td>
<td>
{% match subst.room %}
{% when Some with (x) %}
{{ x }}
{% when None %}
{% if subst.rooms.is_empty() %}
---
{% endmatch %}
{% else %}
{{ subst.rooms|join(", ") }}
{% endif %}
</td>
<td>
{% match subst.text %}
@ -167,5 +140,4 @@
</footer>
<script src="/static/js/bvplan.js"></script>
</body>
</html>
{% endblock %}

View file

@ -1,41 +1,10 @@
<!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>BVplan | dergrimm.net</title>
{% extends "base.html" %}
<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 title %}{{ status_code.as_str() }}{% endblock %}
<style>
body {
text-align: center;
}
</style>
{% 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 %}
<h1>{{ status_code }}</h1>
{% match message %}
{% when Some with (x) %}
@ -43,5 +12,5 @@
<p>{{ x }}</p>
{% when None %}
{% endmatch %}
</body>
</html>
{% endblock %}