From 43e073c54ec781999529c14f2bd68ab3f0784183 Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 24 Apr 2024 15:39:13 +0200 Subject: [PATCH 1/2] calc general boat cat (#436) Reviewed-on: https://git.hofer.link/Ruderverein-Donau-Linz/rowt/pulls/436 --- frontend/tests/log.spec.ts | 16 ++++++++-------- src/model/boat.rs | 12 ++++++++++-- src/model/logbook.rs | 7 +++++++ src/tera/log.rs | 1 + templates/includes/forms/log.html.tera | 8 +++----- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/frontend/tests/log.spec.ts b/frontend/tests/log.spec.ts index 64d2c09..b12f0cb 100644 --- a/frontend/tests/log.spec.ts +++ b/frontend/tests/log.spec.ts @@ -12,10 +12,10 @@ test("Cox can start and cancel trip", async ({ page }, testInfo) => { await page.getByRole("link", { name: "Ausfahrt eintragen" }).click(); if (testInfo.project.name.includes("Mobile")) { // No left boat selector on mobile views - await page.getByText("Kaputtes Boot :-( (7 x)").nth(1).click(); + await page.getByText("Kaputtes Boot :-( (7x)").nth(1).click(); await page.getByRole("option", { name: "Joe" }).click(); } else { - await page.getByText('2x').click(); + await page.getByText('2x', { exact: true }).click(); await page.getByText("Joe", { exact: true }).click(); } await page.getByPlaceholder("Ruderer auswählen").click(); @@ -53,10 +53,10 @@ test("Cox can start and finish trip", async ({ page }, testInfo) => { await page.getByRole("link", { name: "Ausfahrt eintragen" }).click(); if (testInfo.project.name.includes("Mobile")) { // No left boat selector on mobile views - await page.getByText("Kaputtes Boot :-( (7 x)").nth(1).click(); + await page.getByText("Kaputtes Boot :-( (7x)").nth(1).click(); await page.getByRole("option", { name: "Joe" }).click(); } else { - await page.getByText('2x').click(); + await page.getByText('2x', { exact: true }).click(); await page.getByText("Joe", { exact: true }).click(); } await page.getByPlaceholder("Ruderer auswählen").click(); @@ -105,10 +105,10 @@ test("Kiosk can start and cancel trip", async ({ page }, testInfo) => { await page.goto("/log/kiosk/ekrv2019/Linz"); if (testInfo.project.name.includes("Mobile")) { // No left boat selector on mobile views - await page.getByText("Kaputtes Boot :-( (7 x)").nth(1).click(); + await page.getByText("Kaputtes Boot :-( (7x)").nth(1).click(); await page.getByRole("option", { name: "Joe" }).click(); } else { - await page.getByText('2x').click(); + await page.getByText('2x', { exact: true }).click(); await page.getByText("Joe", { exact: true }).click(); } await page.getByPlaceholder("Ruderer auswählen").click(); @@ -139,10 +139,10 @@ test("Kiosk can start and finish trip", async ({ page }, testInfo) => { if (testInfo.project.name.includes("Mobile")) { // No left boat selector on mobile views - await page.getByText("Kaputtes Boot :-( (7 x)").nth(1).click(); + await page.getByText("Kaputtes Boot :-( (7x)").nth(1).click(); await page.getByRole("option", { name: "Joe" }).click(); } else { - await page.getByText('2x').click(); + await page.getByText('2x', { exact: true }).click(); await page.getByText("Joe", { exact: true }).click(); } await page.getByPlaceholder("Ruderer auswählen").click(); diff --git a/src/model/boat.rs b/src/model/boat.rs index 5860d32..115acec 100644 --- a/src/model/boat.rs +++ b/src/model/boat.rs @@ -21,9 +21,9 @@ pub struct Boat { pub boatbuilder: Option, pub default_destination: Option, #[serde(default = "bool::default")] - convert_handoperated_possible: bool, + pub convert_handoperated_possible: bool, #[serde(default = "bool::default")] - default_shipmaster_only_steering: bool, + pub default_shipmaster_only_steering: bool, #[serde(default = "bool::default")] skull: bool, #[serde(default = "bool::default")] @@ -46,6 +46,7 @@ pub struct BoatWithDetails { damage: BoatDamage, on_water: bool, reserved_today: bool, + cat: String, } #[derive(FromForm)] @@ -179,11 +180,18 @@ AND date('now') BETWEEN start_date AND end_date;", if boat.is_locked(db).await { damage = BoatDamage::Locked; } + let cat = if boat.default_shipmaster_only_steering { + format!("{}+", boat.amount_seats - 1) + } else { + format!("{}x", boat.amount_seats) + }; + res.push(BoatWithDetails { damage, on_water: boat.on_water(db).await, reserved_today: boat.reserved_today(db).await, boat, + cat, }); } res diff --git a/src/model/logbook.rs b/src/model/logbook.rs index 5d83f12..156ad8e 100644 --- a/src/model/logbook.rs +++ b/src/model/logbook.rs @@ -126,6 +126,7 @@ pub enum LogbookCreateError { NotYourEntry, ArrivalSetButNotRemainingTwo, OnlyAllowedToEndTripsEndingToday, + CantChangeHandoperatableStatusForThisBoat, } impl From for LogbookCreateError { @@ -302,6 +303,12 @@ ORDER BY departure DESC return Err(LogbookCreateError::BoatNotFound); }; + if log.shipmaster_only_steering != boat.default_shipmaster_only_steering { + if !boat.convert_handoperated_possible { + return Err(LogbookCreateError::CantChangeHandoperatableStatusForThisBoat); + } + } + if boat.amount_seats == 1 && log.rowers.is_empty() { log.rowers = vec![created_by_user.id]; } diff --git a/src/tera/log.rs b/src/tera/log.rs index 241f36c..2c618b0 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -214,6 +214,7 @@ async fn create_logbook( Err(LogbookCreateError::NotYourEntry) => Flash::error(Redirect::to("/log"), "Nicht deine Ausfahrt!"), Err(LogbookCreateError::ArrivalSetButNotRemainingTwo) => Flash::error(Redirect::to("/log"), "Ankunftszeit gesetzt aber nicht Distanz + Strecke"), Err(LogbookCreateError::OnlyAllowedToEndTripsEndingToday) => Flash::error(Redirect::to("/log"), "Nur Ausfahrten, die in der letzten Woche enden dürfen eingetragen werden. Für einen Nachtrag schreibe alle Daten Philipp (Tel. nr. siehe Signal oder it@rudernlinz.at)."), + Err(LogbookCreateError::CantChangeHandoperatableStatusForThisBoat) => Flash::error(Redirect::to("/log"), "Handsteuer-Status dieses Boots kann nicht verändert werden."), } } diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index 99d308e..c70fb8c 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -3,16 +3,14 @@ Inputs: boats #} {% macro show_boats() %} - {% for amount_seats, grouped_boats in boats | group_by(attribute="amount_seats") %} + {% for amount_seats, grouped_boats in boats | group_by(attribute="cat") %}
{% if grouped_boats[0].external %} Vereinsfremde Boote - {% elif grouped_boats[0].default_shipmaster_only_steering %} - {{ grouped_boats[0].amount_seats - 1 }}+ {% else %} - {{ amount_seats }}x + {{ grouped_boats[0].cat }} {% endif %} ({{ grouped_boats | length }}) @@ -78,7 +76,7 @@ {% endmacro new %} {% macro boat_select(id="boat_id") %} - {{ macros::select(label="Boot", data=boats, name="boat_id", id=id, display=["name", " (","amount_seats", " x)"], extras=["default_shipmaster_only_steering", "amount_seats", "on_water", "default_destination"], wrapper_class="col-span-4", show_seats=true) }} + {{ macros::select(label="Boot", data=boats, name="boat_id", id=id, display=["name", " (","cat",")"], extras=["default_shipmaster_only_steering", "amount_seats", "on_water", "default_destination"], wrapper_class="col-span-4", show_seats=true) }} {% endmacro boat_select %} {% macro rower_select(id, selected, amount_seats='', class='', init='false', cox_on_boat='', steering_person_id='') %} {#{% if not amount_seats or amount_seats > 1 %}#} From 237377dc05ddbb77e50c0982bcd92a3fccea53a7 Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 24 Apr 2024 16:56:48 +0200 Subject: [PATCH 2/2] easier handling of external boats, show all in separate category --- src/model/boat.rs | 18 +++++++++++------- templates/includes/forms/log.html.tera | 10 ++-------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/model/boat.rs b/src/model/boat.rs index 115acec..015a54c 100644 --- a/src/model/boat.rs +++ b/src/model/boat.rs @@ -180,10 +180,14 @@ AND date('now') BETWEEN start_date AND end_date;", if boat.is_locked(db).await { damage = BoatDamage::Locked; } - let cat = if boat.default_shipmaster_only_steering { - format!("{}+", boat.amount_seats - 1) + let cat = if boat.external { + format!("Vereinsfremde Boote") } else { - format!("{}x", boat.amount_seats) + if boat.default_shipmaster_only_steering { + format!("{}+", boat.amount_seats - 1) + } else { + format!("{}x", boat.amount_seats) + } }; res.push(BoatWithDetails { @@ -259,7 +263,7 @@ ORDER BY " SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, deleted, convert_handoperated_possible FROM boat -WHERE owner is null or owner = ? +WHERE (owner is null or owner = ?) AND deleted = 0 ORDER BY amount_seats DESC ", user.id @@ -273,7 +277,7 @@ ORDER BY amount_seats DESC " SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, deleted, convert_handoperated_possible FROM boat -WHERE owner = ? OR (owner is null and amount_seats = 1) +WHERE (owner = ? OR (owner is null and amount_seats = 1)) AND deleted = 0 ORDER BY amount_seats DESC ", user.id @@ -291,7 +295,7 @@ ORDER BY amount_seats DESC Boat, "SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, deleted, convert_handoperated_possible FROM boat -WHERE owner is null and location_id = ? +WHERE (owner is null and location_id = ?) AND deleted = 0 ORDER BY amount_seats DESC ",ottensheim.id) .fetch_all(db) @@ -311,7 +315,7 @@ ORDER BY amount_seats DESC SELECT boat.id, boat.name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, deleted, convert_handoperated_possible FROM boat INNER JOIN location ON boat.location_id = location.id -WHERE location.name=? +WHERE location.name=? AND deleted = 0 ORDER BY amount_seats DESC ", location diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index c70fb8c..59a2c4f 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -3,16 +3,10 @@ Inputs: boats #} {% macro show_boats() %} - {% for amount_seats, grouped_boats in boats | group_by(attribute="cat") %} + {% for cat, grouped_boats in boats | group_by(attribute="cat") %}
- - {% if grouped_boats[0].external %} - Vereinsfremde Boote - {% else %} - {{ grouped_boats[0].cat }} - {% endif %} - + {{ cat }} ({{ grouped_boats | length }})