From 715fae59fc51390d9252c2a11de3a1bbe19ac8e9 Mon Sep 17 00:00:00 2001 From: philipp Date: Thu, 9 Nov 2023 08:56:08 +0100 Subject: [PATCH] implement default destination for boats --- frontend/main.ts | 4 ++++ migration.sql | 1 + src/model/boat.rs | 21 +++++++++++++-------- staging-diff.sql | 1 + templates/includes/forms/boat.html.tera | 4 +++- templates/includes/forms/log.html.tera | 6 +++--- templates/includes/macros.html.tera | 2 +- 7 files changed, 26 insertions(+), 13 deletions(-) diff --git a/frontend/main.ts b/frontend/main.ts index 304d6f6..a351893 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -105,6 +105,7 @@ interface ChoiceBoatEvent extends Event{ customProperties: { amount_seats: number, owner: number, + default_destination: string, } }; } @@ -125,6 +126,9 @@ function selectBoatChange() { const amount_seats = event.detail.customProperties.amount_seats; setMaxAmountRowers("newrower", amount_seats); + const destination = document.querySelector('#destination'); + destination.value = event.detail.customProperties.default_destination; + if (event.detail.customProperties.owner){ choiceObjects["newrower"].setChoiceByValue(event.detail.customProperties.owner+""); } diff --git a/migration.sql b/migration.sql index 671a644..4a3233e 100644 --- a/migration.sql +++ b/migration.sql @@ -79,6 +79,7 @@ CREATE TABLE IF NOT EXISTS "boat" ( "year_built" INTEGER, "boatbuilder" TEXT, "default_shipmaster_only_steering" boolean default false not null, + "default_location" text, "skull" boolean default true NOT NULL, -- false => riemen "external" boolean default false NOT NULL -- false => owned by different club ); diff --git a/src/model/boat.rs b/src/model/boat.rs index f5a1d2d..3039f82 100644 --- a/src/model/boat.rs +++ b/src/model/boat.rs @@ -13,6 +13,7 @@ pub struct Boat { pub owner: Option, pub year_built: Option, pub boatbuilder: Option, + pub default_destination: Option, #[serde(default = "bool::default")] default_shipmaster_only_steering: bool, #[serde(default = "bool::default")] @@ -21,7 +22,7 @@ pub struct Boat { external: bool, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "lowercase")] pub enum BoatDamage { None, @@ -29,7 +30,7 @@ pub enum BoatDamage { Locked, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct BoatWithDetails { #[serde(flatten)] boat: Boat, @@ -44,6 +45,7 @@ pub struct BoatToAdd<'r> { pub year_built: Option, pub boatbuilder: Option<&'r str>, pub default_shipmaster_only_steering: bool, + pub default_destination: Option<&'r str>, pub skull: bool, pub external: bool, pub location_id: Option, @@ -57,6 +59,7 @@ pub struct BoatToUpdate<'r> { pub year_built: Option, pub boatbuilder: Option<&'r str>, pub default_shipmaster_only_steering: bool, + pub default_destination: Option<&'r str>, pub skull: bool, pub external: bool, pub location_id: i64, @@ -138,7 +141,7 @@ impl Boat { let boats = sqlx::query_as!( Boat, " -SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, skull, external +SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external FROM boat ORDER BY amount_seats DESC " @@ -158,7 +161,7 @@ ORDER BY amount_seats DESC sqlx::query_as!( Boat, " -SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, skull, external +SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external FROM boat WHERE owner is null or owner = ? ORDER BY amount_seats DESC @@ -172,7 +175,7 @@ ORDER BY amount_seats DESC sqlx::query_as!( Boat, " -SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, skull, external +SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external FROM boat WHERE owner = ? OR (owner is null and amount_seats = 1) ORDER BY amount_seats DESC @@ -191,7 +194,7 @@ ORDER BY amount_seats DESC let boats = sqlx::query_as!( Boat, " -SELECT boat.id, boat.name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, skull, external +SELECT boat.id, boat.name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external FROM boat INNER JOIN location ON boat.location_id = location.id WHERE location.name=? @@ -208,12 +211,13 @@ ORDER BY amount_seats DESC pub async fn create(db: &SqlitePool, boat: BoatToAdd<'_>) -> Result<(), String> { sqlx::query!( - "INSERT INTO boat(name, amount_seats, year_built, boatbuilder, default_shipmaster_only_steering, skull, external, location_id, owner) VALUES (?,?,?,?,?,?,?,?,?)", + "INSERT INTO boat(name, amount_seats, year_built, boatbuilder, default_shipmaster_only_steering, default_destination, skull, external, location_id, owner) VALUES (?,?,?,?,?,?,?,?,?,?)", boat.name, boat.amount_seats, boat.year_built, boat.boatbuilder, boat.default_shipmaster_only_steering, + boat.default_destination, boat.skull, boat.external, boat.location_id, @@ -226,12 +230,13 @@ ORDER BY amount_seats DESC pub async fn update(&self, db: &SqlitePool, boat: BoatToUpdate<'_>) -> Result<(), String> { sqlx::query!( - "UPDATE boat SET name=?, amount_seats=?, year_built=?, boatbuilder=?, default_shipmaster_only_steering=?, skull=?, external=?, location_id=?, owner=? WHERE id=?", + "UPDATE boat SET name=?, amount_seats=?, year_built=?, boatbuilder=?, default_shipmaster_only_steering=?, default_destination=?, skull=?, external=?, location_id=?, owner=? WHERE id=?", boat.name, boat.amount_seats, boat.year_built, boat.boatbuilder, boat.default_shipmaster_only_steering, + boat.default_destination, boat.skull, boat.external, boat.location_id, diff --git a/staging-diff.sql b/staging-diff.sql index e69de29..05bf8fe 100644 --- a/staging-diff.sql +++ b/staging-diff.sql @@ -0,0 +1 @@ +ALTER TABLE boat ADD COLUMN "default_destination" TEXT; diff --git a/templates/includes/forms/boat.html.tera b/templates/includes/forms/boat.html.tera index 614ca79..1c2e196 100644 --- a/templates/includes/forms/boat.html.tera +++ b/templates/includes/forms/boat.html.tera @@ -18,6 +18,7 @@ {{ macros::input(label="Bootsbauer", name="boatbuilder", type="text") }} {{ macros::select(label="Standort", data=locations, name='location_id', selected_id=1) }} {{ macros::select(label="Besitzer", data=users, name='owner', default="Verein") }} + {{ macros::input(label='Default destination', name='default_destination', type='text') }}
{{ macros::checkbox(label="handgesteuert", name="default_shipmaster_only_steering")}} {{ macros::checkbox(label="Skull", name="skull", checked=true)}} @@ -50,7 +51,8 @@ {{ macros::select(data=users, label='Besitzer', name='owner', selected_id=boat.owner, default="Vereinsboot") }} {{ macros::input(label='Baujahr', name='year_built', type='number', min=1950, value=boat.year_built) }} {{ macros::input(label='Bootsbauer', name='boatbuilder', type='text', value=boat.boatbuilder) }} - {{ macros::checkbox(label='hangesteuert', name='default_shipmaster_only_steering', id=uuid , checked=boat.default_shipmaster_only_steering) }} + {{ macros::checkbox(label='handgesteuert', name='default_shipmaster_only_steering', id=uuid , checked=boat.default_shipmaster_only_steering) }} + {{ macros::input(label='Default destination', name='default_destination', type='text', value=boat.default_destination) }} {{ macros::checkbox(label='Skull', name='skull', id=uuid , checked=boat.skull) }} {{ macros::checkbox(label='Externes Boot', name='external', id=uuid , checked=boat.external) }}
diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index bcb4266..97b6433 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -13,7 +13,7 @@ {{ amount_seats }}x {% for boat in grouped_boats %} -
+
{{ boat.name }} {% if boat.owner %} @@ -66,10 +66,10 @@ {% macro boat_select(only_ones, id="boat_id") %} {% if not only_ones %} - {{ 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"], wrapper_class="col-span-4", show_seats=true) }} + {{ 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) }} {% else %} {% set ones = boats | filter(attribute="amount_seats", value=1) %} - {{ macros::select(label="Boot", data=ones, name="boat_id", id=id, display=["name", " (","amount_seats", " x)"], extras=["default_shipmaster_only_steering", "amount_seats", "on_water"], wrapper_class="col-span-4", show_seats=true) }} + {{ macros::select(label="Boot", data=ones, 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) }} {% endif %} {% endmacro boat_select %} diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera index d5f2f4f..cc797e7 100644 --- a/templates/includes/macros.html.tera +++ b/templates/includes/macros.html.tera @@ -175,7 +175,7 @@ {% endif %} {% for d in data %} -