clean ui for logbook
This commit is contained in:
@ -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)
|
||||
|
@ -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())
|
||||
}
|
||||
|
Reference in New Issue
Block a user