Implement complete recurring event deletion with EXDATE and RRULE UNTIL support

Frontend Changes:
- Add DeleteAction enum with DeleteThis, DeleteFollowing, DeleteSeries options
- Update EventContextMenu to show different delete options for recurring events
- Add exception_dates field to CalendarEvent struct
- Fix occurrence generation to respect EXDATE exclusions
- Add comprehensive RRULE parsing with UNTIL date support
- Fix UNTIL date parsing to handle backend format (YYYYMMDDTHHMMSSZ)
- Enhanced debugging for RRULE processing and occurrence generation

Backend Changes:
- Add exception_dates field to CalendarEvent struct with EXDATE parsing/generation
- Implement update_event method for CalDAV client
- Add fetch_event_by_href helper function
- Update DeleteEventRequest model with delete_action and occurrence_date fields
- Implement proper delete_this logic with EXDATE addition
- Implement delete_following logic with RRULE UNTIL modification
- Add comprehensive logging for delete operations

CalDAV Integration:
- Proper EXDATE generation in iCal format for excluded occurrences
- RRULE modification with UNTIL clause for partial series deletion
- Event updating via CalDAV PUT operations
- Full iCal RFC 5545 compliance for recurring event modifications

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Connor Johnstone
2025-08-29 09:18:35 -04:00
parent e1578ed11c
commit 1b57adab98
7 changed files with 440 additions and 40 deletions

View File

@@ -2,7 +2,7 @@ use yew::prelude::*;
use yew_router::prelude::*;
use gloo_storage::{LocalStorage, Storage};
use web_sys::MouseEvent;
use crate::components::{Sidebar, CreateCalendarModal, ContextMenu, EventContextMenu, CalendarContextMenu, CreateEventModal, EventCreationData, RouteHandler, EventStatus, EventClass, ReminderType, RecurrenceType};
use crate::components::{Sidebar, CreateCalendarModal, ContextMenu, EventContextMenu, CalendarContextMenu, CreateEventModal, EventCreationData, RouteHandler, EventStatus, EventClass, ReminderType, RecurrenceType, DeleteAction};
use crate::services::{CalendarService, calendar_service::{UserInfo, CalendarEvent}};
use chrono::NaiveDate;
@@ -475,6 +475,7 @@ pub fn App() -> Html {
is_open={*event_context_menu_open}
x={event_context_menu_pos.0}
y={event_context_menu_pos.1}
event={(*event_context_menu_event).clone()}
on_close={Callback::from({
let event_context_menu_open = event_context_menu_open.clone();
move |_| event_context_menu_open.set(false)
@@ -484,11 +485,18 @@ pub fn App() -> Html {
let event_context_menu_event = event_context_menu_event.clone();
let event_context_menu_open = event_context_menu_open.clone();
let refresh_calendars = refresh_calendars.clone();
move |_: MouseEvent| {
move |delete_action: DeleteAction| {
if let (Some(token), Some(event)) = ((*auth_token).clone(), (*event_context_menu_event).clone()) {
let _refresh_calendars = refresh_calendars.clone();
let event_context_menu_open = event_context_menu_open.clone();
// Log the delete action for now - we'll implement different behaviors later
match delete_action {
DeleteAction::DeleteThis => web_sys::console::log_1(&"Delete this event".into()),
DeleteAction::DeleteFollowing => web_sys::console::log_1(&"Delete following events".into()),
DeleteAction::DeleteSeries => web_sys::console::log_1(&"Delete entire series".into()),
}
wasm_bindgen_futures::spawn_local(async move {
let calendar_service = CalendarService::new();
@@ -503,9 +511,37 @@ pub fn App() -> Html {
};
if let (Some(calendar_path), Some(event_href)) = (&event.calendar_path, &event.href) {
match calendar_service.delete_event(&token, &password, calendar_path.clone(), event_href.clone()).await {
Ok(_) => {
web_sys::console::log_1(&"Event deleted successfully!".into());
// Convert delete action to string and get occurrence date
let action_str = match delete_action {
DeleteAction::DeleteThis => "delete_this".to_string(),
DeleteAction::DeleteFollowing => "delete_following".to_string(),
DeleteAction::DeleteSeries => "delete_series".to_string(),
};
// Get the occurrence date from the clicked event
let occurrence_date = Some(event.start.date_naive().format("%Y-%m-%d").to_string());
web_sys::console::log_1(&format!("🔄 Delete action: {}", action_str).into());
web_sys::console::log_1(&format!("🔄 Event UID: {}", event.uid).into());
web_sys::console::log_1(&format!("🔄 Event start: {}", event.start).into());
web_sys::console::log_1(&format!("🔄 Occurrence date: {:?}", occurrence_date).into());
match calendar_service.delete_event(
&token,
&password,
calendar_path.clone(),
event_href.clone(),
action_str,
occurrence_date
).await {
Ok(message) => {
web_sys::console::log_1(&format!("Delete response: {}", message).into());
// Show the message to the user to explain what actually happened
if message.contains("Warning") {
web_sys::window().unwrap().alert_with_message(&message).unwrap();
}
// Close the context menu
event_context_menu_open.set(false);
// Force a page reload to refresh the calendar events
@@ -513,6 +549,7 @@ pub fn App() -> Html {
}
Err(err) => {
web_sys::console::log_1(&format!("Failed to delete event: {}", err).into());
web_sys::window().unwrap().alert_with_message(&format!("Failed to delete event: {}", err)).unwrap();
}
}
} else {

View File

@@ -1,12 +1,21 @@
use yew::prelude::*;
use web_sys::MouseEvent;
use crate::services::calendar_service::CalendarEvent;
#[derive(Clone, PartialEq, Debug)]
pub enum DeleteAction {
DeleteThis,
DeleteFollowing,
DeleteSeries,
}
#[derive(Properties, PartialEq)]
pub struct EventContextMenuProps {
pub is_open: bool,
pub x: i32,
pub y: i32,
pub on_delete: Callback<MouseEvent>,
pub event: Option<CalendarEvent>,
pub on_delete: Callback<DeleteAction>,
pub on_close: Callback<()>,
}
@@ -23,11 +32,16 @@ pub fn event_context_menu(props: &EventContextMenuProps) -> Html {
props.x, props.y
);
let on_delete_click = {
// Check if the event is recurring
let is_recurring = props.event.as_ref()
.map(|event| event.recurrence_rule.is_some())
.unwrap_or(false);
let create_delete_callback = |action: DeleteAction| {
let on_delete = props.on_delete.clone();
let on_close = props.on_close.clone();
Callback::from(move |e: MouseEvent| {
on_delete.emit(e);
Callback::from(move |_: MouseEvent| {
on_delete.emit(action.clone());
on_close.emit(());
})
};
@@ -38,10 +52,33 @@ pub fn event_context_menu(props: &EventContextMenuProps) -> Html {
class="context-menu"
style={style}
>
<div class="context-menu-item context-menu-delete" onclick={on_delete_click}>
<span class="context-menu-icon">{"🗑️"}</span>
{"Delete Event"}
</div>
{
if is_recurring {
html! {
<>
<div class="context-menu-item context-menu-delete" onclick={create_delete_callback(DeleteAction::DeleteThis)}>
<span class="context-menu-icon">{"🗑️"}</span>
{"Delete This Event"}
</div>
<div class="context-menu-item context-menu-delete" onclick={create_delete_callback(DeleteAction::DeleteFollowing)}>
<span class="context-menu-icon">{"🗑️"}</span>
{"Delete Following Events"}
</div>
<div class="context-menu-item context-menu-delete" onclick={create_delete_callback(DeleteAction::DeleteSeries)}>
<span class="context-menu-icon">{"🗑️"}</span>
{"Delete Entire Series"}
</div>
</>
}
} else {
html! {
<div class="context-menu-item context-menu-delete" onclick={create_delete_callback(DeleteAction::DeleteThis)}>
<span class="context-menu-icon">{"🗑️"}</span>
{"Delete Event"}
</div>
}
}
}
</div>
}
}

View File

@@ -15,7 +15,7 @@ pub use calendar::Calendar;
pub use event_modal::EventModal;
pub use create_calendar_modal::CreateCalendarModal;
pub use context_menu::ContextMenu;
pub use event_context_menu::EventContextMenu;
pub use event_context_menu::{EventContextMenu, DeleteAction};
pub use calendar_context_menu::CalendarContextMenu;
pub use create_event_modal::{CreateEventModal, EventCreationData, EventStatus, EventClass, ReminderType, RecurrenceType};
pub use sidebar::Sidebar;

View File

@@ -1,4 +1,4 @@
use chrono::{DateTime, Utc, NaiveDate, Datelike, Weekday, Duration};
use chrono::{DateTime, Utc, NaiveDate, Datelike, Weekday, Duration, TimeZone};
use serde::{Deserialize, Serialize};
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;
@@ -56,6 +56,7 @@ pub struct CalendarEvent {
pub created: Option<DateTime<Utc>>,
pub last_modified: Option<DateTime<Utc>>,
pub recurrence_rule: Option<String>,
pub exception_dates: Vec<DateTime<Utc>>,
pub all_day: bool,
pub reminders: Vec<EventReminder>,
pub etag: Option<String>,
@@ -267,8 +268,26 @@ impl CalendarService {
for event in events {
if let Some(ref rrule) = event.recurrence_rule {
web_sys::console::log_1(&format!("📅 Processing recurring event '{}' with RRULE: {}",
event.summary.as_deref().unwrap_or("Untitled"),
rrule
).into());
// Log if event has exception dates
if !event.exception_dates.is_empty() {
web_sys::console::log_1(&format!("📅 Event '{}' has {} exception dates: {:?}",
event.summary.as_deref().unwrap_or("Untitled"),
event.exception_dates.len(),
event.exception_dates
).into());
}
// Generate occurrences for recurring events
let occurrences = Self::generate_occurrences(&event, rrule, start_range, end_range);
web_sys::console::log_1(&format!("📅 Generated {} occurrences for event '{}'",
occurrences.len(),
event.summary.as_deref().unwrap_or("Untitled")
).into());
expanded_events.extend(occurrences);
} else {
// Non-recurring event - add as-is
@@ -290,6 +309,8 @@ impl CalendarService {
// Parse RRULE components
let rrule_upper = rrule.to_uppercase();
web_sys::console::log_1(&format!("🔄 Parsing RRULE: {}", rrule_upper).into());
let components: HashMap<String, String> = rrule_upper
.split(';')
.filter_map(|part| {
@@ -316,25 +337,75 @@ impl CalendarService {
.unwrap_or(100)
.min(365); // Cap at 365 occurrences for performance
// Get UNTIL date if specified
let until_date = components.get("UNTIL")
.and_then(|until_str| {
// Parse UNTIL date in YYYYMMDDTHHMMSSZ format
// Try different parsing approaches for UTC dates
if let Ok(dt) = chrono::NaiveDateTime::parse_from_str(until_str.trim_end_matches('Z'), "%Y%m%dT%H%M%S") {
Some(chrono::Utc.from_utc_datetime(&dt))
} else if let Ok(dt) = chrono::DateTime::parse_from_str(until_str, "%Y%m%dT%H%M%SZ") {
Some(dt.with_timezone(&chrono::Utc))
} else if let Ok(date) = chrono::NaiveDate::parse_from_str(until_str, "%Y%m%d") {
// Handle date-only UNTIL
Some(chrono::Utc.from_utc_datetime(&date.and_hms_opt(23, 59, 59).unwrap()))
} else {
web_sys::console::log_1(&format!("⚠️ Failed to parse UNTIL date: {}", until_str).into());
None
}
});
if let Some(until) = until_date {
web_sys::console::log_1(&format!("📅 RRULE has UNTIL: {}", until).into());
}
let start_date = base_event.start.date_naive();
let mut current_date = start_date;
let mut occurrence_count = 0;
// Generate occurrences based on frequency
while current_date <= end_range && occurrence_count < count {
if current_date >= start_range {
// Create occurrence event
let mut occurrence_event = base_event.clone();
// Adjust dates
let days_diff = current_date.signed_duration_since(start_date).num_days();
occurrence_event.start = base_event.start + Duration::days(days_diff);
if let Some(end) = base_event.end {
occurrence_event.end = Some(end + Duration::days(days_diff));
// Check UNTIL constraint - stop if current occurrence is after UNTIL date
if let Some(until) = until_date {
let current_datetime = base_event.start + Duration::days(current_date.signed_duration_since(start_date).num_days());
if current_datetime > until {
web_sys::console::log_1(&format!("🛑 Stopping at {} due to UNTIL {}", current_datetime, until).into());
break;
}
}
if current_date >= start_range {
// Calculate the occurrence datetime
let days_diff = current_date.signed_duration_since(start_date).num_days();
let occurrence_datetime = base_event.start + Duration::days(days_diff);
occurrences.push(occurrence_event);
// Check if this occurrence is in the exception dates (EXDATE)
let is_exception = base_event.exception_dates.iter().any(|exception_date| {
// Compare dates ignoring sub-second precision
let exception_naive = exception_date.naive_utc();
let occurrence_naive = occurrence_datetime.naive_utc();
// Check if dates match (within a minute to handle minor time differences)
let diff = occurrence_naive - exception_naive;
let matches = diff.num_seconds().abs() < 60;
if matches {
web_sys::console::log_1(&format!("🚫 Excluding occurrence {} due to EXDATE {}", occurrence_naive, exception_naive).into());
}
matches
});
if !is_exception {
// Create occurrence event
let mut occurrence_event = base_event.clone();
occurrence_event.start = occurrence_datetime;
if let Some(end) = base_event.end {
occurrence_event.end = Some(end + Duration::days(days_diff));
}
occurrences.push(occurrence_event);
}
}
// Calculate next occurrence date
@@ -534,8 +605,10 @@ impl CalendarService {
token: &str,
password: &str,
calendar_path: String,
event_href: String
) -> Result<(), String> {
event_href: String,
delete_action: String,
occurrence_date: Option<String>
) -> Result<String, String> {
let window = web_sys::window().ok_or("No global window exists")?;
let opts = RequestInit::new();
@@ -544,7 +617,9 @@ impl CalendarService {
let body = serde_json::json!({
"calendar_path": calendar_path,
"event_href": event_href
"event_href": event_href,
"delete_action": delete_action,
"occurrence_date": occurrence_date
});
let body_string = serde_json::to_string(&body)
@@ -580,7 +655,11 @@ impl CalendarService {
.ok_or("Response text is not a string")?;
if resp.ok() {
Ok(())
// Parse the response to get the message
let response: serde_json::Value = serde_json::from_str(&text_string)
.map_err(|e| format!("Failed to parse response JSON: {}", e))?;
let message = response["message"].as_str().unwrap_or("Event deleted successfully").to_string();
Ok(message)
} else {
Err(format!("Request failed with status {}: {}", resp.status(), text_string))
}