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() %} +
+{% endmacro new %} + + +{% macro show(log, state) %} + Bootsname: {{ log.boat.name }}