From 4cb374e24650df0b1d637ee242e102a64b1e9fb9 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 23 Oct 2023 09:36:38 +0200 Subject: [PATCH 01/11] remove debug statements --- src/model/rower.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/model/rower.rs b/src/model/rower.rs index f6a40a8..707c5d6 100644 --- a/src/model/rower.rs +++ b/src/model/rower.rs @@ -33,7 +33,7 @@ WHERE id in (SELECT rower_id FROM rower WHERE logbook_id=?) //TODO: Check if rower is allowed to row sqlx::query!( - "INSERT INTO rower(logbook_id, rower_id) VALUES (?,?)", + "INSERT INTO rower(logbook_id, rower_id) VALUES (?,?);", logbook_id, rower_id ) From 6f9edfa23f46a495f5d2d4a538aa1fc1a78c6e43 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 23 Oct 2023 21:05:59 +0200 Subject: [PATCH 02/11] show header in kiosk mode --- src/tera/boatdamage.rs | 1 + src/tera/log.rs | 3 ++- src/tera/stat.rs | 2 +- templates/base.html.tera | 8 +++++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/tera/boatdamage.rs b/src/tera/boatdamage.rs index 1fb28b2..8722467 100644 --- a/src/tera/boatdamage.rs +++ b/src/tera/boatdamage.rs @@ -36,6 +36,7 @@ async fn index_kiosk( context.insert("boatdamages", &boatdamages); context.insert("boats", &boats); context.insert("coxes", &coxes); + context.insert("show_kiosk_header", &true); Template::render("boatdamages", context.into_json()) } diff --git a/src/tera/log.rs b/src/tera/log.rs index de65e73..9b7cfbb 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -90,7 +90,7 @@ async fn show(db: &State, user: User) -> Template { async fn show_kiosk(db: &State, _kiosk: KioskCookie) -> Template { let logs = Logbook::completed(db).await; - Template::render("log.completed", context!(logs)) + Template::render("log.completed", context!(logs, show_kiosk_header: true)) } #[get("/kiosk/ekrv2019/")] @@ -148,6 +148,7 @@ async fn kiosk( context.insert("logtypes", &logtypes); context.insert("on_water", &on_water); context.insert("distances", &distances); + context.insert("show_kiosk_header", &true); Template::render("kiosk", context.into_json()) } diff --git a/src/tera/stat.rs b/src/tera/stat.rs index 54e0def..c5d0e41 100644 --- a/src/tera/stat.rs +++ b/src/tera/stat.rs @@ -26,7 +26,7 @@ async fn index_kiosk(db: &State, _kiosk: KioskCookie) -> Template { let stat = Stat::get_rowed_km(db).await; let kiosk = true; - Template::render("stat", context!(stat, kiosk)) + Template::render("stat", context!(stat, kiosk, show_kiosk_header: true)) } pub fn routes() -> Vec { diff --git a/templates/base.html.tera b/templates/base.html.tera index cbca953..910e4c1 100644 --- a/templates/base.html.tera +++ b/templates/base.html.tera @@ -12,7 +12,13 @@ {% if loggedin_user %} {{ macros::header(loggedin_user=loggedin_user) }} - {% endif %} + {% endif %} + {% if show_kiosk_header %} + Ausfahrt eintragen + Logbuch + Statistik + Bootsschaden + {% endif %}
{% block content %}{% endblock content %}
From 51860ded27b625568465ed5435d6c97410e03cf5 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 23 Oct 2023 21:32:44 +0200 Subject: [PATCH 03/11] allow deletion of trip in kiosk mode --- src/tera/auth.rs | 1 - src/tera/log.rs | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/tera/auth.rs b/src/tera/auth.rs index 6ff2ddc..2918c01 100644 --- a/src/tera/auth.rs +++ b/src/tera/auth.rs @@ -11,7 +11,6 @@ use rocket::{ FromForm, Request, Route, State, }; use rocket_dyn_templates::{context, tera, Template}; -use serde_json::json; use sqlx::SqlitePool; use crate::model::{ diff --git a/src/tera/log.rs b/src/tera/log.rs index 9b7cfbb..c7deb34 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -246,7 +246,7 @@ async fn home( home_logbook(db, data, logbook_id, &user).await } -#[get("//delete")] +#[get("//delete", rank = 2)] async fn delete(db: &State, logbook_id: i32, user: User) -> Flash { let logbook = Logbook::find_by_id(db, logbook_id).await; if let Some(logbook) = logbook { @@ -268,6 +268,35 @@ async fn delete(db: &State, logbook_id: i32, user: User) -> Flash/delete")] +async fn delete_kiosk( + db: &State, + logbook_id: i32, + _kiosk: KioskCookie, +) -> Flash { + let logbook = Logbook::find_by_id(db, logbook_id).await; + if let Some(logbook) = logbook { + let cox = User::find_by_id(db, logbook.shipmaster as i32) + .await + .unwrap(); + match logbook.delete(db, &cox).await { + Ok(_) => Flash::success( + Redirect::to("/log"), + format!("Logbook with ID {} successfully deleted!", logbook_id), + ), + Err(LogbookDeleteError::NotYourEntry) => Flash::error( + Redirect::to("/log"), + "Du hast nicht die Berechtigung, den Eintrag zu löschen!", + ), + } + } else { + Flash::error( + Redirect::to("/log"), + format!("Logbook with ID {} could not be found!", logbook_id), + ) + } +} + pub fn routes() -> Vec { routes![ index, @@ -279,7 +308,8 @@ pub fn routes() -> Vec { new_kiosk, show, show_kiosk, - delete + delete, + delete_kiosk ] } From 88af24db7be87f25af205a6fb8a8c93ca4b02bf4 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 23 Oct 2023 21:38:08 +0200 Subject: [PATCH 04/11] allow all users to report boat damage --- src/tera/boatdamage.rs | 4 ++-- templates/boatdamages.html.tera | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tera/boatdamage.rs b/src/tera/boatdamage.rs index 8722467..8738e68 100644 --- a/src/tera/boatdamage.rs +++ b/src/tera/boatdamage.rs @@ -26,7 +26,7 @@ async fn index_kiosk( ) -> Template { let boatdamages = BoatDamage::all(db).await; let boats = Boat::all(db).await; - let coxes = User::cox(db).await; + let user = User::all(db).await; let mut context = Context::new(); if let Some(msg) = flash { @@ -35,7 +35,7 @@ async fn index_kiosk( context.insert("boatdamages", &boatdamages); context.insert("boats", &boats); - context.insert("coxes", &coxes); + context.insert("user", &user); context.insert("show_kiosk_header", &true); Template::render("boatdamages", context.into_json()) diff --git a/templates/boatdamages.html.tera b/templates/boatdamages.html.tera index 377e036..09d39eb 100644 --- a/templates/boatdamages.html.tera +++ b/templates/boatdamages.html.tera @@ -27,7 +27,7 @@
{{ log::boat_select(only_ones=false, id='boat') }} {% if not loggedin_user %} - {{ macros::select(label='Gemeldet von', data=coxes, name='user_id') }} + {{ macros::select(label='Gemeldet von', data=user, name='user_id') }} {% endif %} {{ macros::input(label='Beschreibung des Schadens', name='desc', type='text', required=true, wrapper_class='col-span-4') }}
From 547cab368c3dbe67c1387e8c8196ed2d1815ba4e Mon Sep 17 00:00:00 2001 From: Marie Birner Date: Mon, 23 Oct 2023 21:43:01 +0200 Subject: [PATCH 05/11] [TASK] style header kiosk mode --- templates/base.html.tera | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/templates/base.html.tera b/templates/base.html.tera index 910e4c1..a257bcf 100644 --- a/templates/base.html.tera +++ b/templates/base.html.tera @@ -14,13 +14,22 @@ {{ macros::header(loggedin_user=loggedin_user) }} {% endif %} {% if show_kiosk_header %} - Ausfahrt eintragen - Logbuch - Statistik - Bootsschaden +
+ + +
{% endif %} -
{% block content %}{% endblock content %} +
{% block content %}{% endblock content %}
{% if loggedin_user %} From fc42559f1b064ef294acd910fc8d6a1662979ff4 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 23 Oct 2023 21:44:39 +0200 Subject: [PATCH 06/11] show amount of guests --- templates/includes/forms/log.html.tera | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index 53d4552..060e1f1 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -177,6 +177,12 @@ {% for rower in log.rowers %}

{{ rower.name }}

{% endfor %} + + {% set amount_rowers = log.rowers | length %} + {% set amount_guests = log.boat.amount_seats - amount_rowers -1 %} + {% if amount_guests > 0 %} + Gäste (ohne Account): {{ amount_guests }} + {% endif %} {% if allowed_to_close and state == "on_water" %} LÖSCHEN @@ -235,8 +241,7 @@ {{ rower.name }}{% if not loop.last or amount_guests > 0 %}, {% endif %} {% endfor %} {% if amount_guests > 0 %} - {{ amount_guests }} - Gäste (ohne Account) + Gäste (ohne Account): {{ amount_guests }} {% endif %}
{% endif %} From da29d5dcdca42f8cbec0c22fc314da28c7531cfa Mon Sep 17 00:00:00 2001 From: Marie Birner Date: Mon, 23 Oct 2023 21:53:43 +0200 Subject: [PATCH 07/11] [TASK] style delete button in logbook --- templates/includes/forms/log.html.tera | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index 53d4552..5f1fe45 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -162,25 +162,25 @@
{% endif %}
- {% if log.destination %} - {{ log.destination }} - {% endif %} + {% if log.destination %} + {{ log.destination }} + {% endif %} - {% for user in users %} - {% if user.id == log.shipmaster %} -

- {{ user.name }} -

- {% endif %} - {% endfor %} + {% for user in users %} + {% if user.id == log.shipmaster %} +

+ {{ user.name }} +

+ {% endif %} + {% endfor %} - {% for rower in log.rowers %} -

{{ rower.name }}

- {% endfor %} + {% for rower in log.rowers %} +

{{ rower.name }}

+ {% endfor %} - {% if allowed_to_close and state == "on_water" %} - LÖSCHEN - {% endif %} + {% if allowed_to_close and state == "on_water" %} + Löschen + {% endif %}
From 76a05b61073105f4a9d1298aa1a7fdc9115ad2cf Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 23 Oct 2023 22:26:33 +0200 Subject: [PATCH 08/11] add verified for boats --- src/model/boatdamage.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/model/boatdamage.rs b/src/model/boatdamage.rs index b50b754..ed0dbc0 100644 --- a/src/model/boatdamage.rs +++ b/src/model/boatdamage.rs @@ -28,6 +28,7 @@ pub struct BoatDamageWithDetails { user_fixed: Option, user_verified: Option, boat: Boat, + verified: bool, } #[derive(Debug)] @@ -102,6 +103,7 @@ ORDER BY created_at DESC .await .unwrap(), user_fixed, + verified: user_verified.is_some(), user_verified, boat_damage, }); From 52b245b14ef9d38ba20ed56d5141ed648c5b9b4e Mon Sep 17 00:00:00 2001 From: Marie Birner Date: Mon, 23 Oct 2023 22:36:57 +0200 Subject: [PATCH 09/11] [TASK] correct sorting verified and style input / btn combi --- templates/boatdamages.html.tera | 18 +++++++++--------- templates/kiosk.html.tera | 4 +++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/templates/boatdamages.html.tera b/templates/boatdamages.html.tera index 09d39eb..0bfadbd 100644 --- a/templates/boatdamages.html.tera +++ b/templates/boatdamages.html.tera @@ -45,9 +45,9 @@
- {% for boatdamage in boatdamages %} + {% for boatdamage in boatdamages | sort(attribute="verified") %}
-
+
{{ boatdamage.created_at | date(format='%d.%m.%Y') }} ({{ boatdamage.boat.name }}){% if boatdamage.boat.damage %}(Boot gesperrt){% endif %}
{{ boatdamage.desc }}
@@ -58,12 +58,12 @@ Repariert von {{ boatdamage.user_fixed.name }} am/um {{ boatdamage.fixed_at | date(format='%d.%m.%Y (%H:%M)') }} {% else %} {% if loggedin_user.is_cox %} - - + + {% if loggedin_user.is_tech %} - + {% else %} - + {% endif %} {% endif %} @@ -73,9 +73,9 @@ Verifziert von {{ boatdamage.user_verified.name }} am/um {{ boatdamage.verified_at | date(format='%d.%m.%Y (%H:%M)') }} {% else %} {% if loggedin_user.is_tech and boatdamage.fixed_at %} -
- - + + +
{% endif %} {% endif %} diff --git a/templates/kiosk.html.tera b/templates/kiosk.html.tera index e3243cf..35b8018 100644 --- a/templates/kiosk.html.tera +++ b/templates/kiosk.html.tera @@ -9,7 +9,9 @@

Logbuch

{% if flash %} - {{ macros::alert(message=flash.1, type=flash.0, class="sm:col-span-2 lg:col-span-3") }} +
+ {{ macros::alert(message=flash.1, type=flash.0, class="sm:col-span-2 lg:col-span-3") }} +
{% endif %}
From 8ebc06e4455fee5971168cbd7f576a98eb5f98e0 Mon Sep 17 00:00:00 2001 From: Marie Birner Date: Mon, 23 Oct 2023 22:52:11 +0200 Subject: [PATCH 10/11] [TASK] translate alerts --- src/tera/admin/boat.rs | 6 +++--- src/tera/admin/planned_event.rs | 4 ++-- src/tera/admin/user.rs | 4 ++-- src/tera/boatdamage.rs | 4 ++-- src/tera/log.rs | 8 ++++---- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/tera/admin/boat.rs b/src/tera/admin/boat.rs index 2cc186e..a370900 100644 --- a/src/tera/admin/boat.rs +++ b/src/tera/admin/boat.rs @@ -43,7 +43,7 @@ async fn delete(db: &State, _admin: AdminUser, boat: i32) -> Flash Flash::error(Redirect::to("/admin/boat"), "Boat does not exist"), @@ -63,7 +63,7 @@ async fn update( }; match boat.update(db, data.into_inner()).await { - Ok(_) => Flash::success(Redirect::to("/admin/boat"), "Successfully updated boat"), + Ok(_) => Flash::success(Redirect::to("/admin/boat"), "Boot bearbeitet"), Err(e) => Flash::error(Redirect::to("/admin/boat"), e), } } @@ -75,7 +75,7 @@ async fn create( _admin: AdminUser, ) -> Flash { match Boat::create(db, data.into_inner()).await { - Ok(_) => Flash::success(Redirect::to("/admin/boat"), "Successfully created boat"), + Ok(_) => Flash::success(Redirect::to("/admin/boat"), "Boot hinzugefügt"), Err(e) => Flash::error(Redirect::to("/admin/boat"), e), } } diff --git a/src/tera/admin/planned_event.rs b/src/tera/admin/planned_event.rs index c732944..2208d8b 100644 --- a/src/tera/admin/planned_event.rs +++ b/src/tera/admin/planned_event.rs @@ -36,7 +36,7 @@ async fn create( PlannedEvent::create(db, data.name, data.planned_amount_cox, trip_details).await; - Flash::success(Redirect::to("/"), "Successfully planned the event") + Flash::success(Redirect::to("/"), "Event hinzugefügt") } //TODO: add constraints (e.g. planned_amount_cox > 0) @@ -79,7 +79,7 @@ async fn delete(db: &State, id: i64, _admin: AdminUser) -> Flash { planned_event.delete(db).await; - Flash::success(Redirect::to("/"), "Successfully deleted the event") + Flash::success(Redirect::to("/"), "Event gelöscht") } None => Flash::error(Redirect::to("/"), "PlannedEvent does not exist"), } diff --git a/src/tera/admin/user.rs b/src/tera/admin/user.rs index dd17918..7a94196 100644 --- a/src/tera/admin/user.rs +++ b/src/tera/admin/user.rs @@ -35,7 +35,7 @@ async fn resetpw(db: &State, _admin: AdminUser, user: i32) -> Flash< user.reset_pw(db).await; Flash::success( Redirect::to("/admin/user"), - format!("Successfully reset pw of {}", user.name), + format!("Passwort von {} zurückgesetzt", user.name), ) } None => Flash::error(Redirect::to("/admin/user"), "User does not exist"), @@ -50,7 +50,7 @@ async fn delete(db: &State, _admin: AdminUser, user: i32) -> Flash Flash::error(Redirect::to("/admin/user"), "User does not exist"), diff --git a/src/tera/boatdamage.rs b/src/tera/boatdamage.rs index 8738e68..82fb350 100644 --- a/src/tera/boatdamage.rs +++ b/src/tera/boatdamage.rs @@ -133,7 +133,7 @@ async fn fixed<'r>( user_id_fixed: coxuser.id as i32, }; match boatdamage.fixed(db, boatdamage_fixed).await { - Ok(_) => Flash::success(Redirect::to("/boatdamage"), "Successfully fixed the boat."), + Ok(_) => Flash::success(Redirect::to("/boatdamage"), "Bootsschaden behoben."), Err(e) => Flash::error(Redirect::to("/boatdamage"), format!("Error: {e}")), } } @@ -158,7 +158,7 @@ async fn verified<'r>( match boatdamage.verified(db, boatdamage_verified).await { Ok(_) => Flash::success( Redirect::to("/boatdamage"), - "Successfully verified the boat.", + "Bootsschaden verifiziert", ), Err(e) => Flash::error(Redirect::to("/boatdamage"), format!("Error: {e}")), } diff --git a/src/tera/log.rs b/src/tera/log.rs index c7deb34..aa8fb3b 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -208,11 +208,11 @@ async fn home_logbook( }; match logbook.home(db, user, data.into_inner()).await { - Ok(_) => Flash::success(Redirect::to("/log"), "Successfully updated log"), + Ok(_) => Flash::success(Redirect::to("/log"), "Ausfahrt korrekt eingetragen"), Err(LogbookUpdateError::TooManyRowers(expected, actual)) => Flash::error(Redirect::to("/log"), format!("Zu viele Ruderer (Boot fasst maximal {expected}, es wurden jedoch {actual} Ruderer ausgewählt)")), Err(_) => Flash::error( Redirect::to("/log"), - format!("Logbook with ID {} could not be updated!", logbook_id), + format!("Eintrag {} konnte nicht abgesendet werden!", logbook_id), ), } } @@ -253,7 +253,7 @@ async fn delete(db: &State, logbook_id: i32, user: User) -> Flash Flash::success( Redirect::to("/log"), - format!("Logbook with ID {} successfully deleted!", logbook_id), + format!("Eintrag {} gelöscht!", logbook_id), ), Err(LogbookDeleteError::NotYourEntry) => Flash::error( Redirect::to("/log"), @@ -282,7 +282,7 @@ async fn delete_kiosk( match logbook.delete(db, &cox).await { Ok(_) => Flash::success( Redirect::to("/log"), - format!("Logbook with ID {} successfully deleted!", logbook_id), + format!("Eintrag {} gelöscht!", logbook_id), ), Err(LogbookDeleteError::NotYourEntry) => Flash::error( Redirect::to("/log"), From 6d4ebda4bc94e5b738823f9624e01167690a02f7 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 24 Oct 2023 08:16:17 +0200 Subject: [PATCH 11/11] fix ci --- src/tera/admin/boat.rs | 4 ++-- src/tera/admin/planned_event.rs | 10 ++-------- src/tera/log.rs | 17 +++++++++++++---- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/tera/admin/boat.rs b/src/tera/admin/boat.rs index a370900..6ff6200 100644 --- a/src/tera/admin/boat.rs +++ b/src/tera/admin/boat.rs @@ -153,7 +153,7 @@ mod test { .get("_flash") .expect("Expected flash cookie"); - assert_eq!(flash_cookie.value(), "7:successSuccessfully updated boat"); + assert_eq!(flash_cookie.value(), "7:successBoot bearbeitet"); let boat = Boat::find_by_id(&db, 1).await.unwrap(); assert_eq!(boat.name, "Haichiii"); @@ -267,7 +267,7 @@ mod test { .get("_flash") .expect("Expected flash cookie"); - assert_eq!(flash_cookie.value(), "7:successSuccessfully created boat"); + assert_eq!(flash_cookie.value(), "7:successBoot hinzugefügt"); Boat::find_by_name(&db, "completely-new-boat".into()) .await diff --git a/src/tera/admin/planned_event.rs b/src/tera/admin/planned_event.rs index 2208d8b..5208f18 100644 --- a/src/tera/admin/planned_event.rs +++ b/src/tera/admin/planned_event.rs @@ -127,10 +127,7 @@ mod test { .get("_flash") .expect("Expected flash cookie"); - assert_eq!( - flash_cookie.value(), - "7:successSuccessfully deleted the event" - ); + assert_eq!(flash_cookie.value(), "7:successEvent gelöscht"); let event = PlannedEvent::find_by_id(&db, 1).await; assert_eq!(event, None); @@ -265,10 +262,7 @@ mod test { .get("_flash") .expect("Expected flash cookie"); - assert_eq!( - flash_cookie.value(), - "7:successSuccessfully planned the event" - ); + assert_eq!(flash_cookie.value(), "7:successEvent hinzugefügt"); let event = PlannedEvent::find_by_id(&db, 2).await.unwrap(); assert_eq!(event.name, "my-cool-new-event"); diff --git a/src/tera/log.rs b/src/tera/log.rs index aa8fb3b..eb0382f 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -502,7 +502,10 @@ mod test { .get("_flash") .expect("Expected flash cookie"); - assert_eq!(flash_cookie.value(), "7:successSuccessfully updated log"); + assert_eq!( + flash_cookie.value(), + "7:successAusfahrt korrekt eingetragen" + ); } //Kiosk mode @@ -637,7 +640,10 @@ mod test { .get("_flash") .expect("Expected flash cookie"); - assert_eq!(flash_cookie.value(), "7:successSuccessfully updated log"); + assert_eq!( + flash_cookie.value(), + "7:successAusfahrt korrekt eingetragen" + ); } #[sqlx::test] @@ -827,7 +833,7 @@ mod test { assert_eq!( flash_cookie.value(), - "5:errorLogbook with ID 1 could not be updated!" + "5:errorEintrag 1 konnte nicht abgesendet werden!" ); } @@ -874,7 +880,10 @@ mod test { .get("_flash") .expect("Expected flash cookie"); - assert_eq!(flash_cookie.value(), "7:successSuccessfully updated log"); + assert_eq!( + flash_cookie.value(), + "7:successAusfahrt korrekt eingetragen" + ); } async fn cant_start_trip(