Compare commits

..

4 Commits

Author SHA1 Message Date
a0528c1c65 Merge pull request 'nicer-cal' (#573) from nicer-cal into staging
All checks were successful
CI/CD Pipeline / test (push) Successful in 10m22s
CI/CD Pipeline / deploy-staging (push) Successful in 7m19s
CI/CD Pipeline / deploy-main (push) Has been skipped
Reviewed-on: #573
2024-06-06 07:11:32 +02:00
bd63f2c386 use new additional information in test
All checks were successful
CI/CD Pipeline / test (push) Successful in 10m10s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped
2024-06-06 06:59:41 +02:00
e1b78b2725 don't lose trip_type on event cancellation; don't add empty notes in cal
Some checks failed
CI/CD Pipeline / deploy-staging (push) Blocked by required conditions
CI/CD Pipeline / deploy-main (push) Blocked by required conditions
CI/CD Pipeline / test (push) Has been cancelled
2024-06-06 06:57:43 +02:00
fa14cfbf83 add cancellation, trip_type and notes to cal export
Some checks failed
CI/CD Pipeline / test (push) Failing after 9m56s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped
2024-06-06 06:47:41 +02:00
5 changed files with 33 additions and 4 deletions

View File

@ -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,
@ -343,6 +344,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 +360,22 @@ 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 {
if !notes.is_empty() {
name.push_str(&format!("({notes}) "))
}
}
vevent.push(Summary::new(name));
calendar.add_event(vevent);
}
let mut buf = Vec::new();
@ -414,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);
}
}

View File

@ -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<TripType> {
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,

View File

@ -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,

View File

@ -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,

View File

@ -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) }}
<input value="Ausfahrt absagen" class="btn btn-alert" type="submit" />
</form>
</div>