From fa14cfbf83ab8405a94cf40d3985ad57da85bf78 Mon Sep 17 00:00:00 2001 From: philipp Date: Thu, 6 Jun 2024 06:47:41 +0200 Subject: [PATCH 1/3] add cancellation, trip_type and notes to cal export --- src/model/event.rs | 19 ++++++++++++++++++- src/model/tripdetails.rs | 8 ++++++++ src/model/triptype.rs | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/model/event.rs b/src/model/event.rs index f03ada6..bec7892 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -343,6 +343,10 @@ WHERE trip_details.id=? Ok(()) } + pub fn is_cancelled(&self) -> bool { + self.max_people == 0 + } + pub async fn get_ics_feed(db: &SqlitePool) -> String { let mut calendar = ICalendar::new("2.0", "ics-rs"); @@ -355,7 +359,20 @@ WHERE trip_details.id=? event.day.replace('-', ""), event.planned_starting_time.replace(':', "") ))); - vevent.push(Summary::new(event.name)); + let mut name = String::new(); + if event.is_cancelled() { + name.push_str("ABGESAGT :-( "); + } + name.push_str(&format!("{} ", event.name)); + + let tripdetails = event.trip_details(db).await; + if let Some(triptype) = tripdetails.triptype(db).await { + name.push_str(&format!("• {} ", triptype.name)) + } + if let Some(notes) = tripdetails.notes { + name.push_str(&format!("({notes}) ")) + } + vevent.push(Summary::new(name)); calendar.add_event(vevent); } let mut buf = Vec::new(); diff --git a/src/model/tripdetails.rs b/src/model/tripdetails.rs index df1238e..ea4d601 100644 --- a/src/model/tripdetails.rs +++ b/src/model/tripdetails.rs @@ -7,6 +7,7 @@ use sqlx::{FromRow, SqlitePool}; use super::{ notification::Notification, trip::{Trip, TripWithUserAndType}, + triptype::TripType, }; #[derive(FromRow, Debug, Serialize, Deserialize)] @@ -51,6 +52,13 @@ WHERE id like ? .ok() } + pub async fn triptype(&self, db: &SqlitePool) -> Option { + match self.trip_type_id { + None => None, + Some(id) => TripType::find_by_id(db, id).await, + } + } + pub async fn find_by_startingdatetime( db: &SqlitePool, day: String, diff --git a/src/model/triptype.rs b/src/model/triptype.rs index f7aaf94..370fe19 100644 --- a/src/model/triptype.rs +++ b/src/model/triptype.rs @@ -4,7 +4,7 @@ use sqlx::{FromRow, SqlitePool}; #[derive(FromRow, Debug, Serialize, Deserialize, Clone)] pub struct TripType { pub id: i64, - name: String, + pub name: String, desc: String, question: String, icon: String, -- 2.45.2 From e1b78b27259c315aaab5136fb503efc7b03ad90a Mon Sep 17 00:00:00 2001 From: philipp Date: Thu, 6 Jun 2024 06:57:43 +0200 Subject: [PATCH 2/3] don't lose trip_type on event cancellation; don't add empty notes in cal --- src/model/event.rs | 7 +++++-- src/tera/admin/event.rs | 2 +- templates/planned.html.tera | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/model/event.rs b/src/model/event.rs index bec7892..a67a077 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -98,6 +98,7 @@ FROM trip WHERE planned_event_id = ? } } +#[derive(Debug)] pub struct EventUpdate<'a> { pub name: &'a str, pub planned_amount_cox: i32, @@ -361,7 +362,7 @@ WHERE trip_details.id=? ))); let mut name = String::new(); if event.is_cancelled() { - name.push_str("ABGESAGT :-( "); + name.push_str("ABGESAGT! :-( "); } name.push_str(&format!("{} ", event.name)); @@ -370,7 +371,9 @@ WHERE trip_details.id=? name.push_str(&format!("• {} ", triptype.name)) } if let Some(notes) = tripdetails.notes { - name.push_str(&format!("({notes}) ")) + if !notes.is_empty() { + name.push_str(&format!("({notes}) ")) + } } vevent.push(Summary::new(name)); calendar.add_event(vevent); diff --git a/src/tera/admin/event.rs b/src/tera/admin/event.rs index cefde95..4644956 100644 --- a/src/tera/admin/event.rs +++ b/src/tera/admin/event.rs @@ -40,7 +40,7 @@ async fn create( } //TODO: add constraints (e.g. planned_amount_cox > 0) -#[derive(FromForm)] +#[derive(FromForm, Debug)] struct UpdateEventForm<'r> { id: i64, name: &'r str, diff --git a/templates/planned.html.tera b/templates/planned.html.tera index 0ff4851..649df55 100644 --- a/templates/planned.html.tera +++ b/templates/planned.html.tera @@ -251,6 +251,7 @@ {{ macros::input(label='', name='planned_amount_cox', type='hidden', value=event.planned_amount_cox) }} {{ macros::input(label='', name='always_show', type='hidden', value=event.always_show) }} {{ macros::input(label='', name='is_locked', type='hidden', value=event.is_locked) }} + {{ macros::input(label='', name='trip_type', type='hidden', value=event.trip_type_id) }} -- 2.45.2 From bd63f2c386ae34af5bc6f6f14797fb5c7b42a1d3 Mon Sep 17 00:00:00 2001 From: philipp Date: Thu, 6 Jun 2024 06:59:41 +0200 Subject: [PATCH 3/3] use new additional information in test --- src/model/event.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/model/event.rs b/src/model/event.rs index a67a077..6a5aa10 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -434,6 +434,6 @@ mod test { let pool = testdb!(); let actual = Event::get_ics_feed(&pool).await; - assert_eq!("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:ics-rs\r\nBEGIN:VEVENT\r\nUID:1@rudernlinz.at\r\nDTSTAMP:19900101T180000\r\nDTSTART:19700101T100000\r\nSUMMARY:test-planned-event\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", actual); + assert_eq!("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:ics-rs\r\nBEGIN:VEVENT\r\nUID:1@rudernlinz.at\r\nDTSTAMP:19900101T180000\r\nDTSTART:19700101T100000\r\nSUMMARY:test-planned-event (trip_details for a planned event) \r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", actual); } } -- 2.45.2