allow showing stat in kiosk mode

This commit is contained in:
philipp 2023-10-01 20:50:23 +02:00
parent fb503dda6e
commit a96bd81691
3 changed files with 20 additions and 5 deletions

View File

@ -84,7 +84,7 @@ async fn show(db: &State<SqlitePool>, user: User) -> Template {
}
#[get("/show")]
async fn show_kiosk(db: &State<SqlitePool>, _kios: KioskCookie) -> Template {
async fn show_kiosk(db: &State<SqlitePool>, _kiosk: KioskCookie) -> Template {
let logs = Logbook::completed(db).await;
Template::render("log.completed", context!(logs))

View File

@ -7,17 +7,30 @@ use crate::model::{
user::User,
};
#[get("/")]
use super::log::KioskCookie;
#[get("/", rank = 2)]
async fn index(db: &State<SqlitePool>, user: User) -> Template {
let stat = Stat::get_rowed_km(db).await;
let personal = stat::get_personal(db, &user).await;
let kiosk = false;
println!("{personal:?}");
Template::render("stat", context!(loggedin_user: &user, stat, personal))
Template::render(
"stat",
context!(loggedin_user: &user, stat, personal, kiosk),
)
}
#[get("/")]
async fn index_kiosk(db: &State<SqlitePool>, _kiosk: KioskCookie) -> Template {
let stat = Stat::get_rowed_km(db).await;
let kiosk = true;
Template::render("stat", context!(stat, kiosk))
}
pub fn routes() -> Vec<Route> {
routes![index]
routes![index, index_kiosk]
}
#[cfg(test)]

View File

@ -38,12 +38,14 @@
</div>
<script>
{% if personal %}
const data = [
{%- for p in personal %}
{ date: '{{p.date}}', km: {{p.km}} },
{%- endfor %}
]
sessionStorage.setItem('userStats', JSON.stringify(data));
{% endif %}
</script>
<script src="/public/logbook.js"></script>