From 48eb1b7dc275e0cc1d29d7db4f4b1f534c3b4df9 Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 26 Jul 2023 12:56:19 +0200 Subject: [PATCH] clean ui for logbook --- src/model/logbook.rs | 15 +++ src/tera/log.rs | 2 + templates/admin/boat/index.html.tera | 2 +- .../boat => includes/forms}/boat.html.tera | 6 +- templates/includes/forms/log.html.tera | 115 ++++++++++++++++ templates/log.html.tera | 127 +----------------- 6 files changed, 141 insertions(+), 126 deletions(-) rename templates/{admin/boat => includes/forms}/boat.html.tera (97%) create mode 100644 templates/includes/forms/log.html.tera diff --git a/src/model/logbook.rs b/src/model/logbook.rs index d8473f3..dad29e5 100644 --- a/src/model/logbook.rs +++ b/src/model/logbook.rs @@ -182,6 +182,21 @@ impl Logbook { Ok(()) } + pub async fn distances(db: &SqlitePool) -> Vec<(String, i64)>{ + let result = sqlx::query!("SELECT destination, distance_in_km FROM logbook WHERE id IN (SELECT MIN(id) FROM logbook GROUP BY destination) AND destination IS NOT NULL AND distance_in_km IS NOT NULL;") + .fetch_all(db) + .await + .unwrap(); + + result.into_iter().filter_map(|r| { + if let (Some(destination), Some(distance_in_km)) = (r.destination, r.distance_in_km) { + Some((destination, distance_in_km)) + } else { + None + } + }).collect() + } + async fn remove_rowers(&self, db: &mut Transaction<'_, Sqlite>) { sqlx::query!("DELETE FROM rower WHERE logbook_id=?", self.id) .execute(db) diff --git a/src/tera/log.rs b/src/tera/log.rs index 555fa9c..a9df73a 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -26,6 +26,7 @@ async fn index( let coxes = User::cox(db).await; let users = User::all(db).await; let logtypes = LogType::all(db).await; + let distances = Logbook::distances(db).await; let on_water = Logbook::on_water(db).await; let completed = Logbook::completed(db).await; @@ -42,6 +43,7 @@ async fn index( context.insert("loggedin_user", &adminuser.user); context.insert("on_water", &on_water); context.insert("completed", &completed); + context.insert("distances", &distances); Template::render("log", context.into_json()) } diff --git a/templates/admin/boat/index.html.tera b/templates/admin/boat/index.html.tera index 94f1458..968bd25 100644 --- a/templates/admin/boat/index.html.tera +++ b/templates/admin/boat/index.html.tera @@ -1,5 +1,5 @@ {% import "includes/macros" as macros %} -{% import "admin/boat/boat" as boat %} +{% import "includes/forms/boat" as boat %} {% extends "base" %} diff --git a/templates/admin/boat/boat.html.tera b/templates/includes/forms/boat.html.tera similarity index 97% rename from templates/admin/boat/boat.html.tera rename to templates/includes/forms/boat.html.tera index 01e6263..2a7f99b 100644 --- a/templates/admin/boat/boat.html.tera +++ b/templates/includes/forms/boat.html.tera @@ -10,7 +10,7 @@ {{ macros::input(label="Name", name="name", type="text", required=true) }} {{ macros::input(label="Anzahl Sitze", name="amount_seats", type="number", required=true, min=1) }} - {{ macros::input(label="Baujahr", name="year_built", type="number", min=1950, max, 2050) }} + {{ macros::input(label="Baujahr", name="year_built", type="number", min=1950, max=2050) }} {{ macros::input(label="Bootsbauer", name="boatbuilder", type="text") }} {{ macros::select(data=locations, label='location', select_name='location_id', selected_id=1) }} {{ macros::select(data=users, label='users', select_name='owner', default="Vereinsboot") }} @@ -26,7 +26,7 @@ /> -{% endmacro checkbox %} +{% endmacro new %} {% macro edit(boat, uuid) %} @@ -62,4 +62,4 @@ -{% endmacro checkbox %} +{% endmacro edit %} diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera new file mode 100644 index 0000000..55fd6fd --- /dev/null +++ b/templates/includes/forms/log.html.tera @@ -0,0 +1,115 @@ +{% macro new() %} +
+ {{ macros::select(data=boats, select_name='boat_id') }} + {{ macros::select(data=coxes, select_name='shipmaster', selected_id=loggedin_user.id) }} + {{ macros::checkbox(label='shipmaster_only_steering', name='shipmaster_only_steering') }} + Departure: + Arrival: + + Destination: + + {% for distance in distances %} + + {{ macros::input(label="Distanz", name="distance_in_km", type="number", min=0) }} + {{ macros::input(label="Kommentar", name="comments", type="text") }} + {{ macros::select(data=logtypes, select_name='logtype', default="Normal") }} + + + + +
+{% endmacro new %} + + +{% macro show(log, state) %} + Bootsname: {{ log.boat.name }}
+ Schiffsführer: {{ log.shipmaster_user.name }}
+ {% if log.shipmaster_only_steering %} + Schiffsführer steuert nur + {% endif %} + Weggefahren: {{ log.departure }}
+ {% if state == "completed" %} + Angekommen: {{ log.arrival}}
+ {% endif %} + Ziel: {{ log.destination }}
+ {% if state == "completed" %} + Km: {{ log.distance_in_km }}
+ {% endif %} + Kommentare: {{ log.comments }}
+ Logtype: {{ log.logtype }}
+ Ruderer: + {% set amount_rowers = log.rowers | length %} + {% set amount_guests = log.boat.amount_seats - amount_rowers -1 %} + {{ amount_guests }} Gäste (ohne Account) + {% for rower in log.rowers %} + {{ rower.name }} + {% endfor %} + {% if log.shipmaster == loggedin_user.id and state == "on_water" %} + {{ log::home(log=log) }} + {% endif %} +{% endmacro show %} + +{% macro home(log) %} +
+ Destination: + {{ macros::input(label="Distanz", name="distance_in_km", id="distance_in_km_home", type="number", min=0, value=log.distance_in_km) }} + {{ macros::input(label="Kommentar", name="comments", type="text", value=log.comments) }} + {{ macros::select(data=logtypes, select_name='logtype', default="Normal", selected_id=log.logtype) }} + + +
+{% endmacro home %} \ No newline at end of file diff --git a/templates/log.html.tera b/templates/log.html.tera index a101ca5..ae3eb18 100644 --- a/templates/log.html.tera +++ b/templates/log.html.tera @@ -1,142 +1,25 @@ {% import "includes/macros" as macros %} +{% import "includes/forms/log" as log %} {% extends "base" %} {% block content %} - - {% if flash %} - {{ macros::alert(message=flash.1, type=flash.0, class="sm:col-span-2 lg:col-span-3") }} - {% endif %} -

Logbuch

Neue Ausfahrt starten

-
- {{ macros::select(data=boats, select_name='boat_id') }} - {{ macros::select(data=coxes, select_name='shipmaster', selected_id=loggedin_user.id) }} - {{ macros::checkbox(label='shipmaster_only_steering', name='shipmaster_only_steering') }} - Departure: - Arrival: - Destination: - - - {{ macros::input(label="Distanz", name="distance_in_km", type="number", min=0) }} - {{ macros::input(label="Kommentar", name="comments", type="text") }} - {{ macros::select(data=logtypes, select_name='logtype', default="Normal") }} - - - - -
+ {{ log::new() }}

Am Wasser

{% for log in on_water %} - Bootsname: {{ log.boat.name }}
- Schiffsführer: {{ log.shipmaster_user.name }}
- {% if log.shipmaster_only_steering %} - Schiffsführer steuert nur - {% endif %} - Weggefahren: {{ log.departure }}
- Ziel: {{ log.destination }}
- Kommentare: {{ log.comments }}
- Logtype: {{ log.logtype }}
- Ruderer: - {% for rower in log.rowers %} - {{ rower.name }} - {% endfor %} - {% set amount_rowers = log.rowers | length %} - {% set amount_guests = log.boat.amount_seats - amount_rowers -1 %} - {{ amount_guests }} Gäste (ohne Account) - {% if log.shipmaster == loggedin_user.id %} -
- Destination: - {{ macros::input(label="Distanz", name="distance_in_km", id="distance_in_km_home", type="number", min=0, value=log.distance_in_km) }} - {{ macros::input(label="Kommentar", name="comments", type="text", value=log.comments) }} - {{ macros::select(data=logtypes, select_name='logtype', default="Normal", selected_id=log.logtype) }} - - -
- {% endif %} + {{ log::show(log=log, state="on_water") }}
{% endfor %}

Einträge

{% for log in completed %} - Bootsname: {{ log.boat.name }}
- Schiffsführer: {{ log.shipmaster_user.name }}
- {% if log.shipmaster_only_steering %} - Schiffsführer steuert nur - {% endif %} - Ruderer: - {% for rower in log.rowers %} - {{ rower.name }} - {% endfor %} - {% set amount_rowers = log.rowers | length %} - {% set amount_guests = log.boat.amount_seats - amount_rowers -1 %} - {{ amount_guests }} Gäste (ohne Account) - Weggefahren: {{ log.departure }}
- Angekommen: {{ log.arrival}}
- Ziel: {{ log.destination }}
- Km: {{ log.distance_in_km }}
- Kommentare: {{ log.comments }}
- Logtype: {{ log.logtype }}
-
+ {{ log::show(log=log, state="completed") }} +
{% endfor %}
- {% endblock content%}