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, }); 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 ) diff --git a/src/tera/admin/boat.rs b/src/tera/admin/boat.rs index 2cc186e..6ff6200 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), } } @@ -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 c732944..5208f18 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"), } @@ -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/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/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/boatdamage.rs b/src/tera/boatdamage.rs index 1fb28b2..82fb350 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,8 @@ 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()) } @@ -132,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}")), } } @@ -157,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 de65e73..eb0382f 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()) } @@ -207,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), ), } } @@ -245,14 +246,43 @@ 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 { match logbook.delete(db, &user).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"), + "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), + ) + } +} + +#[get("//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!("Eintrag {} gelöscht!", logbook_id), ), Err(LogbookDeleteError::NotYourEntry) => Flash::error( Redirect::to("/log"), @@ -278,7 +308,8 @@ pub fn routes() -> Vec { new_kiosk, show, show_kiosk, - delete + delete, + delete_kiosk ] } @@ -471,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 @@ -606,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] @@ -796,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!" ); } @@ -843,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( 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..a257bcf 100644 --- a/templates/base.html.tera +++ b/templates/base.html.tera @@ -12,9 +12,24 @@ {% if loggedin_user %} {{ macros::header(loggedin_user=loggedin_user) }} - {% endif %} + {% endif %} + {% if show_kiosk_header %} +
+ + +
+ {% endif %} -
{% block content %}{% endblock content %} +
{% block content %}{% endblock content %}
{% if loggedin_user %} diff --git a/templates/boatdamages.html.tera b/templates/boatdamages.html.tera index 377e036..0bfadbd 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') }}
@@ -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/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index 53d4552..be74871 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -162,25 +162,31 @@
{% 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 %} - - {% if allowed_to_close and state == "on_water" %} - LÖSCHEN + + {% 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 + {% endif %}
@@ -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 %} 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 %}