From c27a2ad15e66ba73d2490a4c716af2597e5f542f Mon Sep 17 00:00:00 2001 From: philipp Date: Sun, 28 Apr 2024 19:16:38 +0200 Subject: [PATCH 1/4] don't respond with 500 if no rower is selected --- src/tera/log.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tera/log.rs b/src/tera/log.rs index 2c618b0..0cdca4a 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -250,7 +250,13 @@ async fn create_kiosk( } else if let Some(shipmaster) = data.shipmaster { User::find_by_id(db, shipmaster as i32).await.unwrap() } else { - User::find_by_id(db, data.rowers[0] as i32).await.unwrap() + let Some(rower) = data.rowers.get(0) else { + return Flash::error( + Redirect::to("/log"), + "Ausfahrt ohne Benutzer kann nicht angelegt werden.", + ); + }; + User::find_by_id(db, *rower as i32).await.unwrap() }; Log::create( db, -- 2.45.2 From 9ca510b8925ff497473fc840f591e2def138f5fb Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 29 Apr 2024 08:48:15 +0200 Subject: [PATCH 2/4] show proper time in notifications --- src/model/notification.rs | 26 ++++++++++++++++++++++---- templates/index.html.tera | 4 ++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/model/notification.rs b/src/model/notification.rs index 4678eb4..1ec7217 100644 --- a/src/model/notification.rs +++ b/src/model/notification.rs @@ -70,23 +70,41 @@ impl Notification { } pub async fn for_user(db: &SqlitePool, user: &User) -> Vec { - sqlx::query_as!( - Self, + let rows = sqlx::query!( " -SELECT * FROM notification +SELECT id, user_id, message, read_at, datetime(created_at, 'localtime') as created_at, category, link FROM notification WHERE user_id = ? AND ( read_at IS NULL OR read_at >= datetime('now', '-14 days') ) + AND created_at is not NULL ORDER BY read_at DESC, created_at DESC; ", user.id ) .fetch_all(db) .await - .unwrap() + .unwrap(); + + println!("{rows:#?}"); + + rows.into_iter() + .map(|rec| Notification { + id: rec.id, + user_id: rec.user_id, + message: rec.message, + read_at: rec.read_at, + created_at: NaiveDateTime::parse_from_str( + &rec.created_at.unwrap(), + "%Y-%m-%d %H:%M:%S", + ) + .unwrap(), + category: rec.category, + link: rec.link, + }) + .collect() } pub async fn mark_read(self, db: &SqlitePool) { diff --git a/templates/index.html.tera b/templates/index.html.tera index b200554..f863cf8 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -30,7 +30,7 @@
- {{ notification.category }} • {{ notification.created_at | date(timezone="Europe/Vienna", format="%d.%m.%Y %H:%M",) }} + {{ notification.category }} • {{ notification.created_at | date(format="%d.%m.%Y %H:%M",) }}
{{ notification.message | safe }}
@@ -55,7 +55,7 @@ {% if notification.read_at %}
- {{ notification.category }} • {{ notification.created_at | date(timezone="Europe/Vienna", format="%d.%m.%Y %H:%M") }} + {{ notification.category }} • {{ notification.created_at | date(format="%d.%m.%Y %H:%M") }}
{{ notification.message | safe }}
-- 2.45.2 From 08fe779403b240aec08a2dd79581607829711d45 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 29 Apr 2024 08:48:43 +0200 Subject: [PATCH 3/4] remove debug println --- src/model/notification.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/model/notification.rs b/src/model/notification.rs index 1ec7217..a7747b7 100644 --- a/src/model/notification.rs +++ b/src/model/notification.rs @@ -88,8 +88,6 @@ ORDER BY read_at DESC, created_at DESC; .await .unwrap(); - println!("{rows:#?}"); - rows.into_iter() .map(|rec| Notification { id: rec.id, -- 2.45.2 From c449e878f05c183d651d88ea0745520967b8a2e0 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 29 Apr 2024 21:51:27 +0200 Subject: [PATCH 4/4] rephrase scheckbuch button --- templates/forms/event.html.tera | 2 +- templates/forms/trip.html.tera | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/forms/event.html.tera b/templates/forms/event.html.tera index 976f593..5803c7a 100644 --- a/templates/forms/event.html.tera +++ b/templates/forms/event.html.tera @@ -9,7 +9,7 @@ {{ macros::input(label='Startzeit', name='tripdetails.planned_starting_time', type='time', required=true) }} {{ macros::input(label='Anzahl Steuerleute', name='planned_amount_cox', type='number', required=true, min='0') }} {{ macros::input(label='Anzahl Ruderer (ohne Steuerperson)', name='tripdetails.max_people', type='number', required=true, min='0') }} - {{ macros::checkbox(label='Gäste erlauben', name='tripdetails.allow_guests') }} + {{ macros::checkbox(label='Scheckbuch-Anmeldungen erlauben', name='tripdetails.allow_guests') }} {{ macros::checkbox(label='Immer anzeigen', name='tripdetails.always_show') }} {{ macros::input(label='Anmerkungen', name='tripdetails.notes', type='input') }} {{ macros::select(label='Typ', data=trip_types, name='tripdetails.trip_type', default='Reguläre Ausfahrt') }} diff --git a/templates/forms/trip.html.tera b/templates/forms/trip.html.tera index 9aa3851..27a3b86 100644 --- a/templates/forms/trip.html.tera +++ b/templates/forms/trip.html.tera @@ -4,7 +4,7 @@ {{ macros::input(label='Startzeit (zB "10:00")', name='planned_starting_time', type='time', required=true) }} {{ macros::input(label='Anzahl Ruderer (ohne Steuerperson)', name='max_people', type='number', required=true, min='0') }} - {{ macros::checkbox(label='Gäste erlauben', name='allow_guests') }} + {{ macros::checkbox(label='Scheckbuch-Anmeldungen erlauben', name='allow_guests') }} {{ macros::checkbox(label='Immer anzeigen', name='always_show') }} {{ macros::input(label='Anmerkungen', name='notes', type='input') }} {{ macros::select(label='Typ', data=trip_types, name='trip_type', default='Reguläre Ausfahrt') }} -- 2.45.2