From 5cd75ed8c8c18dff4ec0eae76a780926235d64c5 Mon Sep 17 00:00:00 2001 From: Philipp Hofer Date: Fri, 18 Apr 2025 23:24:03 +0200 Subject: [PATCH 1/2] also be able to cancel trips (not only events) --- src/model/mod.rs | 4 ++-- src/model/trip.rs | 20 ++++++++++---------- src/model/tripdetails.rs | 4 ++-- src/model/usertrip.rs | 4 ++-- templates/planned.html.tera | 10 +++++++--- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/model/mod.rs b/src/model/mod.rs index b9d45d3..8cc6613 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -7,7 +7,7 @@ use crate::AMOUNT_DAYS_TO_SHOW_TRIPS_AHEAD; use self::{ event::{Event, EventWithDetails}, - trip::{Trip, TripWithUserAndType}, + trip::{Trip, TripWithDetails}, waterlevel::Waterlevel, weather::Weather, }; @@ -45,7 +45,7 @@ pub mod weather; pub struct Day { day: NaiveDate, events: Vec, - trips: Vec, + trips: Vec, is_pinned: bool, regular_sees_this_day: bool, max_waterlevel: Option, diff --git a/src/model/trip.rs b/src/model/trip.rs index 7565ea0..9b14133 100644 --- a/src/model/trip.rs +++ b/src/model/trip.rs @@ -30,11 +30,12 @@ pub struct Trip { } #[derive(Serialize, Debug)] -pub struct TripWithUserAndType { +pub struct TripWithDetails { #[serde(flatten)] pub trip: Trip, pub rower: Vec, trip_type: Option, + cancelled: bool, } pub struct TripUpdate<'a> { @@ -52,7 +53,7 @@ impl<'a> TripUpdate<'a> { } } -impl TripWithUserAndType { +impl TripWithDetails { pub async fn from(db: &SqlitePool, trip: Trip) -> Self { let mut trip_type = None; if let Some(trip_type_id) = trip.trip_type_id { @@ -60,8 +61,9 @@ impl TripWithUserAndType { } Self { rower: Registration::all_rower(db, trip.trip_details_id.unwrap()).await, - trip, trip_type, + cancelled: trip.is_cancelled(), + trip, } } } @@ -268,12 +270,12 @@ WHERE trip.id=? } } - pub async fn get_for_today(db: &SqlitePool) -> Vec { + pub async fn get_for_today(db: &SqlitePool) -> Vec { let today = Local::now().date_naive(); Self::get_for_day(db, today).await } - pub async fn get_for_day(db: &SqlitePool, day: NaiveDate) -> Vec { + pub async fn get_for_day(db: &SqlitePool, day: NaiveDate) -> Vec { let day = format!("{day}"); let trips = sqlx::query_as!( Trip, @@ -292,7 +294,7 @@ WHERE day=? let mut ret = Vec::new(); for trip in trips { - ret.push(TripWithUserAndType::from(db, trip).await); + ret.push(TripWithDetails::from(db, trip).await); } ret } @@ -336,9 +338,7 @@ WHERE day=? .unwrap(); //Okay, as trip_details can only be created with proper DB backing if update.cancelled() && !was_already_cancelled { - let rowers = TripWithUserAndType::from(db, update.trip.clone()) - .await - .rower; + let rowers = TripWithDetails::from(db, update.trip.clone()).await.rower; for user in rowers { if let Some(user) = User::find_by_name(db, &user.name).await { let notes = match update.notes { @@ -462,7 +462,7 @@ WHERE day=? pub(crate) async fn get_pinned_for_day( db: &sqlx::Pool, day: NaiveDate, - ) -> Vec { + ) -> Vec { let mut trips = Self::get_for_day(db, day).await; trips.retain(|e| e.trip.always_show); trips diff --git a/src/model/tripdetails.rs b/src/model/tripdetails.rs index 46b74f5..e19a2b7 100644 --- a/src/model/tripdetails.rs +++ b/src/model/tripdetails.rs @@ -6,7 +6,7 @@ use sqlx::{FromRow, SqlitePool}; use super::{ notification::Notification, - trip::{Trip, TripWithUserAndType}, + trip::{Trip, TripWithDetails}, triptype::TripType, }; @@ -138,7 +138,7 @@ WHERE day = ? AND planned_starting_time = ? // This trip_details belongs to a planned_event, no need to do anything continue; }; - let pot_coxes = TripWithUserAndType::from(db, trip.clone()).await; + let pot_coxes = TripWithDetails::from(db, trip.clone()).await; let pot_coxes = pot_coxes.rower; for user in pot_coxes { let cox = User::find_by_id(db, trip.cox_id as i32).await.unwrap(); diff --git a/src/model/usertrip.rs b/src/model/usertrip.rs index 4ea4341..9f14ba6 100644 --- a/src/model/usertrip.rs +++ b/src/model/usertrip.rs @@ -3,7 +3,7 @@ use sqlx::{FromRow, SqlitePool}; use super::{ notification::Notification, - trip::{Trip, TripWithUserAndType}, + trip::{Trip, TripWithDetails}, tripdetails::TripDetails, user::{SteeringUser, User}, }; @@ -158,7 +158,7 @@ impl UserTrip { .unwrap() .cancelled() { - let trip = TripWithUserAndType::from(db, trip.clone()).await; + let trip = TripWithDetails::from(db, trip.clone()).await; if trip.rower.len() == 1 { trip_to_delete = Some(trip.trip); } diff --git a/templates/planned.html.tera b/templates/planned.html.tera index e315430..a3c2fac 100644 --- a/templates/planned.html.tera +++ b/templates/planned.html.tera @@ -240,7 +240,11 @@ {{ macros::input(label='Titel', name='name', type='input', value=event.name) }} - {{ macros::input(label='Anzahl Ruderer', name='max_people', type='number', required=true, value=event.max_people, min='0') }} + {% if event.cancelled %} + + {% else %} + {{ macros::input(label='Anzahl Ruderer', name='max_people', type='number', required=true, value=event.max_people, min='0') }} + {% endif %} {{ macros::input(label='Anzahl Steuerleute', name='planned_amount_cox', type='number', value=event.planned_amount_cox, required=true, min='0') }} {{ macros::checkbox(label='Immer anzeigen', name='always_show', id=event.id,checked=event.always_show) }} {{ macros::checkbox(label='Gesperrt', name='is_locked', id=event.id,checked=event.is_locked) }} @@ -300,7 +304,7 @@ {% if trip.always_show and not day.regular_sees_this_day %} 🔮 {% endif -%} - {% if trip.max_people == 0 %} + {% if trip.cancelled %} ⚠ {{ trip.planned_starting_time }} Uhr @@ -322,7 +326,7 @@ {% endif %}
{% else %} - {% if trip.max_people == 0 %} + {% if trip.cancelled %} Wenn du deine Absage absagen (:^)) willst, einfach entsprechende Anzahl an Ruderer oben eintragen. {% else %}