Compare commits
34 Commits
bugfix/ext
...
ce9914e388
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce9914e388 | ||
|
|
faf5ce2cfd | ||
|
|
2fee7a15f9 | ||
|
|
7caf3539f7 | ||
|
|
1538869f4a | ||
|
|
7ce7d4c9d9 | ||
|
|
037b733d48 | ||
|
|
cb1bb23132 | ||
|
|
5c406569af | ||
|
|
4aca6c7fae | ||
|
|
fd80624429 | ||
|
|
b530dcaa69 | ||
|
|
0821573041 | ||
|
|
703c9ee2f5 | ||
|
|
5854ad291d | ||
|
|
ac1164fd81 | ||
|
|
a6092d13ce | ||
|
|
acc5ced551 | ||
|
|
890940fe31 | ||
|
|
fdea5cd646 | ||
|
|
b307be7eb1 | ||
|
|
9d84c380d1 | ||
|
|
fad03f94f9 | ||
| a4476dcfae | |||
|
|
ca1ca0c3b1 | ||
|
|
64dbf65beb | ||
|
|
96585440d1 | ||
|
|
a297d38276 | ||
|
|
4fdaa9931d | ||
|
|
c6c7b38bef | ||
|
|
78db2cc00f | ||
|
|
73d191c5ca | ||
| d930468748 | |||
|
|
4cbc495c48 |
@@ -4,7 +4,7 @@
|
||||

|
||||
|
||||
>[!WARNING]
|
||||
>This project was entirely vibe coded. It's my first attempt vibe coding anything, but I just sat down one day and realized this was something I've wanted to build for many years, but would just take way too long. With AI, I've been able to lay out the majority of the app in one long weekend. So proceed at your own risk, but I actually think the app is pretty solid.
|
||||
>This project was entirely vibe coded. It's my first attempt vibe coding anything, but I just sat down one day and realized this was something I've wanted to build for many years, but would just take way too long. With AI, I've been able to lay out the majority of the app in one long weekend. So proceed at your own risk, but I actually think the app is pretty decent. There are still a lot of places where the AI has implemented some really poor solutions to the problems that I didn't catch, but I've begun using it for my own general use.
|
||||
|
||||
A modern CalDAV web client built with Rust WebAssembly.
|
||||
|
||||
|
||||
@@ -39,19 +39,13 @@ impl AuthService {
|
||||
request.username.clone(),
|
||||
request.password.clone(),
|
||||
);
|
||||
println!("📝 Created CalDAV config");
|
||||
|
||||
// Test authentication against CalDAV server
|
||||
let caldav_client = CalDAVClient::new(caldav_config.clone());
|
||||
println!("🔗 Created CalDAV client, attempting to discover calendars...");
|
||||
|
||||
// Try to discover calendars as an authentication test
|
||||
match caldav_client.discover_calendars().await {
|
||||
Ok(calendars) => {
|
||||
println!(
|
||||
"✅ Authentication successful! Found {} calendars",
|
||||
calendars.len()
|
||||
);
|
||||
Ok(_calendars) => {
|
||||
|
||||
// Find or create user in database
|
||||
let user_repo = UserRepository::new(&self.db);
|
||||
|
||||
@@ -167,8 +167,6 @@ impl CalDAVClient {
|
||||
};
|
||||
|
||||
let basic_auth = self.config.get_basic_auth();
|
||||
println!("🔑 REPORT Basic Auth: Basic {}", basic_auth);
|
||||
println!("🌐 REPORT URL: {}", url);
|
||||
|
||||
let response = self
|
||||
.http_client
|
||||
@@ -349,6 +347,8 @@ impl CalDAVClient {
|
||||
}
|
||||
}
|
||||
full_prop.push_str(&format!(":{}", prop_value));
|
||||
|
||||
|
||||
full_properties.insert(prop_name, full_prop);
|
||||
}
|
||||
|
||||
@@ -358,27 +358,30 @@ impl CalDAVClient {
|
||||
.ok_or_else(|| CalDAVError::ParseError("Missing UID field".to_string()))?
|
||||
.clone();
|
||||
|
||||
// Determine if it's an all-day event FIRST by checking for VALUE=DATE parameter per RFC 5545
|
||||
let empty_string = String::new();
|
||||
let dtstart_raw = full_properties.get("DTSTART").unwrap_or(&empty_string);
|
||||
let dtstart_value = properties.get("DTSTART").unwrap_or(&empty_string);
|
||||
let all_day = dtstart_raw.contains("VALUE=DATE") || (!dtstart_value.contains("T") && dtstart_value.len() == 8);
|
||||
|
||||
|
||||
// Parse start time (required)
|
||||
let start = properties
|
||||
let start_prop = properties
|
||||
.get("DTSTART")
|
||||
.ok_or_else(|| CalDAVError::ParseError("Missing DTSTART field".to_string()))?;
|
||||
let start = self.parse_datetime(start, full_properties.get("DTSTART"))?;
|
||||
let (start_naive, start_tzid) = self.parse_datetime_with_tz(start_prop, full_properties.get("DTSTART"))?;
|
||||
|
||||
// Parse end time (optional - use start time if not present)
|
||||
let end = if let Some(dtend) = properties.get("DTEND") {
|
||||
Some(self.parse_datetime(dtend, full_properties.get("DTEND"))?)
|
||||
let (end_naive, end_tzid) = if let Some(dtend) = properties.get("DTEND") {
|
||||
let (end_dt, end_tz) = self.parse_datetime_with_tz(dtend, full_properties.get("DTEND"))?;
|
||||
(Some(end_dt), end_tz)
|
||||
} else if let Some(_duration) = properties.get("DURATION") {
|
||||
// TODO: Parse duration and add to start time
|
||||
Some(start)
|
||||
(Some(start_naive), start_tzid.clone())
|
||||
} else {
|
||||
None
|
||||
(None, None)
|
||||
};
|
||||
|
||||
// Determine if it's an all-day event by checking for VALUE=DATE parameter
|
||||
let empty_string = String::new();
|
||||
let dtstart_raw = properties.get("DTSTART").unwrap_or(&empty_string);
|
||||
let all_day = dtstart_raw.contains("VALUE=DATE") || (!dtstart_raw.contains("T") && dtstart_raw.len() == 8);
|
||||
|
||||
// Parse status
|
||||
let status = properties
|
||||
.get("STATUS")
|
||||
@@ -411,23 +414,35 @@ impl CalDAVClient {
|
||||
.map(|s| s.split(',').map(|c| c.trim().to_string()).collect())
|
||||
.unwrap_or_default();
|
||||
|
||||
// Parse dates
|
||||
let created = properties
|
||||
.get("CREATED")
|
||||
.and_then(|s| self.parse_datetime(s, None).ok());
|
||||
|
||||
let last_modified = properties
|
||||
.get("LAST-MODIFIED")
|
||||
.and_then(|s| self.parse_datetime(s, None).ok());
|
||||
// Parse dates with timezone information
|
||||
let (created_naive, created_tzid) = if let Some(created_str) = properties.get("CREATED") {
|
||||
match self.parse_datetime_with_tz(created_str, None) {
|
||||
Ok((dt, tz)) => (Some(dt), tz),
|
||||
Err(_) => (None, None)
|
||||
}
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
|
||||
let (last_modified_naive, last_modified_tzid) = if let Some(modified_str) = properties.get("LAST-MODIFIED") {
|
||||
match self.parse_datetime_with_tz(modified_str, None) {
|
||||
Ok((dt, tz)) => (Some(dt), tz),
|
||||
Err(_) => (None, None)
|
||||
}
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
|
||||
// Parse exception dates (EXDATE)
|
||||
let exdate = self.parse_exdate(&event);
|
||||
|
||||
// Create VEvent with required fields
|
||||
let mut vevent = VEvent::new(uid, start);
|
||||
// Create VEvent with parsed naive datetime and timezone info
|
||||
let mut vevent = VEvent::new(uid, start_naive);
|
||||
|
||||
// Set optional fields
|
||||
vevent.dtend = end;
|
||||
// Set optional fields with timezone information
|
||||
vevent.dtend = end_naive;
|
||||
vevent.dtstart_tzid = start_tzid;
|
||||
vevent.dtend_tzid = end_tzid;
|
||||
vevent.summary = properties.get("SUMMARY").cloned();
|
||||
vevent.description = properties.get("DESCRIPTION").cloned();
|
||||
vevent.location = properties.get("LOCATION").cloned();
|
||||
@@ -450,10 +465,13 @@ impl CalDAVClient {
|
||||
vevent.attendees = Vec::new();
|
||||
|
||||
vevent.categories = categories;
|
||||
vevent.created = created;
|
||||
vevent.last_modified = last_modified;
|
||||
vevent.created = created_naive;
|
||||
vevent.created_tzid = created_tzid;
|
||||
vevent.last_modified = last_modified_naive;
|
||||
vevent.last_modified_tzid = last_modified_tzid;
|
||||
vevent.rrule = properties.get("RRULE").cloned();
|
||||
vevent.exdate = exdate;
|
||||
vevent.exdate = exdate.into_iter().map(|dt| dt.naive_utc()).collect();
|
||||
vevent.exdate_tzid = None; // TODO: Parse timezone info for EXDATE
|
||||
vevent.all_day = all_day;
|
||||
|
||||
// Parse alarms
|
||||
@@ -566,11 +584,9 @@ impl CalDAVClient {
|
||||
pub async fn discover_calendars(&self) -> Result<Vec<String>, CalDAVError> {
|
||||
// First, try to discover user calendars if we have a calendar path in config
|
||||
if let Some(calendar_path) = &self.config.calendar_path {
|
||||
println!("Using configured calendar path: {}", calendar_path);
|
||||
return Ok(vec![calendar_path.clone()]);
|
||||
}
|
||||
|
||||
println!("No calendar path configured, discovering calendars...");
|
||||
|
||||
// Try different common CalDAV discovery paths
|
||||
// Note: paths should be relative to the server URL base
|
||||
@@ -583,20 +599,16 @@ impl CalDAVClient {
|
||||
let mut has_valid_caldav_response = false;
|
||||
|
||||
for path in discovery_paths {
|
||||
println!("Trying discovery path: {}", path);
|
||||
match self.discover_calendars_at_path(&path).await {
|
||||
Ok(calendars) => {
|
||||
println!("Found {} calendar(s) at {}", calendars.len(), path);
|
||||
has_valid_caldav_response = true;
|
||||
all_calendars.extend(calendars);
|
||||
}
|
||||
Err(CalDAVError::ServerError(status)) => {
|
||||
Err(CalDAVError::ServerError(_status)) => {
|
||||
// HTTP error - this might be expected for some paths, continue trying
|
||||
println!("Discovery path {} returned HTTP {}, trying next path", path, status);
|
||||
}
|
||||
Err(e) => {
|
||||
// Network or other error - this suggests the server isn't reachable or isn't CalDAV
|
||||
println!("Discovery failed for path {}: {:?}", path, e);
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
@@ -653,7 +665,6 @@ impl CalDAVClient {
|
||||
}
|
||||
|
||||
let body = response.text().await.map_err(CalDAVError::RequestError)?;
|
||||
println!("Discovery response for {}: {}", path, body);
|
||||
|
||||
let mut calendar_paths = Vec::new();
|
||||
|
||||
@@ -664,7 +675,6 @@ impl CalDAVClient {
|
||||
|
||||
// Extract href first
|
||||
if let Some(href) = self.extract_xml_content(response_content, "href") {
|
||||
println!("🔍 Checking resource: {}", href);
|
||||
|
||||
// Check if this is a calendar collection by looking for supported-calendar-component-set
|
||||
// This indicates it's an actual calendar that can contain events
|
||||
@@ -688,14 +698,10 @@ impl CalDAVClient {
|
||||
&& !href.ends_with("/calendars/")
|
||||
&& href.ends_with('/')
|
||||
{
|
||||
println!("📅 Found calendar collection: {}", href);
|
||||
calendar_paths.push(href);
|
||||
} else {
|
||||
println!("❌ Skipping system/root directory: {}", href);
|
||||
}
|
||||
} else {
|
||||
println!("ℹ️ Not a calendar collection: {} (is_calendar: {}, has_collection: {})",
|
||||
href, is_calendar, has_collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -704,6 +710,99 @@ impl CalDAVClient {
|
||||
Ok(calendar_paths)
|
||||
}
|
||||
|
||||
/// Parse iCal datetime format and return NaiveDateTime + timezone info
|
||||
/// According to RFC 5545: if no TZID parameter is provided, treat as UTC
|
||||
fn parse_datetime_with_tz(
|
||||
&self,
|
||||
datetime_str: &str,
|
||||
original_property: Option<&String>,
|
||||
) -> Result<(chrono::NaiveDateTime, Option<String>), CalDAVError> {
|
||||
// Extract timezone information from the original property if available
|
||||
let mut timezone_id: Option<String> = None;
|
||||
if let Some(prop) = original_property {
|
||||
// Look for TZID parameter in the property
|
||||
// Format: DTSTART;TZID=America/Denver:20231225T090000
|
||||
if let Some(tzid_start) = prop.find("TZID=") {
|
||||
let tzid_part = &prop[tzid_start + 5..];
|
||||
if let Some(tzid_end) = tzid_part.find(':') {
|
||||
timezone_id = Some(tzid_part[..tzid_end].to_string());
|
||||
} else if let Some(tzid_end) = tzid_part.find(';') {
|
||||
timezone_id = Some(tzid_part[..tzid_end].to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clean the datetime string - remove any TZID prefix if present
|
||||
let cleaned = datetime_str.replace("TZID=", "").trim().to_string();
|
||||
|
||||
// Split on colon to separate TZID from datetime if format is "TZID=America/Denver:20231225T090000"
|
||||
let datetime_part = if let Some(colon_pos) = cleaned.find(':') {
|
||||
&cleaned[colon_pos + 1..]
|
||||
} else {
|
||||
&cleaned
|
||||
};
|
||||
|
||||
// Try different parsing formats
|
||||
let formats = [
|
||||
"%Y%m%dT%H%M%SZ", // UTC format: 20231225T120000Z
|
||||
"%Y%m%dT%H%M%S", // Local format: 20231225T120000
|
||||
"%Y%m%d", // Date only: 20231225
|
||||
];
|
||||
|
||||
for format in &formats {
|
||||
// Try parsing as UTC format (with Z suffix)
|
||||
if datetime_part.ends_with('Z') {
|
||||
if let Ok(dt) = chrono::NaiveDateTime::parse_from_str(&datetime_part[..datetime_part.len()-1], "%Y%m%dT%H%M%S") {
|
||||
// Z suffix means UTC, ignore any TZID parameter
|
||||
return Ok((dt, Some("UTC".to_string())));
|
||||
}
|
||||
}
|
||||
|
||||
// Try parsing with timezone offset (e.g., 20231225T120000-0500)
|
||||
if let Ok(dt) = chrono::DateTime::parse_from_str(datetime_part, "%Y%m%dT%H%M%S%z") {
|
||||
// Convert to naive UTC time and return UTC timezone
|
||||
return Ok((dt.naive_utc(), Some("UTC".to_string())));
|
||||
}
|
||||
|
||||
// Try ISO format with timezone offset (e.g., 2023-12-25T12:00:00-05:00)
|
||||
if let Ok(dt) = chrono::DateTime::parse_from_str(datetime_part, "%Y-%m-%dT%H:%M:%S%z") {
|
||||
// Convert to naive UTC time and return UTC timezone
|
||||
return Ok((dt.naive_utc(), Some("UTC".to_string())));
|
||||
}
|
||||
|
||||
// Try ISO format with Z suffix (e.g., 2023-12-25T12:00:00Z)
|
||||
if let Ok(dt) = chrono::DateTime::parse_from_str(datetime_part, "%Y-%m-%dT%H:%M:%SZ") {
|
||||
// Z suffix means UTC
|
||||
return Ok((dt.naive_utc(), Some("UTC".to_string())));
|
||||
}
|
||||
|
||||
// Special handling for date-only format (all-day events)
|
||||
if *format == "%Y%m%d" {
|
||||
if let Ok(date) = chrono::NaiveDate::parse_from_str(datetime_part, format) {
|
||||
// Convert date to midnight datetime for all-day events
|
||||
let naive_dt = date.and_hms_opt(0, 0, 0).unwrap();
|
||||
let tz = timezone_id.unwrap_or_else(|| "UTC".to_string());
|
||||
return Ok((naive_dt, Some(tz)));
|
||||
}
|
||||
} else {
|
||||
// Try parsing as naive datetime for time-based formats
|
||||
if let Ok(naive_dt) = chrono::NaiveDateTime::parse_from_str(datetime_part, format) {
|
||||
// Per RFC 5545: if no TZID parameter is provided, treat as UTC
|
||||
let tz = timezone_id.unwrap_or_else(|| "UTC".to_string());
|
||||
|
||||
// If it's UTC, the naive time is already correct
|
||||
// If it's a local timezone, we store the naive time and the timezone ID
|
||||
return Ok((naive_dt, Some(tz)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Err(CalDAVError::ParseError(format!(
|
||||
"Could not parse datetime: {}",
|
||||
datetime_str
|
||||
)))
|
||||
}
|
||||
|
||||
/// Parse iCal datetime format with timezone support
|
||||
fn parse_datetime(
|
||||
&self,
|
||||
@@ -1207,8 +1306,19 @@ impl CalDAVClient {
|
||||
// Format datetime for iCal (YYYYMMDDTHHMMSSZ format)
|
||||
let format_datetime =
|
||||
|dt: &DateTime<Utc>| -> String { dt.format("%Y%m%dT%H%M%SZ").to_string() };
|
||||
let format_datetime_naive =
|
||||
|dt: &chrono::NaiveDateTime| -> String { dt.format("%Y%m%dT%H%M%S").to_string() };
|
||||
|
||||
let format_date = |dt: &DateTime<Utc>| -> String { dt.format("%Y%m%d").to_string() };
|
||||
let _format_date = |dt: &DateTime<Utc>| -> String { dt.format("%Y%m%d").to_string() };
|
||||
|
||||
// Format NaiveDateTime for iCal (local time without Z suffix)
|
||||
let format_naive_datetime = |dt: &chrono::NaiveDateTime| -> String {
|
||||
dt.format("%Y%m%dT%H%M%S").to_string()
|
||||
};
|
||||
|
||||
let format_naive_date = |dt: &chrono::NaiveDateTime| -> String {
|
||||
dt.format("%Y%m%d").to_string()
|
||||
};
|
||||
|
||||
// Start building the iCal event
|
||||
let mut ical = String::new();
|
||||
@@ -1225,15 +1335,77 @@ impl CalDAVClient {
|
||||
if event.all_day {
|
||||
ical.push_str(&format!(
|
||||
"DTSTART;VALUE=DATE:{}\r\n",
|
||||
format_date(&event.dtstart)
|
||||
format_naive_date(&event.dtstart)
|
||||
));
|
||||
if let Some(end) = &event.dtend {
|
||||
ical.push_str(&format!("DTEND;VALUE=DATE:{}\r\n", format_date(end)));
|
||||
ical.push_str(&format!("DTEND;VALUE=DATE:{}\r\n", format_naive_date(end)));
|
||||
}
|
||||
} else {
|
||||
ical.push_str(&format!("DTSTART:{}\r\n", format_datetime(&event.dtstart)));
|
||||
// Include timezone information for non-all-day events per RFC 5545
|
||||
if let Some(ref start_tzid) = event.dtstart_tzid {
|
||||
if start_tzid == "UTC" {
|
||||
// UTC events should use Z suffix format
|
||||
ical.push_str(&format!("DTSTART:{}Z\r\n", format_naive_datetime(&event.dtstart)));
|
||||
} else if start_tzid.starts_with('+') || start_tzid.starts_with('-') {
|
||||
// Timezone offset format (e.g., "+05:00", "-04:00")
|
||||
// Convert local time to UTC using the offset and use Z format
|
||||
if let Ok(offset_hours) = start_tzid[1..3].parse::<i32>() {
|
||||
let offset_minutes = start_tzid[4..6].parse::<i32>().unwrap_or(0);
|
||||
let total_offset_minutes = if start_tzid.starts_with('+') {
|
||||
offset_hours * 60 + offset_minutes
|
||||
} else {
|
||||
-(offset_hours * 60 + offset_minutes)
|
||||
};
|
||||
|
||||
// Convert local time to UTC by applying the inverse offset
|
||||
// If timezone is +04:00 (local ahead of UTC), subtract to get UTC
|
||||
// If timezone is -04:00 (local behind UTC), add to get UTC
|
||||
let utc_time = event.dtstart - chrono::Duration::minutes(total_offset_minutes as i64);
|
||||
ical.push_str(&format!("DTSTART:{}Z\r\n", format_naive_datetime(&utc_time)));
|
||||
} else {
|
||||
// Fallback to floating time if offset parsing fails
|
||||
ical.push_str(&format!("DTSTART:{}\r\n", format_naive_datetime(&event.dtstart)));
|
||||
}
|
||||
} else {
|
||||
// Named timezone (e.g., "America/New_York") - use TZID parameter per RFC 5545
|
||||
ical.push_str(&format!("DTSTART;TZID={}:{}\r\n", start_tzid, format_naive_datetime(&event.dtstart)));
|
||||
}
|
||||
} else {
|
||||
// No timezone info - treat as floating local time per RFC 5545
|
||||
ical.push_str(&format!("DTSTART:{}\r\n", format_naive_datetime(&event.dtstart)));
|
||||
}
|
||||
|
||||
if let Some(end) = &event.dtend {
|
||||
ical.push_str(&format!("DTEND:{}\r\n", format_datetime(end)));
|
||||
if let Some(ref end_tzid) = event.dtend_tzid {
|
||||
if end_tzid == "UTC" {
|
||||
// UTC events should use Z suffix format
|
||||
ical.push_str(&format!("DTEND:{}Z\r\n", format_naive_datetime(end)));
|
||||
} else if end_tzid.starts_with('+') || end_tzid.starts_with('-') {
|
||||
// Timezone offset format (e.g., "+05:00", "-04:00")
|
||||
// Convert local time to UTC using the offset and use Z format
|
||||
if let Ok(offset_hours) = end_tzid[1..3].parse::<i32>() {
|
||||
let offset_minutes = end_tzid[4..6].parse::<i32>().unwrap_or(0);
|
||||
let total_offset_minutes = if end_tzid.starts_with('+') {
|
||||
offset_hours * 60 + offset_minutes
|
||||
} else {
|
||||
-(offset_hours * 60 + offset_minutes)
|
||||
};
|
||||
|
||||
// Convert local time to UTC by subtracting the offset
|
||||
let utc_time = *end - chrono::Duration::minutes(total_offset_minutes as i64);
|
||||
ical.push_str(&format!("DTEND:{}Z\r\n", format_naive_datetime(&utc_time)));
|
||||
} else {
|
||||
// Fallback to floating time if offset parsing fails
|
||||
ical.push_str(&format!("DTEND:{}\r\n", format_naive_datetime(end)));
|
||||
}
|
||||
} else {
|
||||
// Named timezone (e.g., "America/New_York") - use TZID parameter per RFC 5545
|
||||
ical.push_str(&format!("DTEND;TZID={}:{}\r\n", end_tzid, format_naive_datetime(end)));
|
||||
}
|
||||
} else {
|
||||
// No timezone info - treat as floating local time per RFC 5545
|
||||
ical.push_str(&format!("DTEND:{}\r\n", format_naive_datetime(end)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1289,7 +1461,18 @@ impl CalDAVClient {
|
||||
|
||||
// Creation and modification times
|
||||
if let Some(created) = &event.created {
|
||||
ical.push_str(&format!("CREATED:{}\r\n", format_datetime(created)));
|
||||
if let Some(ref created_tzid) = event.created_tzid {
|
||||
if created_tzid == "UTC" {
|
||||
ical.push_str(&format!("CREATED:{}Z\r\n", format_datetime_naive(created)));
|
||||
} else {
|
||||
// Per RFC 5545, CREATED typically should be in UTC or floating time
|
||||
// Treat non-UTC as floating time
|
||||
ical.push_str(&format!("CREATED:{}\r\n", format_datetime_naive(created)));
|
||||
}
|
||||
} else {
|
||||
// No timezone info - output as floating time per RFC 5545
|
||||
ical.push_str(&format!("CREATED:{}\r\n", format_datetime_naive(created)));
|
||||
}
|
||||
}
|
||||
|
||||
ical.push_str(&format!("LAST-MODIFIED:{}\r\n", format_datetime(&now)));
|
||||
@@ -1346,10 +1529,10 @@ impl CalDAVClient {
|
||||
if event.all_day {
|
||||
ical.push_str(&format!(
|
||||
"EXDATE;VALUE=DATE:{}\r\n",
|
||||
format_date(exception_date)
|
||||
format_naive_date(exception_date)
|
||||
));
|
||||
} else {
|
||||
ical.push_str(&format!("EXDATE:{}\r\n", format_datetime(exception_date)));
|
||||
ical.push_str(&format!("EXDATE:{}\r\n", format_naive_datetime(exception_date)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,10 +82,6 @@ pub async fn get_user_info(
|
||||
.await
|
||||
.map_err(|e| ApiError::Internal(format!("Failed to discover calendars: {}", e)))?;
|
||||
|
||||
println!(
|
||||
"✅ Authentication successful! Found {} calendars",
|
||||
calendar_paths.len()
|
||||
);
|
||||
|
||||
let calendars: Vec<CalendarInfo> = calendar_paths
|
||||
.iter()
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::{
|
||||
AppState,
|
||||
};
|
||||
use calendar_models::{
|
||||
AlarmAction, AlarmTrigger, Attendee, CalendarUser, EventClass, EventStatus, VAlarm, VEvent,
|
||||
Attendee, CalendarUser, EventClass, EventStatus, VEvent,
|
||||
};
|
||||
|
||||
use super::auth::{extract_bearer_token, extract_password_header};
|
||||
@@ -35,7 +35,6 @@ pub async fn get_calendar_events(
|
||||
// Extract and verify token
|
||||
let token = extract_bearer_token(&headers)?;
|
||||
let password = extract_password_header(&headers)?;
|
||||
println!("🔑 API call with password length: {}", password.len());
|
||||
|
||||
// Create CalDAV config from token and password
|
||||
let config = state
|
||||
@@ -85,7 +84,7 @@ pub async fn get_calendar_events(
|
||||
} - chrono::Duration::days(1);
|
||||
|
||||
all_events.retain(|event| {
|
||||
let event_date = event.dtstart.date_naive();
|
||||
let event_date = event.dtstart.date();
|
||||
|
||||
// For non-recurring events, check if the event date is within the month
|
||||
if event.rrule.is_none() || event.rrule.as_ref().unwrap().is_empty() {
|
||||
@@ -127,7 +126,6 @@ pub async fn get_calendar_events(
|
||||
});
|
||||
}
|
||||
|
||||
println!("📅 Returning {} events", all_events.len());
|
||||
Ok(Json(all_events))
|
||||
}
|
||||
|
||||
@@ -234,26 +232,26 @@ pub async fn delete_event(
|
||||
if event.rrule.is_some() && !event.rrule.as_ref().unwrap().is_empty() {
|
||||
// Recurring event - add EXDATE for this occurrence
|
||||
if let Some(occurrence_date) = &request.occurrence_date {
|
||||
let exception_utc = if let Ok(date) =
|
||||
let exception_datetime = if let Ok(date) =
|
||||
chrono::DateTime::parse_from_rfc3339(occurrence_date)
|
||||
{
|
||||
// RFC3339 format (with time and timezone)
|
||||
date.with_timezone(&chrono::Utc)
|
||||
// RFC3339 format (with time and timezone) - convert to naive
|
||||
date.naive_utc()
|
||||
} else if let Ok(naive_date) =
|
||||
chrono::NaiveDate::parse_from_str(occurrence_date, "%Y-%m-%d")
|
||||
{
|
||||
// Simple date format (YYYY-MM-DD)
|
||||
naive_date.and_hms_opt(0, 0, 0).unwrap().and_utc()
|
||||
naive_date.and_hms_opt(0, 0, 0).unwrap()
|
||||
} else {
|
||||
return Err(ApiError::BadRequest(format!("Invalid occurrence date format: {}. Expected RFC3339 or YYYY-MM-DD", occurrence_date)));
|
||||
};
|
||||
|
||||
let mut updated_event = event;
|
||||
updated_event.exdate.push(exception_utc);
|
||||
updated_event.exdate.push(exception_datetime);
|
||||
|
||||
println!(
|
||||
"🔄 Adding EXDATE {} to recurring event {}",
|
||||
exception_utc.format("%Y%m%dT%H%M%SZ"),
|
||||
exception_datetime.format("%Y%m%dT%H%M%S"),
|
||||
updated_event.uid
|
||||
);
|
||||
|
||||
@@ -453,19 +451,16 @@ pub async fn create_event(
|
||||
calendar_paths[0].clone()
|
||||
};
|
||||
|
||||
// Parse dates and times
|
||||
// Parse dates and times as local times (no UTC conversion)
|
||||
let start_datetime =
|
||||
parse_event_datetime(&request.start_date, &request.start_time, request.all_day)
|
||||
parse_event_datetime_local(&request.start_date, &request.start_time, request.all_day)
|
||||
.map_err(|e| ApiError::BadRequest(format!("Invalid start date/time: {}", e)))?;
|
||||
|
||||
let mut end_datetime = parse_event_datetime(&request.end_date, &request.end_time, request.all_day)
|
||||
let end_datetime = parse_event_datetime_local(&request.end_date, &request.end_time, request.all_day)
|
||||
.map_err(|e| ApiError::BadRequest(format!("Invalid end date/time: {}", e)))?;
|
||||
|
||||
// For all-day events, add one day to end date for RFC-5545 compliance
|
||||
// RFC-5545 uses exclusive end dates for all-day events
|
||||
if request.all_day {
|
||||
end_datetime = end_datetime + chrono::Duration::days(1);
|
||||
}
|
||||
// Note: Frontend already converts inclusive UI dates to exclusive dates for all-day events
|
||||
// No additional conversion needed here
|
||||
|
||||
// Validate that end is after start (allow equal times for all-day events)
|
||||
if request.all_day {
|
||||
@@ -527,19 +522,8 @@ pub async fn create_event(
|
||||
.collect()
|
||||
};
|
||||
|
||||
// Parse alarms - convert from minutes string to EventReminder structs
|
||||
let alarms: Vec<crate::calendar::EventReminder> = if request.reminder.trim().is_empty() {
|
||||
Vec::new()
|
||||
} else {
|
||||
match request.reminder.parse::<i32>() {
|
||||
Ok(minutes) => vec![crate::calendar::EventReminder {
|
||||
minutes_before: minutes,
|
||||
action: crate::calendar::ReminderAction::Display,
|
||||
description: None,
|
||||
}],
|
||||
Err(_) => Vec::new(),
|
||||
}
|
||||
};
|
||||
// Use VAlarms directly from request (no conversion needed)
|
||||
let alarms = request.alarms;
|
||||
|
||||
// Check if recurrence is already a full RRULE or just a simple type
|
||||
let rrule = if request.recurrence.starts_with("FREQ=") {
|
||||
@@ -594,9 +578,13 @@ pub async fn create_event(
|
||||
}
|
||||
};
|
||||
|
||||
// Create the VEvent struct (RFC 5545 compliant)
|
||||
// Create the VEvent struct (RFC 5545 compliant) with local times
|
||||
let mut event = VEvent::new(uid, start_datetime);
|
||||
event.dtend = Some(end_datetime);
|
||||
|
||||
// Set timezone information from client
|
||||
event.dtstart_tzid = Some(request.timezone.clone());
|
||||
event.dtend_tzid = Some(request.timezone.clone());
|
||||
event.summary = if request.title.trim().is_empty() {
|
||||
None
|
||||
} else {
|
||||
@@ -646,21 +634,7 @@ pub async fn create_event(
|
||||
event.categories = categories;
|
||||
event.rrule = rrule;
|
||||
event.all_day = request.all_day;
|
||||
event.alarms = alarms
|
||||
.into_iter()
|
||||
.map(|reminder| VAlarm {
|
||||
action: AlarmAction::Display,
|
||||
trigger: AlarmTrigger::Duration(chrono::Duration::minutes(
|
||||
-reminder.minutes_before as i64,
|
||||
)),
|
||||
duration: None,
|
||||
repeat: None,
|
||||
description: reminder.description,
|
||||
summary: None,
|
||||
attendees: Vec::new(),
|
||||
attach: Vec::new(),
|
||||
})
|
||||
.collect();
|
||||
event.alarms = alarms;
|
||||
event.calendar_path = Some(calendar_path.clone());
|
||||
|
||||
// Create the event on the CalDAV server
|
||||
@@ -757,19 +731,18 @@ pub async fn update_event(
|
||||
let (mut event, calendar_path, event_href) = found_event
|
||||
.ok_or_else(|| ApiError::NotFound(format!("Event with UID '{}' not found", request.uid)))?;
|
||||
|
||||
// Parse dates and times
|
||||
// Parse dates and times as local times (no UTC conversion)
|
||||
println!("🕐 UPDATE: Received start_date: '{}', start_time: '{}', timezone: '{}'",
|
||||
request.start_date, request.start_time, request.timezone);
|
||||
let start_datetime =
|
||||
parse_event_datetime(&request.start_date, &request.start_time, request.all_day)
|
||||
parse_event_datetime_local(&request.start_date, &request.start_time, request.all_day)
|
||||
.map_err(|e| ApiError::BadRequest(format!("Invalid start date/time: {}", e)))?;
|
||||
|
||||
let mut end_datetime = parse_event_datetime(&request.end_date, &request.end_time, request.all_day)
|
||||
let end_datetime = parse_event_datetime_local(&request.end_date, &request.end_time, request.all_day)
|
||||
.map_err(|e| ApiError::BadRequest(format!("Invalid end date/time: {}", e)))?;
|
||||
|
||||
// For all-day events, add one day to end date for RFC-5545 compliance
|
||||
// RFC-5545 uses exclusive end dates for all-day events
|
||||
if request.all_day {
|
||||
end_datetime = end_datetime + chrono::Duration::days(1);
|
||||
}
|
||||
// Note: Frontend already converts inclusive UI dates to exclusive dates for all-day events
|
||||
// No additional conversion needed here
|
||||
|
||||
// Validate that end is after start (allow equal times for all-day events)
|
||||
if request.all_day {
|
||||
@@ -786,9 +759,11 @@ pub async fn update_event(
|
||||
}
|
||||
}
|
||||
|
||||
// Update event properties
|
||||
// Update event properties with local times and timezone info
|
||||
event.dtstart = start_datetime;
|
||||
event.dtend = Some(end_datetime);
|
||||
event.dtstart_tzid = Some(request.timezone.clone());
|
||||
event.dtend_tzid = Some(request.timezone.clone());
|
||||
event.summary = if request.title.trim().is_empty() {
|
||||
None
|
||||
} else {
|
||||
@@ -822,6 +797,99 @@ pub async fn update_event(
|
||||
|
||||
event.priority = request.priority;
|
||||
|
||||
// Process recurrence information to set RRULE
|
||||
println!("🔄 Processing recurrence: '{}'", request.recurrence);
|
||||
println!("🔄 Recurrence days: {:?}", request.recurrence_days);
|
||||
println!("🔄 Recurrence interval: {:?}", request.recurrence_interval);
|
||||
println!("🔄 Recurrence count: {:?}", request.recurrence_count);
|
||||
println!("🔄 Recurrence end date: {:?}", request.recurrence_end_date);
|
||||
|
||||
let rrule = if request.recurrence.starts_with("FREQ=") {
|
||||
// Frontend sent a complete RRULE string, use it directly
|
||||
if request.recurrence.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(request.recurrence.clone())
|
||||
}
|
||||
} else {
|
||||
// Parse recurrence type and build RRULE with all parameters
|
||||
let base_rrule = match request.recurrence.to_uppercase().as_str() {
|
||||
"DAILY" => Some("FREQ=DAILY".to_string()),
|
||||
"WEEKLY" => {
|
||||
// Handle weekly recurrence with optional BYDAY parameter
|
||||
let mut rrule = "FREQ=WEEKLY".to_string();
|
||||
|
||||
// Check if specific days are selected (recurrence_days has 7 elements: [Sun, Mon, Tue, Wed, Thu, Fri, Sat])
|
||||
if request.recurrence_days.len() == 7 {
|
||||
let selected_days: Vec<&str> = request
|
||||
.recurrence_days
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(i, &selected)| {
|
||||
if selected {
|
||||
Some(match i {
|
||||
0 => "SU", // Sunday
|
||||
1 => "MO", // Monday
|
||||
2 => "TU", // Tuesday
|
||||
3 => "WE", // Wednesday
|
||||
4 => "TH", // Thursday
|
||||
5 => "FR", // Friday
|
||||
6 => "SA", // Saturday
|
||||
_ => return None,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
if !selected_days.is_empty() {
|
||||
rrule = format!("{};BYDAY={}", rrule, selected_days.join(","));
|
||||
}
|
||||
}
|
||||
|
||||
Some(rrule)
|
||||
}
|
||||
"MONTHLY" => Some("FREQ=MONTHLY".to_string()),
|
||||
"YEARLY" => Some("FREQ=YEARLY".to_string()),
|
||||
"NONE" | "" => None, // Clear any existing recurrence
|
||||
_ => None,
|
||||
};
|
||||
|
||||
// Add INTERVAL, COUNT, and UNTIL parameters if specified
|
||||
if let Some(mut rrule_string) = base_rrule {
|
||||
// Add INTERVAL parameter (every N days/weeks/months/years)
|
||||
if let Some(interval) = request.recurrence_interval {
|
||||
if interval > 1 {
|
||||
rrule_string = format!("{};INTERVAL={}", rrule_string, interval);
|
||||
}
|
||||
}
|
||||
|
||||
// Add COUNT or UNTIL parameter (but not both - COUNT takes precedence)
|
||||
if let Some(count) = request.recurrence_count {
|
||||
rrule_string = format!("{};COUNT={}", rrule_string, count);
|
||||
} else if let Some(end_date) = &request.recurrence_end_date {
|
||||
// Convert YYYY-MM-DD to YYYYMMDD format for UNTIL
|
||||
if let Ok(date) = chrono::NaiveDate::parse_from_str(end_date, "%Y-%m-%d") {
|
||||
rrule_string = format!("{};UNTIL={}", rrule_string, date.format("%Y%m%d"));
|
||||
}
|
||||
}
|
||||
|
||||
Some(rrule_string)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
event.rrule = rrule.clone();
|
||||
println!("🔄 Set event RRULE to: {:?}", rrule);
|
||||
|
||||
if rrule.is_some() {
|
||||
println!("✨ Converting singleton event to recurring series with RRULE: {}", rrule.as_ref().unwrap());
|
||||
} else {
|
||||
println!("📝 Event remains non-recurring (no RRULE set)");
|
||||
}
|
||||
|
||||
// Update the event on the CalDAV server
|
||||
println!(
|
||||
"📝 Updating event {} at calendar_path: {}, event_href: {}",
|
||||
@@ -840,33 +908,29 @@ pub async fn update_event(
|
||||
}))
|
||||
}
|
||||
|
||||
fn parse_event_datetime(
|
||||
fn parse_event_datetime_local(
|
||||
date_str: &str,
|
||||
time_str: &str,
|
||||
all_day: bool,
|
||||
) -> Result<chrono::DateTime<chrono::Utc>, String> {
|
||||
use chrono::{NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
|
||||
) -> Result<chrono::NaiveDateTime, String> {
|
||||
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
|
||||
|
||||
// Parse the date
|
||||
let date = NaiveDate::parse_from_str(date_str, "%Y-%m-%d")
|
||||
.map_err(|_| format!("Invalid date format: {}. Expected YYYY-MM-DD", date_str))?;
|
||||
|
||||
if all_day {
|
||||
// For all-day events, use noon UTC to avoid timezone boundary issues
|
||||
// This ensures the date remains correct when converted to any local timezone
|
||||
// For all-day events, use start of day
|
||||
let datetime = date
|
||||
.and_hms_opt(12, 0, 0)
|
||||
.ok_or_else(|| "Failed to create noon datetime".to_string())?;
|
||||
Ok(Utc.from_utc_datetime(&datetime))
|
||||
.and_hms_opt(0, 0, 0)
|
||||
.ok_or_else(|| "Failed to create start-of-day datetime".to_string())?;
|
||||
Ok(datetime)
|
||||
} else {
|
||||
// Parse the time
|
||||
let time = NaiveTime::parse_from_str(time_str, "%H:%M")
|
||||
.map_err(|_| format!("Invalid time format: {}. Expected HH:MM", time_str))?;
|
||||
|
||||
// Combine date and time
|
||||
let datetime = NaiveDateTime::new(date, time);
|
||||
|
||||
// Frontend now sends UTC times, so treat as UTC directly
|
||||
Ok(Utc.from_utc_datetime(&datetime))
|
||||
// Combine date and time - now keeping as local time
|
||||
Ok(NaiveDateTime::new(date, time))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,17 +285,25 @@ fn convert_ical_to_vevent(ical_event: IcalEvent) -> Result<VEvent, Box<dyn std::
|
||||
|
||||
let vevent = VEvent {
|
||||
uid: uid.unwrap_or_else(|| Uuid::new_v4().to_string()),
|
||||
dtstart,
|
||||
dtend,
|
||||
dtstart: dtstart.naive_utc(),
|
||||
dtstart_tzid: None, // TODO: Parse timezone from ICS
|
||||
dtend: dtend.map(|dt| dt.naive_utc()),
|
||||
dtend_tzid: None, // TODO: Parse timezone from ICS
|
||||
summary,
|
||||
description,
|
||||
location,
|
||||
all_day,
|
||||
rrule,
|
||||
rdate: Vec::new(),
|
||||
rdate_tzid: None,
|
||||
exdate: Vec::new(), // External calendars don't need exception handling
|
||||
exdate_tzid: None,
|
||||
recurrence_id: None,
|
||||
recurrence_id_tzid: None,
|
||||
created: None,
|
||||
created_tzid: None,
|
||||
last_modified: None,
|
||||
last_modified_tzid: None,
|
||||
dtstamp: Utc::now(),
|
||||
sequence: Some(0),
|
||||
status: None,
|
||||
@@ -313,7 +321,6 @@ fn convert_ical_to_vevent(ical_event: IcalEvent) -> Result<VEvent, Box<dyn std::
|
||||
class: None,
|
||||
contact: None,
|
||||
comment: None,
|
||||
rdate: Vec::new(),
|
||||
alarms: Vec::new(),
|
||||
etag: None,
|
||||
href: None,
|
||||
@@ -478,32 +485,23 @@ fn parse_datetime_with_tz(datetime_str: &str, tzid: Option<&str>) -> Option<Date
|
||||
fn deduplicate_events(mut events: Vec<VEvent>) -> Vec<VEvent> {
|
||||
use std::collections::HashMap;
|
||||
|
||||
let original_count = events.len();
|
||||
|
||||
// First pass: Group by UID and prefer recurring events over single events with same UID
|
||||
let mut uid_groups: HashMap<String, Vec<VEvent>> = HashMap::new();
|
||||
|
||||
for event in events.drain(..) {
|
||||
// Debug logging to understand what's happening
|
||||
println!("🔍 Event: '{}' at {} (RRULE: {}) - UID: {}",
|
||||
event.summary.as_ref().unwrap_or(&"No Title".to_string()),
|
||||
event.dtstart.format("%Y-%m-%d %H:%M"),
|
||||
if event.rrule.is_some() { "Yes" } else { "No" },
|
||||
event.uid
|
||||
);
|
||||
|
||||
uid_groups.entry(event.uid.clone()).or_insert_with(Vec::new).push(event);
|
||||
}
|
||||
|
||||
let mut uid_deduplicated_events = Vec::new();
|
||||
|
||||
for (uid, mut events_with_uid) in uid_groups.drain() {
|
||||
for (_uid, mut events_with_uid) in uid_groups.drain() {
|
||||
if events_with_uid.len() == 1 {
|
||||
// Only one event with this UID, keep it
|
||||
uid_deduplicated_events.push(events_with_uid.into_iter().next().unwrap());
|
||||
} else {
|
||||
// Multiple events with same UID - prefer recurring over non-recurring
|
||||
println!("🔍 Found {} events with UID '{}'", events_with_uid.len(), uid);
|
||||
|
||||
// Sort by preference: recurring events first, then by completeness
|
||||
events_with_uid.sort_by(|a, b| {
|
||||
@@ -522,10 +520,6 @@ fn deduplicate_events(mut events: Vec<VEvent>) -> Vec<VEvent> {
|
||||
|
||||
// Keep the first (preferred) event
|
||||
let preferred_event = events_with_uid.into_iter().next().unwrap();
|
||||
println!("🔄 UID dedup: Keeping '{}' (RRULE: {})",
|
||||
preferred_event.summary.as_ref().unwrap_or(&"No Title".to_string()),
|
||||
if preferred_event.rrule.is_some() { "Yes" } else { "No" }
|
||||
);
|
||||
uid_deduplicated_events.push(preferred_event);
|
||||
}
|
||||
}
|
||||
@@ -552,13 +546,12 @@ fn deduplicate_events(mut events: Vec<VEvent>) -> Vec<VEvent> {
|
||||
|
||||
let mut deduplicated_recurring = Vec::new();
|
||||
|
||||
for (title, events_with_title) in title_groups.drain() {
|
||||
for (_title, events_with_title) in title_groups.drain() {
|
||||
if events_with_title.len() == 1 {
|
||||
// Single event with this title, keep as-is
|
||||
deduplicated_recurring.push(events_with_title.into_iter().next().unwrap());
|
||||
} else {
|
||||
// Multiple events with same title - consolidate or deduplicate
|
||||
println!("🔍 Found {} events with title '{}'", events_with_title.len(), title);
|
||||
|
||||
// Check if these are actually different recurring patterns for the same logical event
|
||||
let consolidated = consolidate_same_title_events(events_with_title);
|
||||
@@ -585,15 +578,9 @@ fn deduplicate_events(mut events: Vec<VEvent>) -> Vec<VEvent> {
|
||||
let existing_completeness = event_completeness_score(existing_event);
|
||||
|
||||
if current_completeness > existing_completeness {
|
||||
println!("🔄 Replacing single event: Keeping '{}' over '{}'",
|
||||
event.summary.as_ref().unwrap_or(&"No Title".to_string()),
|
||||
existing_event.summary.as_ref().unwrap_or(&"No Title".to_string())
|
||||
);
|
||||
deduplicated_single[existing_index] = event;
|
||||
} else {
|
||||
println!("🚫 Discarding duplicate single event: Keeping existing '{}'",
|
||||
existing_event.summary.as_ref().unwrap_or(&"No Title".to_string())
|
||||
);
|
||||
// Discarding duplicate single event - keeping existing
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -613,10 +600,6 @@ fn deduplicate_events(mut events: Vec<VEvent>) -> Vec<VEvent> {
|
||||
});
|
||||
|
||||
if is_rrule_generated {
|
||||
println!("🚫 Discarding RRULE-generated instance: '{}' at {} would be generated by recurring event",
|
||||
event.summary.as_ref().unwrap_or(&"No Title".to_string()),
|
||||
event.dtstart.format("%Y-%m-%d %H:%M")
|
||||
);
|
||||
} else {
|
||||
// This is a unique single event
|
||||
seen_single.insert(dedup_key, deduplicated_single.len());
|
||||
@@ -628,11 +611,6 @@ fn deduplicate_events(mut events: Vec<VEvent>) -> Vec<VEvent> {
|
||||
let mut result = deduplicated_recurring;
|
||||
result.extend(deduplicated_single);
|
||||
|
||||
println!("📊 Deduplication complete: {} -> {} events ({} recurring, {} single)",
|
||||
original_count, result.len(),
|
||||
result.iter().filter(|e| e.rrule.is_some()).count(),
|
||||
result.iter().filter(|e| e.rrule.is_none()).count()
|
||||
);
|
||||
|
||||
result
|
||||
}
|
||||
@@ -658,14 +636,6 @@ fn consolidate_same_title_events(events: Vec<VEvent>) -> Vec<VEvent> {
|
||||
}
|
||||
|
||||
// Log the RRULEs we're working with
|
||||
for event in &events {
|
||||
if let Some(rrule) = &event.rrule {
|
||||
println!("🔍 RRULE for '{}': {}",
|
||||
event.summary.as_ref().unwrap_or(&"No Title".to_string()),
|
||||
rrule
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if all events have similar time patterns and could be consolidated
|
||||
let first_event = &events[0];
|
||||
@@ -688,7 +658,6 @@ fn consolidate_same_title_events(events: Vec<VEvent>) -> Vec<VEvent> {
|
||||
});
|
||||
|
||||
if !can_consolidate {
|
||||
println!("🚫 Cannot consolidate events - different times or durations");
|
||||
// Just deduplicate exact duplicates
|
||||
return deduplicate_exact_recurring_events(events);
|
||||
}
|
||||
@@ -701,13 +670,11 @@ fn consolidate_same_title_events(events: Vec<VEvent>) -> Vec<VEvent> {
|
||||
if weekly_events.len() >= 2 && weekly_events.len() == events.len() {
|
||||
// All events are weekly - try to consolidate into a single multi-day weekly pattern
|
||||
if let Some(consolidated) = consolidate_weekly_patterns(&events) {
|
||||
println!("✅ Successfully consolidated {} weekly patterns into one", events.len());
|
||||
return vec![consolidated];
|
||||
}
|
||||
}
|
||||
|
||||
// If we can't consolidate, just deduplicate exact matches and keep the most complete one
|
||||
println!("🚫 Cannot consolidate - keeping most complete event");
|
||||
let deduplicated = deduplicate_exact_recurring_events(events);
|
||||
|
||||
// If we still have multiple events, keep only the most complete one
|
||||
@@ -834,7 +801,7 @@ fn would_event_be_generated_by_rrule(recurring_event: &VEvent, single_event: &VE
|
||||
if rrule.contains("FREQ=DAILY") {
|
||||
// Daily recurrence
|
||||
let interval = extract_interval_from_rrule(rrule).unwrap_or(1);
|
||||
let days_diff = (single_event.dtstart.date_naive() - recurring_event.dtstart.date_naive()).num_days();
|
||||
let days_diff = (single_event.dtstart.date() - recurring_event.dtstart.date()).num_days();
|
||||
|
||||
if days_diff >= 0 && days_diff % interval as i64 == 0 {
|
||||
// Check if times match (allowing for timezone differences within same day)
|
||||
@@ -845,7 +812,7 @@ fn would_event_be_generated_by_rrule(recurring_event: &VEvent, single_event: &VE
|
||||
} else if rrule.contains("FREQ=WEEKLY") {
|
||||
// Weekly recurrence
|
||||
let interval = extract_interval_from_rrule(rrule).unwrap_or(1);
|
||||
let days_diff = (single_event.dtstart.date_naive() - recurring_event.dtstart.date_naive()).num_days();
|
||||
let days_diff = (single_event.dtstart.date() - recurring_event.dtstart.date()).num_days();
|
||||
|
||||
// First check if it's the same day of week and time
|
||||
let recurring_weekday = recurring_event.dtstart.weekday();
|
||||
|
||||
@@ -14,6 +14,33 @@ use calendar_models::{EventClass, EventStatus, VEvent};
|
||||
|
||||
use super::auth::{extract_bearer_token, extract_password_header};
|
||||
|
||||
fn parse_event_datetime_local(
|
||||
date_str: &str,
|
||||
time_str: &str,
|
||||
all_day: bool,
|
||||
) -> Result<chrono::NaiveDateTime, String> {
|
||||
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
|
||||
|
||||
// Parse the date
|
||||
let date = NaiveDate::parse_from_str(date_str, "%Y-%m-%d")
|
||||
.map_err(|_| format!("Invalid date format: {}. Expected YYYY-MM-DD", date_str))?;
|
||||
|
||||
if all_day {
|
||||
// For all-day events, use start of day
|
||||
let datetime = date
|
||||
.and_hms_opt(0, 0, 0)
|
||||
.ok_or_else(|| "Failed to create start-of-day datetime".to_string())?;
|
||||
Ok(datetime)
|
||||
} else {
|
||||
// Parse the time
|
||||
let time = NaiveTime::parse_from_str(time_str, "%H:%M")
|
||||
.map_err(|_| format!("Invalid time format: {}. Expected HH:MM", time_str))?;
|
||||
|
||||
// Combine date and time - now keeping as local time
|
||||
Ok(NaiveDateTime::new(date, time))
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new recurring event series
|
||||
pub async fn create_event_series(
|
||||
State(state): State<Arc<AppState>>,
|
||||
@@ -106,84 +133,27 @@ pub async fn create_event_series(
|
||||
|
||||
println!("📅 Using calendar path: {}", calendar_path);
|
||||
|
||||
// Parse datetime components
|
||||
let start_date =
|
||||
chrono::NaiveDate::parse_from_str(&request.start_date, "%Y-%m-%d").map_err(|_| {
|
||||
ApiError::BadRequest("Invalid start_date format. Expected YYYY-MM-DD".to_string())
|
||||
})?;
|
||||
// Parse dates and times as local times (no UTC conversion)
|
||||
let start_datetime = parse_event_datetime_local(&request.start_date, &request.start_time, request.all_day)
|
||||
.map_err(|e| ApiError::BadRequest(format!("Invalid start date/time: {}", e)))?;
|
||||
|
||||
let (start_datetime, end_datetime) = if request.all_day {
|
||||
// For all-day events, use the dates as-is
|
||||
let start_dt = start_date
|
||||
.and_hms_opt(0, 0, 0)
|
||||
.ok_or_else(|| ApiError::BadRequest("Invalid start date".to_string()))?;
|
||||
let end_datetime = parse_event_datetime_local(&request.end_date, &request.end_time, request.all_day)
|
||||
.map_err(|e| ApiError::BadRequest(format!("Invalid end date/time: {}", e)))?;
|
||||
|
||||
let end_date = if !request.end_date.is_empty() {
|
||||
chrono::NaiveDate::parse_from_str(&request.end_date, "%Y-%m-%d").map_err(|_| {
|
||||
ApiError::BadRequest("Invalid end_date format. Expected YYYY-MM-DD".to_string())
|
||||
})?
|
||||
} else {
|
||||
start_date
|
||||
};
|
||||
|
||||
let end_dt = end_date
|
||||
.and_hms_opt(23, 59, 59)
|
||||
.ok_or_else(|| ApiError::BadRequest("Invalid end date".to_string()))?;
|
||||
|
||||
// Frontend now sends UTC times, so treat as UTC directly
|
||||
let start_local = chrono::Utc.from_utc_datetime(&start_dt);
|
||||
let end_local = chrono::Utc.from_utc_datetime(&end_dt);
|
||||
|
||||
(
|
||||
start_local.with_timezone(&chrono::Utc),
|
||||
end_local.with_timezone(&chrono::Utc),
|
||||
)
|
||||
} else {
|
||||
// Parse times for timed events
|
||||
let start_time = if !request.start_time.is_empty() {
|
||||
chrono::NaiveTime::parse_from_str(&request.start_time, "%H:%M").map_err(|_| {
|
||||
ApiError::BadRequest("Invalid start_time format. Expected HH:MM".to_string())
|
||||
})?
|
||||
} else {
|
||||
chrono::NaiveTime::from_hms_opt(9, 0, 0).unwrap() // Default to 9 AM
|
||||
};
|
||||
|
||||
let end_time = if !request.end_time.is_empty() {
|
||||
chrono::NaiveTime::parse_from_str(&request.end_time, "%H:%M").map_err(|_| {
|
||||
ApiError::BadRequest("Invalid end_time format. Expected HH:MM".to_string())
|
||||
})?
|
||||
} else {
|
||||
chrono::NaiveTime::from_hms_opt(10, 0, 0).unwrap() // Default to 1 hour duration
|
||||
};
|
||||
|
||||
let start_dt = start_date.and_time(start_time);
|
||||
let end_dt = if !request.end_date.is_empty() {
|
||||
let end_date = chrono::NaiveDate::parse_from_str(&request.end_date, "%Y-%m-%d")
|
||||
.map_err(|_| {
|
||||
ApiError::BadRequest("Invalid end_date format. Expected YYYY-MM-DD".to_string())
|
||||
})?;
|
||||
end_date.and_time(end_time)
|
||||
} else {
|
||||
start_date.and_time(end_time)
|
||||
};
|
||||
|
||||
// Frontend now sends UTC times, so treat as UTC directly
|
||||
let start_local = chrono::Utc.from_utc_datetime(&start_dt);
|
||||
let end_local = chrono::Utc.from_utc_datetime(&end_dt);
|
||||
|
||||
(
|
||||
start_local.with_timezone(&chrono::Utc),
|
||||
end_local.with_timezone(&chrono::Utc),
|
||||
)
|
||||
};
|
||||
// Note: Frontend already converts inclusive UI dates to exclusive dates for all-day events
|
||||
// No additional conversion needed here
|
||||
|
||||
// Generate a unique UID for the series
|
||||
let uid = format!("series-{}", uuid::Uuid::new_v4().to_string());
|
||||
|
||||
// Create the VEvent for the series
|
||||
// Create the VEvent for the series with local times
|
||||
let mut event = VEvent::new(uid.clone(), start_datetime);
|
||||
event.dtend = Some(end_datetime);
|
||||
event.all_day = request.all_day; // Set the all_day flag properly
|
||||
|
||||
// Set timezone information from client
|
||||
event.dtstart_tzid = Some(request.timezone.clone());
|
||||
event.dtend_tzid = Some(request.timezone.clone());
|
||||
event.summary = if request.title.trim().is_empty() {
|
||||
None
|
||||
} else {
|
||||
@@ -257,6 +227,8 @@ pub async fn update_event_series(
|
||||
"🔄 Update event series request received: series_uid='{}', update_scope='{}', recurrence_count={:?}, recurrence_end_date={:?}",
|
||||
request.series_uid, request.update_scope, request.recurrence_count, request.recurrence_end_date
|
||||
);
|
||||
println!("🕐 SERIES: Received start_date: '{}', start_time: '{}', timezone: '{}'",
|
||||
request.start_date, request.start_time, request.timezone);
|
||||
|
||||
// Extract and verify token
|
||||
let token = extract_bearer_token(&headers)?;
|
||||
@@ -372,7 +344,7 @@ pub async fn update_event_series(
|
||||
);
|
||||
|
||||
// Parse datetime components for the update
|
||||
let original_start_date = existing_event.dtstart.date_naive();
|
||||
let original_start_date = existing_event.dtstart.date();
|
||||
|
||||
// For "this_and_future" and "this_only" updates, use the occurrence date for the modified event
|
||||
// For "all_in_series" updates, preserve the original series start date
|
||||
@@ -399,7 +371,7 @@ pub async fn update_event_series(
|
||||
// Calculate the duration from the original event
|
||||
let original_duration_days = existing_event
|
||||
.dtend
|
||||
.map(|end| (end.date_naive() - existing_event.dtstart.date_naive()).num_days())
|
||||
.map(|end| (end.date() - existing_event.dtstart.date()).num_days())
|
||||
.unwrap_or(0);
|
||||
start_date + chrono::Duration::days(original_duration_days)
|
||||
} else {
|
||||
@@ -410,11 +382,8 @@ pub async fn update_event_series(
|
||||
.and_hms_opt(12, 0, 0)
|
||||
.ok_or_else(|| ApiError::BadRequest("Invalid end date".to_string()))?;
|
||||
|
||||
// For all-day events, use UTC directly (no local conversion needed)
|
||||
(
|
||||
chrono::Utc.from_utc_datetime(&start_dt),
|
||||
chrono::Utc.from_utc_datetime(&end_dt),
|
||||
)
|
||||
// For all-day events, use local times directly
|
||||
(start_dt, end_dt)
|
||||
} else {
|
||||
let start_time = if !request.start_time.is_empty() {
|
||||
chrono::NaiveTime::parse_from_str(&request.start_time, "%H:%M").map_err(|_| {
|
||||
@@ -445,17 +414,11 @@ pub async fn update_event_series(
|
||||
.dtend
|
||||
.map(|end| end - existing_event.dtstart)
|
||||
.unwrap_or_else(|| chrono::Duration::hours(1));
|
||||
(chrono::Utc.from_utc_datetime(&start_dt) + original_duration).naive_utc()
|
||||
start_dt + original_duration
|
||||
};
|
||||
|
||||
// Frontend now sends UTC times, so treat as UTC directly
|
||||
let start_local = chrono::Utc.from_utc_datetime(&start_dt);
|
||||
let end_local = chrono::Utc.from_utc_datetime(&end_dt);
|
||||
|
||||
(
|
||||
start_local.with_timezone(&chrono::Utc),
|
||||
end_local.with_timezone(&chrono::Utc),
|
||||
)
|
||||
// Frontend now sends local times, so use them directly
|
||||
(start_dt, end_dt)
|
||||
};
|
||||
|
||||
// Handle different update scopes
|
||||
@@ -702,8 +665,8 @@ fn build_series_rrule_with_freq(
|
||||
fn update_entire_series(
|
||||
existing_event: &mut VEvent,
|
||||
request: &UpdateEventSeriesRequest,
|
||||
start_datetime: chrono::DateTime<chrono::Utc>,
|
||||
end_datetime: chrono::DateTime<chrono::Utc>,
|
||||
start_datetime: chrono::NaiveDateTime,
|
||||
end_datetime: chrono::NaiveDateTime,
|
||||
) -> Result<(VEvent, u32), ApiError> {
|
||||
// Clone the existing event to preserve all metadata
|
||||
let mut updated_event = existing_event.clone();
|
||||
@@ -711,6 +674,8 @@ fn update_entire_series(
|
||||
// Update only the modified properties from the request
|
||||
updated_event.dtstart = start_datetime;
|
||||
updated_event.dtend = Some(end_datetime);
|
||||
updated_event.dtstart_tzid = Some(request.timezone.clone());
|
||||
updated_event.dtend_tzid = Some(request.timezone.clone());
|
||||
updated_event.summary = if request.title.trim().is_empty() {
|
||||
existing_event.summary.clone() // Keep original if empty
|
||||
} else {
|
||||
@@ -743,8 +708,9 @@ fn update_entire_series(
|
||||
|
||||
// Update timestamps
|
||||
let now = chrono::Utc::now();
|
||||
let now_naive = now.naive_utc();
|
||||
updated_event.dtstamp = now;
|
||||
updated_event.last_modified = Some(now);
|
||||
updated_event.last_modified = Some(now_naive);
|
||||
// Keep original created timestamp to preserve event history
|
||||
|
||||
// Update RRULE if recurrence parameters are provided
|
||||
@@ -832,8 +798,8 @@ fn update_entire_series(
|
||||
async fn update_this_and_future(
|
||||
existing_event: &mut VEvent,
|
||||
request: &UpdateEventSeriesRequest,
|
||||
start_datetime: chrono::DateTime<chrono::Utc>,
|
||||
end_datetime: chrono::DateTime<chrono::Utc>,
|
||||
start_datetime: chrono::NaiveDateTime,
|
||||
end_datetime: chrono::NaiveDateTime,
|
||||
client: &CalDAVClient,
|
||||
calendar_path: &str,
|
||||
) -> Result<(VEvent, u32), ApiError> {
|
||||
@@ -881,6 +847,8 @@ async fn update_this_and_future(
|
||||
new_series.uid = new_series_uid.clone();
|
||||
new_series.dtstart = start_datetime;
|
||||
new_series.dtend = Some(end_datetime);
|
||||
new_series.dtstart_tzid = Some(request.timezone.clone());
|
||||
new_series.dtend_tzid = Some(request.timezone.clone());
|
||||
new_series.summary = if request.title.trim().is_empty() {
|
||||
None
|
||||
} else {
|
||||
@@ -913,9 +881,10 @@ async fn update_this_and_future(
|
||||
|
||||
// Update timestamps
|
||||
let now = chrono::Utc::now();
|
||||
let now_naive = now.naive_utc();
|
||||
new_series.dtstamp = now;
|
||||
new_series.created = Some(now);
|
||||
new_series.last_modified = Some(now);
|
||||
new_series.created = Some(now_naive);
|
||||
new_series.last_modified = Some(now_naive);
|
||||
new_series.href = None; // Will be set when created
|
||||
|
||||
println!(
|
||||
@@ -943,8 +912,8 @@ async fn update_this_and_future(
|
||||
async fn update_single_occurrence(
|
||||
existing_event: &mut VEvent,
|
||||
request: &UpdateEventSeriesRequest,
|
||||
start_datetime: chrono::DateTime<chrono::Utc>,
|
||||
end_datetime: chrono::DateTime<chrono::Utc>,
|
||||
start_datetime: chrono::NaiveDateTime,
|
||||
end_datetime: chrono::NaiveDateTime,
|
||||
client: &CalDAVClient,
|
||||
calendar_path: &str,
|
||||
_original_event_href: &str,
|
||||
@@ -969,21 +938,20 @@ async fn update_single_occurrence(
|
||||
// Create the EXDATE datetime using the original event's time
|
||||
let original_time = existing_event.dtstart.time();
|
||||
let exception_datetime = exception_date.and_time(original_time);
|
||||
let exception_utc = chrono::Utc.from_utc_datetime(&exception_datetime);
|
||||
|
||||
// Add the exception date to the original series
|
||||
println!(
|
||||
"📝 BEFORE adding EXDATE: existing_event.exdate = {:?}",
|
||||
existing_event.exdate
|
||||
);
|
||||
existing_event.exdate.push(exception_utc);
|
||||
existing_event.exdate.push(exception_datetime);
|
||||
println!(
|
||||
"📝 AFTER adding EXDATE: existing_event.exdate = {:?}",
|
||||
existing_event.exdate
|
||||
);
|
||||
println!(
|
||||
"🚫 Added EXDATE for single occurrence modification: {}",
|
||||
exception_utc.format("%Y-%m-%d %H:%M:%S")
|
||||
exception_datetime.format("%Y-%m-%d %H:%M:%S")
|
||||
);
|
||||
|
||||
// Create exception event by cloning the existing event to preserve all metadata
|
||||
@@ -995,6 +963,8 @@ async fn update_single_occurrence(
|
||||
// Update the modified properties from the request
|
||||
exception_event.dtstart = start_datetime;
|
||||
exception_event.dtend = Some(end_datetime);
|
||||
exception_event.dtstart_tzid = Some(request.timezone.clone());
|
||||
exception_event.dtend_tzid = Some(request.timezone.clone());
|
||||
exception_event.summary = if request.title.trim().is_empty() {
|
||||
existing_event.summary.clone() // Keep original if empty
|
||||
} else {
|
||||
@@ -1027,8 +997,9 @@ async fn update_single_occurrence(
|
||||
|
||||
// Update timestamps for the exception event
|
||||
let now = chrono::Utc::now();
|
||||
let now_naive = now.naive_utc();
|
||||
exception_event.dtstamp = now;
|
||||
exception_event.last_modified = Some(now);
|
||||
exception_event.last_modified = Some(now_naive);
|
||||
// Keep original created timestamp to preserve event history
|
||||
|
||||
// Set RECURRENCE-ID to point to the original occurrence
|
||||
@@ -1044,7 +1015,7 @@ async fn update_single_occurrence(
|
||||
|
||||
println!(
|
||||
"✨ Created exception event with RECURRENCE-ID: {}",
|
||||
exception_utc.format("%Y-%m-%d %H:%M:%S")
|
||||
exception_datetime.format("%Y-%m-%d %H:%M:%S")
|
||||
);
|
||||
|
||||
// Create the exception event as a new event (original series will be updated by main handler)
|
||||
@@ -1172,15 +1143,14 @@ async fn delete_single_occurrence(
|
||||
// Create the EXDATE datetime (use the same time as the original event)
|
||||
let original_time = existing_event.dtstart.time();
|
||||
let exception_datetime = exception_date.and_time(original_time);
|
||||
let exception_utc = chrono::Utc.from_utc_datetime(&exception_datetime);
|
||||
|
||||
// Add the exception date to the event's EXDATE list
|
||||
let mut updated_event = existing_event;
|
||||
updated_event.exdate.push(exception_utc);
|
||||
updated_event.exdate.push(exception_datetime);
|
||||
|
||||
println!(
|
||||
"🗑️ Added EXDATE for single occurrence deletion: {}",
|
||||
exception_utc.format("%Y%m%dT%H%M%SZ")
|
||||
exception_datetime.format("%Y%m%dT%H%M%S")
|
||||
);
|
||||
|
||||
// Update the event on the CalDAV server
|
||||
|
||||
@@ -3,6 +3,7 @@ use axum::{
|
||||
response::{IntoResponse, Response},
|
||||
Json,
|
||||
};
|
||||
use calendar_models::VAlarm;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// API request/response types
|
||||
@@ -113,10 +114,11 @@ pub struct CreateEventRequest {
|
||||
pub organizer: String, // organizer email
|
||||
pub attendees: String, // comma-separated attendee emails
|
||||
pub categories: String, // comma-separated categories
|
||||
pub reminder: String, // reminder type
|
||||
pub alarms: Vec<VAlarm>, // event alarms
|
||||
pub recurrence: String, // recurrence type
|
||||
pub recurrence_days: Vec<bool>, // [Sun, Mon, Tue, Wed, Thu, Fri, Sat] for weekly recurrence
|
||||
pub calendar_path: Option<String>, // Optional - use first calendar if not specified
|
||||
pub timezone: String, // Client timezone (e.g., "+05:00", "-04:00")
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
@@ -143,11 +145,15 @@ pub struct UpdateEventRequest {
|
||||
pub organizer: String, // organizer email
|
||||
pub attendees: String, // comma-separated attendee emails
|
||||
pub categories: String, // comma-separated categories
|
||||
pub reminder: String, // reminder type
|
||||
pub alarms: Vec<VAlarm>, // event alarms
|
||||
pub recurrence: String, // recurrence type
|
||||
pub recurrence_days: Vec<bool>, // [Sun, Mon, Tue, Wed, Thu, Fri, Sat] for weekly recurrence
|
||||
pub recurrence_interval: Option<u32>, // Every N days/weeks/months/years
|
||||
pub recurrence_count: Option<u32>, // Number of occurrences
|
||||
pub recurrence_end_date: Option<String>, // When the series ends (YYYY-MM-DD)
|
||||
pub calendar_path: Option<String>, // Optional - search all calendars if not specified
|
||||
pub update_action: Option<String>, // "update_series" for recurring events
|
||||
pub timezone: String, // Client timezone (e.g., "+05:00", "-04:00")
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub until_date: Option<String>, // ISO datetime string for RRULE UNTIL clause
|
||||
}
|
||||
@@ -176,7 +182,7 @@ pub struct CreateEventSeriesRequest {
|
||||
pub organizer: String, // organizer email
|
||||
pub attendees: String, // comma-separated attendee emails
|
||||
pub categories: String, // comma-separated categories
|
||||
pub reminder: String, // reminder type
|
||||
pub alarms: Vec<VAlarm>, // event alarms
|
||||
|
||||
// Series-specific fields
|
||||
pub recurrence: String, // recurrence type (daily, weekly, monthly, yearly)
|
||||
@@ -185,6 +191,7 @@ pub struct CreateEventSeriesRequest {
|
||||
pub recurrence_end_date: Option<String>, // When the series ends (YYYY-MM-DD)
|
||||
pub recurrence_count: Option<u32>, // Number of occurrences
|
||||
pub calendar_path: Option<String>, // Optional - search all calendars if not specified
|
||||
pub timezone: String, // Client timezone (e.g., "+05:00", "-04:00")
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
@@ -213,7 +220,7 @@ pub struct UpdateEventSeriesRequest {
|
||||
pub organizer: String, // organizer email
|
||||
pub attendees: String, // comma-separated attendee emails
|
||||
pub categories: String, // comma-separated categories
|
||||
pub reminder: String, // reminder type
|
||||
pub alarms: Vec<VAlarm>, // event alarms
|
||||
|
||||
// Series-specific fields
|
||||
pub recurrence: String, // recurrence type (daily, weekly, monthly, yearly)
|
||||
@@ -227,6 +234,7 @@ pub struct UpdateEventSeriesRequest {
|
||||
pub update_scope: String, // "this_only", "this_and_future", "all_in_series"
|
||||
pub occurrence_date: Option<String>, // ISO date string for specific occurrence being updated
|
||||
pub changed_fields: Option<Vec<String>>, // List of field names that were changed (for optimization)
|
||||
pub timezone: String, // Client timezone (e.g., "+05:00", "-04:00")
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! VEvent - RFC 5545 compliant calendar event structure
|
||||
|
||||
use crate::common::*;
|
||||
use chrono::{DateTime, Duration, Utc};
|
||||
use chrono::{DateTime, Duration, NaiveDateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// ==================== VEVENT COMPONENT ====================
|
||||
@@ -9,12 +9,14 @@ use serde::{Deserialize, Serialize};
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct VEvent {
|
||||
// Required properties
|
||||
pub dtstamp: DateTime<Utc>, // Date-time stamp (DTSTAMP) - REQUIRED
|
||||
pub uid: String, // Unique identifier (UID) - REQUIRED
|
||||
pub dtstart: DateTime<Utc>, // Start date-time (DTSTART) - REQUIRED
|
||||
pub dtstamp: DateTime<Utc>, // Date-time stamp (DTSTAMP) - REQUIRED (always UTC)
|
||||
pub uid: String, // Unique identifier (UID) - REQUIRED
|
||||
pub dtstart: NaiveDateTime, // Start date-time (DTSTART) - REQUIRED (local time)
|
||||
pub dtstart_tzid: Option<String>, // Timezone ID for DTSTART (TZID parameter)
|
||||
|
||||
// Optional properties (commonly used)
|
||||
pub dtend: Option<DateTime<Utc>>, // End date-time (DTEND)
|
||||
pub dtend: Option<NaiveDateTime>, // End date-time (DTEND) (local time)
|
||||
pub dtend_tzid: Option<String>, // Timezone ID for DTEND (TZID parameter)
|
||||
pub duration: Option<Duration>, // Duration (DURATION) - alternative to DTEND
|
||||
pub summary: Option<String>, // Summary/title (SUMMARY)
|
||||
pub description: Option<String>, // Description (DESCRIPTION)
|
||||
@@ -43,14 +45,19 @@ pub struct VEvent {
|
||||
|
||||
// Versioning and modification
|
||||
pub sequence: Option<u32>, // Sequence number (SEQUENCE)
|
||||
pub created: Option<DateTime<Utc>>, // Creation time (CREATED)
|
||||
pub last_modified: Option<DateTime<Utc>>, // Last modified (LAST-MODIFIED)
|
||||
pub created: Option<NaiveDateTime>, // Creation time (CREATED) (local time)
|
||||
pub created_tzid: Option<String>, // Timezone ID for CREATED
|
||||
pub last_modified: Option<NaiveDateTime>, // Last modified (LAST-MODIFIED) (local time)
|
||||
pub last_modified_tzid: Option<String>, // Timezone ID for LAST-MODIFIED
|
||||
|
||||
// Recurrence
|
||||
pub rrule: Option<String>, // Recurrence rule (RRULE)
|
||||
pub rdate: Vec<DateTime<Utc>>, // Recurrence dates (RDATE)
|
||||
pub exdate: Vec<DateTime<Utc>>, // Exception dates (EXDATE)
|
||||
pub recurrence_id: Option<DateTime<Utc>>, // Recurrence ID (RECURRENCE-ID)
|
||||
pub rrule: Option<String>, // Recurrence rule (RRULE)
|
||||
pub rdate: Vec<NaiveDateTime>, // Recurrence dates (RDATE) (local time)
|
||||
pub rdate_tzid: Option<String>, // Timezone ID for RDATE
|
||||
pub exdate: Vec<NaiveDateTime>, // Exception dates (EXDATE) (local time)
|
||||
pub exdate_tzid: Option<String>, // Timezone ID for EXDATE
|
||||
pub recurrence_id: Option<NaiveDateTime>, // Recurrence ID (RECURRENCE-ID) (local time)
|
||||
pub recurrence_id_tzid: Option<String>, // Timezone ID for RECURRENCE-ID
|
||||
|
||||
// Alarms and attachments
|
||||
pub alarms: Vec<VAlarm>, // VALARM components
|
||||
@@ -64,13 +71,15 @@ pub struct VEvent {
|
||||
}
|
||||
|
||||
impl VEvent {
|
||||
/// Create a new VEvent with required fields
|
||||
pub fn new(uid: String, dtstart: DateTime<Utc>) -> Self {
|
||||
/// Create a new VEvent with required fields (local time)
|
||||
pub fn new(uid: String, dtstart: NaiveDateTime) -> Self {
|
||||
Self {
|
||||
dtstamp: Utc::now(),
|
||||
uid,
|
||||
dtstart,
|
||||
dtstart_tzid: None,
|
||||
dtend: None,
|
||||
dtend_tzid: None,
|
||||
duration: None,
|
||||
summary: None,
|
||||
description: None,
|
||||
@@ -89,12 +98,17 @@ impl VEvent {
|
||||
url: None,
|
||||
geo: None,
|
||||
sequence: None,
|
||||
created: Some(Utc::now()),
|
||||
last_modified: Some(Utc::now()),
|
||||
created: Some(chrono::Local::now().naive_local()),
|
||||
created_tzid: None,
|
||||
last_modified: Some(chrono::Local::now().naive_local()),
|
||||
last_modified_tzid: None,
|
||||
rrule: None,
|
||||
rdate: Vec::new(),
|
||||
rdate_tzid: None,
|
||||
exdate: Vec::new(),
|
||||
exdate_tzid: None,
|
||||
recurrence_id: None,
|
||||
recurrence_id_tzid: None,
|
||||
alarms: Vec::new(),
|
||||
attachments: Vec::new(),
|
||||
etag: None,
|
||||
@@ -105,7 +119,7 @@ impl VEvent {
|
||||
}
|
||||
|
||||
/// Helper method to get effective end time (dtend or dtstart + duration)
|
||||
pub fn get_end_time(&self) -> DateTime<Utc> {
|
||||
pub fn get_end_time(&self) -> NaiveDateTime {
|
||||
if let Some(dtend) = self.dtend {
|
||||
dtend
|
||||
} else if let Some(duration) = self.duration {
|
||||
@@ -136,7 +150,7 @@ impl VEvent {
|
||||
|
||||
/// Helper method to get start date for UI compatibility
|
||||
pub fn get_date(&self) -> chrono::NaiveDate {
|
||||
self.dtstart.date_naive()
|
||||
self.dtstart.date()
|
||||
}
|
||||
|
||||
/// Check if event is recurring
|
||||
|
||||
@@ -30,6 +30,25 @@ web-sys = { version = "0.3", features = [
|
||||
"RequestMode",
|
||||
"Response",
|
||||
"CssStyleDeclaration",
|
||||
"MediaQueryList",
|
||||
"MediaQueryListEvent",
|
||||
# Notification API for browser notifications
|
||||
"Notification",
|
||||
"NotificationOptions",
|
||||
"NotificationPermission",
|
||||
# Service Worker API for background processing
|
||||
"ServiceWorkerContainer",
|
||||
"ServiceWorkerRegistration",
|
||||
"MessageEvent",
|
||||
# IndexedDB API for persistent alarm storage
|
||||
"IdbDatabase",
|
||||
"IdbObjectStore",
|
||||
"IdbTransaction",
|
||||
"IdbRequest",
|
||||
"IdbKeyRange",
|
||||
"IdbFactory",
|
||||
"IdbOpenDbRequest",
|
||||
"IdbVersionChangeEvent",
|
||||
] }
|
||||
wasm-bindgen = "0.2"
|
||||
js-sys = "0.3"
|
||||
@@ -71,3 +90,6 @@ gloo-storage = "0.3"
|
||||
gloo-timers = "0.3"
|
||||
wasm-bindgen-futures = "0.4"
|
||||
|
||||
# IndexedDB for persistent alarm storage
|
||||
indexed_db_futures = "0.4"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ dist = "dist"
|
||||
BACKEND_API_URL = "http://localhost:3000/api"
|
||||
|
||||
[watch]
|
||||
watch = ["src", "Cargo.toml", "../calendar-models/src", "styles.css", "index.html"]
|
||||
watch = ["src", "Cargo.toml", "../calendar-models/src", "styles.css", "print-preview.css", "index.html"]
|
||||
ignore = ["../backend/", "../target/"]
|
||||
|
||||
[serve]
|
||||
|
||||
@@ -6,15 +6,30 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<base data-trunk-public-url />
|
||||
<link data-trunk rel="css" href="styles.css">
|
||||
<link data-trunk rel="css" href="print-preview.css">
|
||||
<link data-trunk rel="copy-file" href="styles/google.css">
|
||||
<link data-trunk rel="copy-file" href="service-worker.js">
|
||||
<link data-trunk rel="icon" href="favicon.ico">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
console.log("HTML fully loaded, waiting for WASM...");
|
||||
window.addEventListener('TrunkApplicationStarted', () => {
|
||||
console.log("Trunk application started successfully!");
|
||||
// Application loaded successfully
|
||||
});
|
||||
|
||||
// Register service worker for alarm background processing
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
navigator.serviceWorker.register('/service-worker.js')
|
||||
.then((registration) => {
|
||||
// Service worker registered successfully
|
||||
})
|
||||
.catch((registrationError) => {
|
||||
console.log('SW registration failed: ', registrationError);
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
1215
frontend/print-preview.css
Normal file
1215
frontend/print-preview.css
Normal file
File diff suppressed because it is too large
Load Diff
150
frontend/service-worker.js
Normal file
150
frontend/service-worker.js
Normal file
@@ -0,0 +1,150 @@
|
||||
// Calendar Alarms Service Worker
|
||||
// Handles background alarm checking when the main app is not active
|
||||
|
||||
const SW_VERSION = 'v1.0.0';
|
||||
const CACHE_NAME = `calendar-alarms-${SW_VERSION}`;
|
||||
const STORAGE_KEY = 'calendar_alarms';
|
||||
|
||||
// Install event
|
||||
self.addEventListener('install', event => {
|
||||
self.skipWaiting(); // Activate immediately
|
||||
});
|
||||
|
||||
// Activate event
|
||||
self.addEventListener('activate', event => {
|
||||
event.waitUntil(self.clients.claim()); // Take control immediately
|
||||
});
|
||||
|
||||
// Message handler for communication with main app
|
||||
self.addEventListener('message', event => {
|
||||
const { type, data } = event.data;
|
||||
|
||||
switch (type) {
|
||||
case 'CHECK_ALARMS':
|
||||
handleCheckAlarms(event, data);
|
||||
break;
|
||||
case 'SCHEDULE_ALARM':
|
||||
handleScheduleAlarm(data, event);
|
||||
break;
|
||||
case 'REMOVE_ALARM':
|
||||
handleRemoveAlarm(data, event);
|
||||
break;
|
||||
case 'PING':
|
||||
event.ports[0].postMessage({ type: 'PONG', version: SW_VERSION });
|
||||
break;
|
||||
default:
|
||||
console.warn('Unknown message type:', type);
|
||||
}
|
||||
});
|
||||
|
||||
// Handle alarm checking request
|
||||
function handleCheckAlarms(event, data) {
|
||||
try {
|
||||
// Main app sends alarms data to check
|
||||
const allAlarms = data?.alarms || [];
|
||||
const dueAlarms = checkProvidedAlarms(allAlarms);
|
||||
|
||||
// Send results back to main app
|
||||
event.ports[0].postMessage({
|
||||
type: 'ALARMS_DUE',
|
||||
data: dueAlarms
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error checking alarms:', error);
|
||||
event.ports[0].postMessage({
|
||||
type: 'ALARM_CHECK_ERROR',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Process alarms sent from main app
|
||||
function checkProvidedAlarms(alarms) {
|
||||
const now = new Date();
|
||||
const nowStr = formatDateTimeForComparison(now);
|
||||
|
||||
// Filter alarms that should trigger and are pending
|
||||
const dueAlarms = alarms.filter(alarm => {
|
||||
return alarm.status === 'Pending' && alarm.trigger_time <= nowStr;
|
||||
});
|
||||
|
||||
return dueAlarms;
|
||||
}
|
||||
|
||||
// Handle schedule alarm request (not needed with localStorage approach)
|
||||
function handleScheduleAlarm(alarmData, event) {
|
||||
// Service worker doesn't handle storage with localStorage approach
|
||||
// Main app handles all storage operations
|
||||
event.ports[0].postMessage({
|
||||
type: 'ALARM_SCHEDULED',
|
||||
data: { success: true, alarmId: alarmData.id }
|
||||
});
|
||||
}
|
||||
|
||||
// Handle remove alarm request (not needed with localStorage approach)
|
||||
function handleRemoveAlarm(alarmData, event) {
|
||||
// Service worker doesn't handle storage with localStorage approach
|
||||
// Main app handles all storage operations
|
||||
event.ports[0].postMessage({
|
||||
type: 'ALARM_REMOVED',
|
||||
data: { success: true, eventUid: alarmData.eventUid }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Format date time for comparison (YYYY-MM-DDTHH:MM:SS)
|
||||
function formatDateTimeForComparison(date) {
|
||||
return date.getFullYear() + '-' +
|
||||
String(date.getMonth() + 1).padStart(2, '0') + '-' +
|
||||
String(date.getDate()).padStart(2, '0') + 'T' +
|
||||
String(date.getHours()).padStart(2, '0') + ':' +
|
||||
String(date.getMinutes()).padStart(2, '0') + ':' +
|
||||
String(date.getSeconds()).padStart(2, '0');
|
||||
}
|
||||
|
||||
// Background alarm checking (runs periodically)
|
||||
// Note: Service worker can't access localStorage, so this just pings the main app
|
||||
setInterval(async () => {
|
||||
try {
|
||||
// Notify all clients to check their alarms
|
||||
const clients = await self.clients.matchAll();
|
||||
|
||||
clients.forEach(client => {
|
||||
client.postMessage({
|
||||
type: 'BACKGROUND_ALARM_CHECK_REQUEST'
|
||||
});
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Background alarm check failed:', error);
|
||||
}
|
||||
}, 60000); // Check every minute
|
||||
|
||||
// Handle push notifications (for future enhancement)
|
||||
self.addEventListener('push', event => {
|
||||
console.log('Push notification received:', event);
|
||||
// Future: Handle server-sent alarm notifications
|
||||
});
|
||||
|
||||
// Handle notification clicks
|
||||
self.addEventListener('notificationclick', event => {
|
||||
console.log('Notification clicked:', event);
|
||||
|
||||
event.notification.close();
|
||||
|
||||
// Focus or open the calendar app
|
||||
event.waitUntil(
|
||||
self.clients.matchAll().then(clients => {
|
||||
// Try to focus existing client
|
||||
for (const client of clients) {
|
||||
if (client.url.includes('localhost') || client.url.includes(self.location.origin)) {
|
||||
return client.focus();
|
||||
}
|
||||
}
|
||||
|
||||
// Open new window if no client exists
|
||||
return self.clients.openWindow('/');
|
||||
})
|
||||
);
|
||||
});
|
||||
@@ -1,12 +1,12 @@
|
||||
use crate::components::{
|
||||
CalendarContextMenu, CalendarManagementModal, ContextMenu, CreateEventModal, DeleteAction,
|
||||
CalendarContextMenu, CalendarManagementModal, ColorEditorModal, ContextMenu, CreateEventModal, DeleteAction,
|
||||
EditAction, EventContextMenu, EventModal, EventCreationData,
|
||||
MobileWarningModal, RouteHandler, Sidebar, Theme, ViewMode,
|
||||
};
|
||||
use crate::components::mobile_warning_modal::is_mobile_device;
|
||||
use crate::components::sidebar::{Style};
|
||||
use crate::models::ical::VEvent;
|
||||
use crate::services::{calendar_service::{UserInfo, ExternalCalendar}, CalendarService};
|
||||
use crate::services::{calendar_service::{UserInfo, ExternalCalendar}, CalendarService, AlarmScheduler};
|
||||
use chrono::NaiveDate;
|
||||
use gloo_storage::{LocalStorage, Storage};
|
||||
use gloo_timers::callback::Interval;
|
||||
@@ -15,43 +15,68 @@ use web_sys::MouseEvent;
|
||||
use yew::prelude::*;
|
||||
use yew_router::prelude::*;
|
||||
|
||||
fn get_theme_event_colors() -> Vec<String> {
|
||||
if let Some(window) = web_sys::window() {
|
||||
if let Some(document) = window.document() {
|
||||
if let Some(root) = document.document_element() {
|
||||
if let Ok(Some(computed_style)) = window.get_computed_style(&root) {
|
||||
if let Ok(colors_string) = computed_style.get_property_value("--event-colors") {
|
||||
if !colors_string.is_empty() {
|
||||
return colors_string
|
||||
.split(',')
|
||||
.map(|color| color.trim().to_string())
|
||||
.filter(|color| !color.is_empty())
|
||||
.collect();
|
||||
fn get_default_event_colors() -> Vec<String> {
|
||||
vec![
|
||||
"#3B82F6".to_string(), // Blue
|
||||
"#10B981".to_string(), // Emerald
|
||||
"#F59E0B".to_string(), // Amber
|
||||
"#EF4444".to_string(), // Red
|
||||
"#8B5CF6".to_string(), // Violet
|
||||
"#06B6D4".to_string(), // Cyan
|
||||
"#84CC16".to_string(), // Lime
|
||||
"#F97316".to_string(), // Orange
|
||||
"#EC4899".to_string(), // Pink
|
||||
"#6366F1".to_string(), // Indigo
|
||||
"#14B8A6".to_string(), // Teal
|
||||
"#F3B806".to_string(), // Yellow
|
||||
"#8B5A2B".to_string(), // Brown
|
||||
"#6B7280".to_string(), // Gray
|
||||
"#DC2626".to_string(), // Dark Red
|
||||
"#7C3AED".to_string(), // Purple
|
||||
]
|
||||
}
|
||||
|
||||
fn get_event_colors_from_preferences() -> Vec<String> {
|
||||
// Try to load custom colors from user preferences
|
||||
if let Some(prefs) = crate::services::preferences::PreferencesService::load_cached() {
|
||||
if let Some(colors_json) = prefs.calendar_colors {
|
||||
// Try to parse the JSON structure
|
||||
if let Ok(colors_data) = serde_json::from_str::<serde_json::Value>(&colors_json) {
|
||||
// Check if it has a custom_palette field
|
||||
if let Some(custom_palette) = colors_data.get("custom_palette") {
|
||||
if let Some(colors_array) = custom_palette.as_array() {
|
||||
let custom_colors: Vec<String> = colors_array
|
||||
.iter()
|
||||
.filter_map(|v| v.as_str().map(|s| s.to_string()))
|
||||
.collect();
|
||||
|
||||
// Only use custom colors if we have a reasonable number
|
||||
if custom_colors.len() >= 8 {
|
||||
return custom_colors;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to default colors
|
||||
get_default_event_colors()
|
||||
}
|
||||
|
||||
vec![
|
||||
"#3B82F6".to_string(),
|
||||
"#10B981".to_string(),
|
||||
"#F59E0B".to_string(),
|
||||
"#EF4444".to_string(),
|
||||
"#8B5CF6".to_string(),
|
||||
"#06B6D4".to_string(),
|
||||
"#84CC16".to_string(),
|
||||
"#F97316".to_string(),
|
||||
"#EC4899".to_string(),
|
||||
"#6366F1".to_string(),
|
||||
"#14B8A6".to_string(),
|
||||
"#F3B806".to_string(),
|
||||
"#8B5A2B".to_string(),
|
||||
"#6B7280".to_string(),
|
||||
"#DC2626".to_string(),
|
||||
"#7C3AED".to_string(),
|
||||
]
|
||||
async fn save_custom_colors_to_preferences(colors: Vec<String>) -> Result<(), String> {
|
||||
// Create the JSON structure for storing custom colors
|
||||
let colors_json = serde_json::json!({
|
||||
"custom_palette": colors
|
||||
});
|
||||
|
||||
// Convert to string for preferences storage
|
||||
let colors_string = serde_json::to_string(&colors_json)
|
||||
.map_err(|e| format!("Failed to serialize colors: {}", e))?;
|
||||
|
||||
// Update preferences via the preferences service
|
||||
let preferences_service = crate::services::preferences::PreferencesService::new();
|
||||
preferences_service.update_preference("calendar_colors", serde_json::Value::String(colors_string)).await
|
||||
}
|
||||
|
||||
#[function_component]
|
||||
@@ -71,7 +96,6 @@ pub fn App() -> Html {
|
||||
match auth_service.verify_token(&stored_token).await {
|
||||
Ok(true) => {
|
||||
// Token is valid, set it
|
||||
web_sys::console::log_1(&"✅ Stored auth token is valid".into());
|
||||
auth_token.set(Some(stored_token));
|
||||
}
|
||||
_ => {
|
||||
@@ -97,6 +121,8 @@ pub fn App() -> Html {
|
||||
let color_picker_open = use_state(|| -> Option<String> { None });
|
||||
let calendar_management_modal_open = use_state(|| false);
|
||||
let context_menu_open = use_state(|| false);
|
||||
let color_editor_open = use_state(|| false);
|
||||
let color_editor_data = use_state(|| -> Option<(usize, String)> { None }); // (index, current_color)
|
||||
let context_menu_pos = use_state(|| (0i32, 0i32));
|
||||
let context_menu_calendar_path = use_state(|| -> Option<String> { None });
|
||||
let event_context_menu_open = use_state(|| false);
|
||||
@@ -122,6 +148,11 @@ pub fn App() -> Html {
|
||||
// Mobile warning state
|
||||
let mobile_warning_open = use_state(|| is_mobile_device());
|
||||
let refresh_interval = use_state(|| -> Option<Interval> { None });
|
||||
|
||||
// Alarm system state
|
||||
let alarm_scheduler = use_state(|| AlarmScheduler::new());
|
||||
let alarm_check_interval = use_state(|| -> Option<Interval> { None });
|
||||
let alarm_system_initialized = use_state(|| false);
|
||||
|
||||
// Calendar view state - load from localStorage if available
|
||||
let current_view = use_state(|| {
|
||||
@@ -156,7 +187,76 @@ pub fn App() -> Html {
|
||||
}
|
||||
});
|
||||
|
||||
let available_colors = use_state(|| get_theme_event_colors());
|
||||
let available_colors = use_state(|| get_event_colors_from_preferences());
|
||||
|
||||
// Refresh colors when preferences might have changed
|
||||
let refresh_colors = {
|
||||
let available_colors = available_colors.clone();
|
||||
Callback::from(move |_| {
|
||||
available_colors.set(get_event_colors_from_preferences());
|
||||
})
|
||||
};
|
||||
|
||||
// Initialize alarm system after user login
|
||||
{
|
||||
let auth_token = auth_token.clone();
|
||||
let alarm_scheduler = alarm_scheduler.clone();
|
||||
let alarm_system_initialized = alarm_system_initialized.clone();
|
||||
let alarm_check_interval = alarm_check_interval.clone();
|
||||
|
||||
use_effect_with((*auth_token).clone(), move |token| {
|
||||
if token.is_some() && !*alarm_system_initialized {
|
||||
|
||||
let alarm_scheduler = alarm_scheduler.clone();
|
||||
let alarm_system_initialized = alarm_system_initialized.clone();
|
||||
let alarm_check_interval = alarm_check_interval.clone();
|
||||
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
// Request notification permission
|
||||
let scheduler = (*alarm_scheduler).clone();
|
||||
match scheduler.request_notification_permission().await {
|
||||
Ok(_permission) => {
|
||||
}
|
||||
Err(e) => {
|
||||
web_sys::console::warn_1(
|
||||
&format!("⚠️ Failed to request notification permission: {:?}", e).into()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
alarm_scheduler.set(scheduler);
|
||||
alarm_system_initialized.set(true);
|
||||
|
||||
// Set up alarm checking interval (every 30 seconds)
|
||||
let interval = {
|
||||
let alarm_scheduler_ref = alarm_scheduler.clone();
|
||||
Interval::new(30_000, move || {
|
||||
// Get a fresh copy of the current scheduler state each time
|
||||
let mut scheduler = (*alarm_scheduler_ref).clone();
|
||||
let triggered_count = scheduler.check_and_trigger_alarms();
|
||||
|
||||
if triggered_count > 0 {
|
||||
web_sys::console::log_1(
|
||||
&format!("🔔 Triggered {} alarm(s)", triggered_count).into()
|
||||
);
|
||||
}
|
||||
|
||||
// Update the scheduler state with any changes (like alarm status updates)
|
||||
alarm_scheduler_ref.set(scheduler);
|
||||
})
|
||||
};
|
||||
|
||||
alarm_check_interval.set(Some(interval));
|
||||
});
|
||||
} else if token.is_none() {
|
||||
// Clean up alarm system on logout
|
||||
alarm_check_interval.set(None); // This will drop and cancel the interval
|
||||
alarm_system_initialized.set(false);
|
||||
}
|
||||
|
||||
|| ()
|
||||
});
|
||||
}
|
||||
|
||||
// Function to refresh calendar data without full page reload
|
||||
let refresh_calendar_data = {
|
||||
@@ -164,12 +264,14 @@ pub fn App() -> Html {
|
||||
let auth_token = auth_token.clone();
|
||||
let external_calendars = external_calendars.clone();
|
||||
let external_calendar_events = external_calendar_events.clone();
|
||||
let refresh_colors = refresh_colors.clone();
|
||||
|
||||
Callback::from(move |_| {
|
||||
let user_info = user_info.clone();
|
||||
let auth_token = auth_token.clone();
|
||||
let external_calendars = external_calendars.clone();
|
||||
let external_calendar_events = external_calendar_events.clone();
|
||||
let refresh_colors = refresh_colors.clone();
|
||||
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
// Refresh main calendar data if authenticated
|
||||
@@ -212,6 +314,8 @@ pub fn App() -> Html {
|
||||
// Add timestamp to force re-render
|
||||
info.last_updated = (js_sys::Date::now() / 1000.0) as u64;
|
||||
user_info.set(Some(info));
|
||||
// Refresh colors after loading user preferences
|
||||
refresh_colors.emit(());
|
||||
}
|
||||
Err(err) => {
|
||||
web_sys::console::log_1(
|
||||
@@ -284,6 +388,71 @@ pub fn App() -> Html {
|
||||
})
|
||||
};
|
||||
|
||||
let on_color_editor_open = {
|
||||
let color_editor_open = color_editor_open.clone();
|
||||
let color_editor_data = color_editor_data.clone();
|
||||
Callback::from(move |(index, color): (usize, String)| {
|
||||
color_editor_data.set(Some((index, color)));
|
||||
color_editor_open.set(true);
|
||||
})
|
||||
};
|
||||
|
||||
let on_color_editor_close = {
|
||||
let color_editor_open = color_editor_open.clone();
|
||||
Callback::from(move |_| {
|
||||
color_editor_open.set(false);
|
||||
})
|
||||
};
|
||||
|
||||
let on_color_editor_save = {
|
||||
let available_colors = available_colors.clone();
|
||||
let color_editor_open = color_editor_open.clone();
|
||||
let refresh_colors = refresh_colors.clone();
|
||||
Callback::from(move |(index, new_color): (usize, String)| {
|
||||
// Update the colors array
|
||||
let mut colors = (*available_colors).clone();
|
||||
if index < colors.len() {
|
||||
colors[index] = new_color;
|
||||
available_colors.set(colors.clone());
|
||||
|
||||
// Save to preferences asynchronously
|
||||
let colors_for_save = colors.clone();
|
||||
let refresh_colors = refresh_colors.clone();
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
if let Err(e) = save_custom_colors_to_preferences(colors_for_save).await {
|
||||
web_sys::console::log_1(&format!("Failed to save custom colors: {}", e).into());
|
||||
} else {
|
||||
// Refresh colors to ensure UI is in sync
|
||||
refresh_colors.emit(());
|
||||
}
|
||||
});
|
||||
}
|
||||
color_editor_open.set(false);
|
||||
})
|
||||
};
|
||||
|
||||
let on_color_editor_reset_all = {
|
||||
let available_colors = available_colors.clone();
|
||||
let refresh_colors = refresh_colors.clone();
|
||||
Callback::from(move |_| {
|
||||
// Reset to default colors
|
||||
let default_colors = get_default_event_colors();
|
||||
available_colors.set(default_colors.clone());
|
||||
|
||||
// Save to preferences asynchronously
|
||||
let colors_for_save = default_colors.clone();
|
||||
let refresh_colors = refresh_colors.clone();
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
if let Err(e) = save_custom_colors_to_preferences(colors_for_save).await {
|
||||
web_sys::console::log_1(&format!("Failed to save default colors: {}", e).into());
|
||||
} else {
|
||||
// Refresh colors to ensure UI is in sync
|
||||
refresh_colors.emit(());
|
||||
}
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
let on_view_change = {
|
||||
let current_view = current_view.clone();
|
||||
Callback::from(move |new_view: ViewMode| {
|
||||
@@ -301,7 +470,6 @@ pub fn App() -> Html {
|
||||
|
||||
let on_theme_change = {
|
||||
let current_theme = current_theme.clone();
|
||||
let available_colors = available_colors.clone();
|
||||
Callback::from(move |new_theme: Theme| {
|
||||
// Save theme to localStorage
|
||||
let _ = LocalStorage::set("calendar_theme", new_theme.value());
|
||||
@@ -316,8 +484,7 @@ pub fn App() -> Html {
|
||||
// Update state
|
||||
current_theme.set(new_theme);
|
||||
|
||||
// Update available colors after theme change
|
||||
available_colors.set(get_theme_event_colors());
|
||||
// Colors are now unified and don't change with themes
|
||||
})
|
||||
};
|
||||
|
||||
@@ -685,7 +852,9 @@ pub fn App() -> Html {
|
||||
let create_event_modal_open = create_event_modal_open.clone();
|
||||
let auth_token = auth_token.clone();
|
||||
let refresh_calendar_data = refresh_calendar_data.clone();
|
||||
let alarm_scheduler = alarm_scheduler.clone();
|
||||
Callback::from(move |event_data: EventCreationData| {
|
||||
let alarm_scheduler = alarm_scheduler.clone();
|
||||
// Check if this is an update operation (has original_uid) or a create operation
|
||||
if let Some(original_uid) = event_data.original_uid.clone() {
|
||||
web_sys::console::log_1(&format!("Updating event via modal: {:?}", event_data).into());
|
||||
@@ -724,8 +893,9 @@ pub fn App() -> Html {
|
||||
crate::components::event_form::RecurrenceType::Yearly);
|
||||
|
||||
let update_result = if is_recurring && event_data_for_update.edit_scope.is_some() {
|
||||
// Use series update endpoint for recurring events
|
||||
let edit_action = event_data_for_update.edit_scope.unwrap();
|
||||
// Only use series endpoint for existing recurring events being edited
|
||||
// Singleton→series conversion should use regular update_event endpoint
|
||||
let edit_action = event_data_for_update.edit_scope.as_ref().unwrap();
|
||||
let scope = match edit_action {
|
||||
crate::components::EditAction::EditAll => "all_in_series".to_string(),
|
||||
crate::components::EditAction::EditFuture => "this_and_future".to_string(),
|
||||
@@ -754,11 +924,13 @@ pub fn App() -> Html {
|
||||
params.14, // reminder
|
||||
params.15, // recurrence
|
||||
params.16, // recurrence_days
|
||||
params.17, // recurrence_interval
|
||||
params.18, // recurrence_count
|
||||
params.19, // recurrence_until
|
||||
params.17, // calendar_path
|
||||
params.20, // calendar_path
|
||||
scope,
|
||||
event_data_for_update.occurrence_date.map(|d| d.format("%Y-%m-%d").to_string()), // occurrence_date
|
||||
params.21, // timezone
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
@@ -785,10 +957,11 @@ pub fn App() -> Html {
|
||||
params.14, // reminder
|
||||
params.15, // recurrence
|
||||
params.16, // recurrence_days
|
||||
params.17, // calendar_path
|
||||
vec![], // exception_dates - empty for simple updates
|
||||
None, // update_action - None for regular updates
|
||||
None, // until_date - None for regular updates
|
||||
params.17, // recurrence_interval
|
||||
params.18, // recurrence_count
|
||||
params.19, // recurrence_until
|
||||
params.20, // calendar_path
|
||||
params.21, // timezone
|
||||
)
|
||||
.await
|
||||
};
|
||||
@@ -796,6 +969,45 @@ pub fn App() -> Html {
|
||||
match update_result {
|
||||
Ok(_) => {
|
||||
web_sys::console::log_1(&"Event updated successfully via modal".into());
|
||||
|
||||
// Re-schedule alarms for the updated event
|
||||
let alarm_scheduler_for_update = alarm_scheduler.clone();
|
||||
let event_data_for_alarms = event_data_for_update.clone();
|
||||
let original_uid_for_alarms = original_uid.clone();
|
||||
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
let mut scheduler = (*alarm_scheduler_for_update).clone();
|
||||
|
||||
// Remove old alarms for this event
|
||||
scheduler.remove_event_alarms(&original_uid_for_alarms);
|
||||
|
||||
// Schedule new alarms if any exist
|
||||
if !event_data_for_alarms.alarms.is_empty() {
|
||||
let params = event_data_for_alarms.to_create_event_params();
|
||||
|
||||
// Parse start date/time for alarm scheduling
|
||||
if let (Ok(start_date), Ok(start_time)) = (
|
||||
chrono::NaiveDate::parse_from_str(¶ms.2, "%Y-%m-%d"),
|
||||
chrono::NaiveTime::parse_from_str(¶ms.3, "%H:%M")
|
||||
) {
|
||||
// Create a temporary VEvent for alarm scheduling
|
||||
let start_datetime = start_date.and_time(start_time);
|
||||
let mut temp_event = VEvent::new(original_uid_for_alarms.clone(), start_datetime);
|
||||
temp_event.summary = Some(params.0.clone()); // title
|
||||
temp_event.location = if params.6.is_empty() { None } else { Some(params.6.clone()) };
|
||||
temp_event.alarms = event_data_for_alarms.alarms.clone();
|
||||
|
||||
scheduler.schedule_event_alarms(&temp_event);
|
||||
|
||||
web_sys::console::log_1(
|
||||
&format!("🔔 Re-scheduled {} alarm(s) for updated event", temp_event.alarms.len()).into()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
alarm_scheduler_for_update.set(scheduler);
|
||||
});
|
||||
|
||||
// Refresh calendar data without page reload
|
||||
refresh_callback.emit(());
|
||||
}
|
||||
@@ -853,6 +1065,12 @@ pub fn App() -> Html {
|
||||
};
|
||||
|
||||
let params = event_data.to_create_event_params();
|
||||
// Clone values we'll need for alarm scheduling
|
||||
let title_for_alarms = params.0.clone();
|
||||
let start_date_for_alarms = params.2.clone();
|
||||
let start_time_for_alarms = params.3.clone();
|
||||
let location_for_alarms = params.6.clone();
|
||||
|
||||
let create_result = _calendar_service
|
||||
.create_event(
|
||||
&_token, &_password, params.0, // title
|
||||
@@ -872,14 +1090,46 @@ pub fn App() -> Html {
|
||||
params.14, // reminder
|
||||
params.15, // recurrence
|
||||
params.16, // recurrence_days
|
||||
params.17, // recurrence_interval
|
||||
params.18, // recurrence_count
|
||||
params.19, // recurrence_until
|
||||
params.17, // calendar_path
|
||||
params.20, // calendar_path
|
||||
params.21, // timezone
|
||||
)
|
||||
.await;
|
||||
match create_result {
|
||||
Ok(_) => {
|
||||
web_sys::console::log_1(&"Event created successfully".into());
|
||||
|
||||
// Schedule alarms for the created event if any exist
|
||||
if !event_data.alarms.is_empty() {
|
||||
// Since create_event doesn't return the UID, we need to generate one
|
||||
// The backend should be using the same UUID generation logic
|
||||
let event_uid = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
// Parse start date/time for alarm scheduling
|
||||
if let (Ok(start_date), Ok(start_time)) = (
|
||||
chrono::NaiveDate::parse_from_str(&start_date_for_alarms, "%Y-%m-%d"),
|
||||
chrono::NaiveTime::parse_from_str(&start_time_for_alarms, "%H:%M")
|
||||
) {
|
||||
// Create a temporary VEvent for alarm scheduling
|
||||
let start_datetime = start_date.and_time(start_time);
|
||||
let mut temp_event = VEvent::new(event_uid.clone(), start_datetime);
|
||||
temp_event.summary = Some(title_for_alarms.clone());
|
||||
temp_event.location = if location_for_alarms.is_empty() { None } else { Some(location_for_alarms.clone()) };
|
||||
temp_event.alarms = event_data.alarms.clone();
|
||||
|
||||
// Schedule alarms for the new event (synchronously)
|
||||
let mut scheduler = (*alarm_scheduler).clone();
|
||||
scheduler.schedule_event_alarms(&temp_event);
|
||||
alarm_scheduler.set(scheduler);
|
||||
|
||||
web_sys::console::log_1(
|
||||
&format!("🔔 Scheduled {} alarm(s) for new event", temp_event.alarms.len()).into()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh calendar data without page reload
|
||||
refresh_callback.emit(());
|
||||
}
|
||||
@@ -906,8 +1156,8 @@ pub fn App() -> Html {
|
||||
original_event,
|
||||
new_start,
|
||||
new_end,
|
||||
preserve_rrule,
|
||||
until_date,
|
||||
_preserve_rrule,
|
||||
_until_date,
|
||||
update_scope,
|
||||
occurrence_date,
|
||||
): (
|
||||
@@ -915,7 +1165,7 @@ pub fn App() -> Html {
|
||||
chrono::NaiveDateTime,
|
||||
chrono::NaiveDateTime,
|
||||
bool,
|
||||
Option<chrono::DateTime<chrono::Utc>>,
|
||||
Option<chrono::NaiveDateTime>,
|
||||
Option<String>,
|
||||
Option<String>,
|
||||
)| {
|
||||
@@ -954,30 +1204,13 @@ pub fn App() -> Html {
|
||||
String::new()
|
||||
};
|
||||
|
||||
// Convert local naive datetime to UTC before sending to backend
|
||||
use chrono::TimeZone;
|
||||
let local_tz = chrono::Local;
|
||||
|
||||
let start_utc = local_tz.from_local_datetime(&new_start)
|
||||
.single()
|
||||
.unwrap_or_else(|| {
|
||||
// Fallback for ambiguous times (DST transitions)
|
||||
local_tz.from_local_datetime(&new_start).earliest().unwrap()
|
||||
})
|
||||
.with_timezone(&chrono::Utc);
|
||||
|
||||
let end_utc = local_tz.from_local_datetime(&new_end)
|
||||
.single()
|
||||
.unwrap_or_else(|| {
|
||||
// Fallback for ambiguous times (DST transitions)
|
||||
local_tz.from_local_datetime(&new_end).earliest().unwrap()
|
||||
})
|
||||
.with_timezone(&chrono::Utc);
|
||||
|
||||
let start_date = start_utc.format("%Y-%m-%d").to_string();
|
||||
let start_time = start_utc.format("%H:%M").to_string();
|
||||
let end_date = end_utc.format("%Y-%m-%d").to_string();
|
||||
let end_time = end_utc.format("%H:%M").to_string();
|
||||
// Send local times to backend, which will handle timezone conversion
|
||||
let start_date = new_start.format("%Y-%m-%d").to_string();
|
||||
let start_time = new_start.format("%H:%M").to_string();
|
||||
let end_date = new_end.format("%Y-%m-%d").to_string();
|
||||
let end_time = new_end.format("%H:%M").to_string();
|
||||
|
||||
// Convert existing event data to string formats for the API
|
||||
let status_str = match original_event.status {
|
||||
@@ -1003,7 +1236,7 @@ pub fn App() -> Html {
|
||||
};
|
||||
|
||||
// Convert reminders to string format
|
||||
let reminder_str = if !original_event.alarms.is_empty() {
|
||||
let _reminder_str = if !original_event.alarms.is_empty() {
|
||||
// Convert from VAlarm to minutes before
|
||||
"15".to_string() // TODO: Convert VAlarm trigger to minutes
|
||||
} else {
|
||||
@@ -1054,14 +1287,23 @@ pub fn App() -> Html {
|
||||
.collect::<Vec<_>>()
|
||||
.join(","),
|
||||
original_event.categories.join(","),
|
||||
reminder_str.clone(),
|
||||
original_event.alarms.clone(),
|
||||
recurrence_str.clone(),
|
||||
vec![false; 7],
|
||||
None,
|
||||
None,
|
||||
original_event.calendar_path.clone(),
|
||||
scope.clone(),
|
||||
occurrence_date,
|
||||
vec![false; 7], // recurrence_days
|
||||
1, // recurrence_interval - default for drag-and-drop
|
||||
None, // recurrence_count
|
||||
None, // recurrence_until
|
||||
original_event.calendar_path.clone(), // calendar_path
|
||||
scope.clone(), // update_scope
|
||||
occurrence_date, // occurrence_date
|
||||
{
|
||||
// Get timezone offset
|
||||
let date = js_sys::Date::new_0();
|
||||
let timezone_offset = date.get_timezone_offset(); // Minutes from UTC
|
||||
let hours = -(timezone_offset as i32) / 60; // Convert to hours, negate for proper sign
|
||||
let minutes = (timezone_offset as i32).abs() % 60;
|
||||
format!("{:+03}:{:02}", hours, minutes) // Format as +05:00 or -04:00
|
||||
}, // timezone
|
||||
)
|
||||
.await,
|
||||
)
|
||||
@@ -1102,17 +1344,21 @@ pub fn App() -> Html {
|
||||
.collect::<Vec<_>>()
|
||||
.join(","),
|
||||
original_event.categories.join(","),
|
||||
reminder_str,
|
||||
original_event.alarms.clone(),
|
||||
recurrence_str,
|
||||
recurrence_days,
|
||||
1, // recurrence_interval - default to 1 for drag-and-drop
|
||||
None, // recurrence_count - preserve existing
|
||||
None, // recurrence_until - preserve existing
|
||||
original_event.calendar_path,
|
||||
original_event.exdate.clone(),
|
||||
if preserve_rrule {
|
||||
Some("update_series".to_string())
|
||||
} else {
|
||||
Some("this_and_future".to_string())
|
||||
{
|
||||
// Get timezone offset
|
||||
let date = js_sys::Date::new_0();
|
||||
let timezone_offset = date.get_timezone_offset(); // Minutes from UTC
|
||||
let hours = -(timezone_offset as i32) / 60; // Convert to hours, negate for proper sign
|
||||
let minutes = (timezone_offset as i32).abs() % 60;
|
||||
format!("{:+03}:{:02}", hours, minutes) // Format as +05:00 or -04:00
|
||||
},
|
||||
until_date,
|
||||
)
|
||||
.await
|
||||
};
|
||||
@@ -1193,10 +1439,6 @@ pub fn App() -> Html {
|
||||
})
|
||||
};
|
||||
|
||||
// Debug logging
|
||||
web_sys::console::log_1(
|
||||
&format!("App rendering: auth_token = {:?}", auth_token.is_some()).into(),
|
||||
);
|
||||
|
||||
html! {
|
||||
<BrowserRouter>
|
||||
@@ -1386,6 +1628,7 @@ pub fn App() -> Html {
|
||||
on_theme_change={on_theme_change}
|
||||
current_style={(*current_style).clone()}
|
||||
on_style_change={on_style_change}
|
||||
on_color_editor_open={on_color_editor_open}
|
||||
/>
|
||||
<main class="app-main">
|
||||
<RouteHandler
|
||||
@@ -1474,7 +1717,7 @@ pub fn App() -> Html {
|
||||
let calendar_management_modal_open = calendar_management_modal_open.clone();
|
||||
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
let calendar_service = CalendarService::new();
|
||||
let _calendar_service = CalendarService::new();
|
||||
match CalendarService::get_external_calendars().await {
|
||||
Ok(calendars) => {
|
||||
external_calendars.set(calendars);
|
||||
@@ -1597,7 +1840,7 @@ pub fn App() -> Html {
|
||||
};
|
||||
|
||||
// Get the occurrence date from the clicked event
|
||||
let occurrence_date = Some(event.dtstart.date_naive().format("%Y-%m-%d").to_string());
|
||||
let occurrence_date = Some(event.dtstart.date().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());
|
||||
@@ -1637,6 +1880,19 @@ pub fn App() -> Html {
|
||||
}
|
||||
}
|
||||
})}
|
||||
on_edit_singleton={Callback::from({
|
||||
let event_context_menu_event = event_context_menu_event.clone();
|
||||
let event_context_menu_open = event_context_menu_open.clone();
|
||||
let create_event_modal_open = create_event_modal_open.clone();
|
||||
let event_edit_scope = event_edit_scope.clone();
|
||||
move |event: VEvent| {
|
||||
// For singleton events, open edit modal WITHOUT setting edit_scope
|
||||
event_context_menu_event.set(Some(event));
|
||||
event_edit_scope.set(None); // Explicitly set to None for singleton edits
|
||||
event_context_menu_open.set(false);
|
||||
create_event_modal_open.set(true);
|
||||
}
|
||||
})}
|
||||
on_view_details={Callback::from({
|
||||
let event_context_menu_open = event_context_menu_open.clone();
|
||||
let view_event_modal_open = view_event_modal_open.clone();
|
||||
@@ -1701,7 +1957,25 @@ pub fn App() -> Html {
|
||||
is_open={*mobile_warning_open}
|
||||
on_close={on_mobile_warning_close}
|
||||
/>
|
||||
|
||||
// Color editor modal
|
||||
<ColorEditorModal
|
||||
is_open={*color_editor_open}
|
||||
current_color={color_editor_data.as_ref().map(|(_, color)| color.clone()).unwrap_or_default()}
|
||||
color_index={color_editor_data.as_ref().map(|(index, _)| *index).unwrap_or(0)}
|
||||
default_color={
|
||||
let default_colors = get_default_event_colors();
|
||||
let index = color_editor_data.as_ref().map(|(index, _)| *index).unwrap_or(0);
|
||||
default_colors.get(index).cloned().unwrap_or_else(|| "#3B82F6".to_string())
|
||||
}
|
||||
on_close={on_color_editor_close}
|
||||
on_save={on_color_editor_save}
|
||||
on_reset_all={on_color_editor_reset_all}
|
||||
/>
|
||||
</div>
|
||||
|
||||
// Hidden print copy that gets shown only during printing
|
||||
<div id="print-preview-copy" class="print-preview-paper" style="display: none;"></div>
|
||||
</BrowserRouter>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::components::{
|
||||
CalendarHeader, CreateEventModal, EventCreationData, EventModal, MonthView, ViewMode, WeekView,
|
||||
CalendarHeader, CreateEventModal, EventCreationData, EventModal, MonthView, PrintPreviewModal, ViewMode, WeekView,
|
||||
};
|
||||
use crate::models::ical::VEvent;
|
||||
use crate::services::{calendar_service::{UserInfo, ExternalCalendar}, CalendarService};
|
||||
use chrono::{Datelike, Duration, Local, NaiveDate};
|
||||
use chrono::{Datelike, Duration, Local, NaiveDate, Weekday};
|
||||
use gloo_storage::{LocalStorage, Storage};
|
||||
use std::collections::HashMap;
|
||||
use web_sys::MouseEvent;
|
||||
@@ -32,7 +32,7 @@ pub struct CalendarProps {
|
||||
chrono::NaiveDateTime,
|
||||
chrono::NaiveDateTime,
|
||||
bool,
|
||||
Option<chrono::DateTime<chrono::Utc>>,
|
||||
Option<chrono::NaiveDateTime>,
|
||||
Option<String>,
|
||||
Option<String>,
|
||||
)>,
|
||||
@@ -111,6 +111,7 @@ pub fn Calendar(props: &CalendarProps) -> Html {
|
||||
use_effect_with((*current_date, view.clone(), external_events.len(), props.user_info.clone()), move |(date, _view, _external_len, user_info)| {
|
||||
let auth_token: Option<String> = LocalStorage::get("auth_token").ok();
|
||||
let date = *date; // Clone the date to avoid lifetime issues
|
||||
let view_mode = _view.clone(); // Clone the view mode to avoid lifetime issues
|
||||
let external_events = external_events.clone(); // Clone external events to avoid lifetime issues
|
||||
let user_info = user_info.clone(); // Clone user_info to avoid lifetime issues
|
||||
|
||||
@@ -136,17 +137,53 @@ pub fn Calendar(props: &CalendarProps) -> Html {
|
||||
String::new()
|
||||
};
|
||||
|
||||
let current_year = date.year();
|
||||
let current_month = date.month();
|
||||
// Determine which months to fetch based on view mode
|
||||
let months_to_fetch = match view_mode {
|
||||
ViewMode::Month => {
|
||||
// For month view, just fetch the current month
|
||||
vec![(date.year(), date.month())]
|
||||
}
|
||||
ViewMode::Week => {
|
||||
// For week view, calculate the week bounds and fetch all months that intersect
|
||||
let start_of_week = get_start_of_week(date);
|
||||
let end_of_week = start_of_week + Duration::days(6);
|
||||
|
||||
let mut months = vec![(start_of_week.year(), start_of_week.month())];
|
||||
|
||||
// If the week spans into a different month, add that month too
|
||||
if end_of_week.month() != start_of_week.month() || end_of_week.year() != start_of_week.year() {
|
||||
months.push((end_of_week.year(), end_of_week.month()));
|
||||
}
|
||||
|
||||
months
|
||||
}
|
||||
};
|
||||
|
||||
match calendar_service
|
||||
.fetch_events_for_month_vevent(
|
||||
&token,
|
||||
&password,
|
||||
current_year,
|
||||
current_month,
|
||||
)
|
||||
.await
|
||||
// Fetch events for all required months
|
||||
let mut all_events = Vec::new();
|
||||
for (year, month) in months_to_fetch {
|
||||
match calendar_service
|
||||
.fetch_events_for_month_vevent(
|
||||
&token,
|
||||
&password,
|
||||
year,
|
||||
month,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(mut month_events) => {
|
||||
all_events.append(&mut month_events);
|
||||
}
|
||||
Err(err) => {
|
||||
error.set(Some(format!("Failed to load events for {}-{}: {}", year, month, err)));
|
||||
loading.set(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process the combined events
|
||||
match Ok(all_events) as Result<Vec<VEvent>, String>
|
||||
{
|
||||
Ok(vevents) => {
|
||||
// Filter CalDAV events based on calendar visibility
|
||||
@@ -389,6 +426,15 @@ pub fn Calendar(props: &CalendarProps) -> Html {
|
||||
})
|
||||
};
|
||||
|
||||
// Handle print calendar preview
|
||||
let show_print_preview = use_state(|| false);
|
||||
let on_print = {
|
||||
let show_print_preview = show_print_preview.clone();
|
||||
Callback::from(move |_: MouseEvent| {
|
||||
show_print_preview.set(true);
|
||||
})
|
||||
};
|
||||
|
||||
// Handle drag-to-create event
|
||||
let on_create_event = {
|
||||
let show_create_modal = show_create_modal.clone();
|
||||
@@ -428,7 +474,7 @@ pub fn Calendar(props: &CalendarProps) -> Html {
|
||||
chrono::NaiveDateTime,
|
||||
chrono::NaiveDateTime,
|
||||
bool,
|
||||
Option<chrono::DateTime<chrono::Utc>>,
|
||||
Option<chrono::NaiveDateTime>,
|
||||
Option<String>,
|
||||
Option<String>,
|
||||
)| {
|
||||
@@ -457,6 +503,7 @@ pub fn Calendar(props: &CalendarProps) -> Html {
|
||||
on_today={on_today}
|
||||
time_increment={Some(*time_increment)}
|
||||
on_time_increment_toggle={Some(on_time_increment_toggle)}
|
||||
on_print={Some(on_print)}
|
||||
/>
|
||||
|
||||
{
|
||||
@@ -563,6 +610,47 @@ pub fn Calendar(props: &CalendarProps) -> Html {
|
||||
})
|
||||
}}
|
||||
/>
|
||||
|
||||
// Print preview modal
|
||||
{
|
||||
if *show_print_preview {
|
||||
html! {
|
||||
<PrintPreviewModal
|
||||
on_close={{
|
||||
let show_print_preview = show_print_preview.clone();
|
||||
Callback::from(move |_| {
|
||||
show_print_preview.set(false);
|
||||
})
|
||||
}}
|
||||
view_mode={props.view.clone()}
|
||||
current_date={*current_date}
|
||||
selected_date={*selected_date}
|
||||
events={(*events).clone()}
|
||||
user_info={props.user_info.clone()}
|
||||
external_calendars={props.external_calendars.clone()}
|
||||
time_increment={*time_increment}
|
||||
today={today}
|
||||
/>
|
||||
}
|
||||
} else {
|
||||
html! {}
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to calculate the start of the week (Sunday) for a given date
|
||||
fn get_start_of_week(date: NaiveDate) -> NaiveDate {
|
||||
let weekday = date.weekday();
|
||||
let days_from_sunday = match weekday {
|
||||
Weekday::Sun => 0,
|
||||
Weekday::Mon => 1,
|
||||
Weekday::Tue => 2,
|
||||
Weekday::Wed => 3,
|
||||
Weekday::Thu => 4,
|
||||
Weekday::Fri => 5,
|
||||
Weekday::Sat => 6,
|
||||
};
|
||||
date - Duration::days(days_from_sunday)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ pub struct CalendarHeaderProps {
|
||||
pub time_increment: Option<u32>,
|
||||
#[prop_or_default]
|
||||
pub on_time_increment_toggle: Option<Callback<MouseEvent>>,
|
||||
#[prop_or_default]
|
||||
pub on_print: Option<Callback<MouseEvent>>,
|
||||
}
|
||||
|
||||
#[function_component(CalendarHeader)]
|
||||
@@ -39,6 +41,17 @@ pub fn calendar_header(props: &CalendarHeaderProps) -> Html {
|
||||
html! {}
|
||||
}
|
||||
}
|
||||
{
|
||||
if let Some(print_callback) = &props.on_print {
|
||||
html! {
|
||||
<button class="print-button" onclick={print_callback.clone()} title="Print Calendar">
|
||||
<i class="fas fa-print"></i>
|
||||
</button>
|
||||
}
|
||||
} else {
|
||||
html! {}
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<h2 class="month-year">{title}</h2>
|
||||
<div class="header-right">
|
||||
|
||||
@@ -9,6 +9,7 @@ pub struct CalendarListItemProps {
|
||||
pub on_color_change: Callback<(String, String)>, // (calendar_path, color)
|
||||
pub on_color_picker_toggle: Callback<String>, // calendar_path
|
||||
pub available_colors: Vec<String>,
|
||||
pub on_color_editor_open: Callback<(usize, String)>, // (index, current_color)
|
||||
pub on_context_menu: Callback<(MouseEvent, String)>, // (event, calendar_path)
|
||||
pub on_visibility_toggle: Callback<String>, // calendar_path
|
||||
}
|
||||
@@ -66,13 +67,25 @@ pub fn calendar_list_item(props: &CalendarListItemProps) -> Html {
|
||||
on_color_change.emit((cal_path.clone(), color_str.clone()));
|
||||
});
|
||||
|
||||
let on_color_right_click = {
|
||||
let on_color_editor_open = props.on_color_editor_open.clone();
|
||||
let color_index = props.available_colors.iter().position(|c| c == color).unwrap_or(0);
|
||||
let color_str = color.clone();
|
||||
Callback::from(move |e: MouseEvent| {
|
||||
e.prevent_default();
|
||||
e.stop_propagation();
|
||||
on_color_editor_open.emit((color_index, color_str.clone()));
|
||||
})
|
||||
};
|
||||
|
||||
let is_selected = props.calendar.color == *color;
|
||||
let class_name = if is_selected { "color-option selected" } else { "color-option" };
|
||||
|
||||
html! {
|
||||
<div class={class_name}
|
||||
style={format!("background-color: {}", color)}
|
||||
onclick={on_color_select}>
|
||||
onclick={on_color_select}
|
||||
oncontextmenu={on_color_right_click}>
|
||||
</div>
|
||||
}
|
||||
}).collect::<Html>()
|
||||
|
||||
@@ -195,7 +195,7 @@ pub fn calendar_management_modal(props: &CalendarManagementModalProps) -> Html {
|
||||
let on_external_success = on_external_success.clone();
|
||||
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
let calendar_service = CalendarService::new();
|
||||
let _calendar_service = CalendarService::new();
|
||||
|
||||
match CalendarService::create_external_calendar(&name, &url, &color).await {
|
||||
Ok(calendar) => {
|
||||
|
||||
176
frontend/src/components/color_editor_modal.rs
Normal file
176
frontend/src/components/color_editor_modal.rs
Normal file
@@ -0,0 +1,176 @@
|
||||
use yew::prelude::*;
|
||||
use web_sys::HtmlInputElement;
|
||||
use wasm_bindgen::JsCast;
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct ColorEditorModalProps {
|
||||
pub is_open: bool,
|
||||
pub current_color: String,
|
||||
pub color_index: usize,
|
||||
pub default_color: String, // Default color for this index
|
||||
pub on_close: Callback<()>,
|
||||
pub on_save: Callback<(usize, String)>, // (index, new_color)
|
||||
pub on_reset_all: Callback<()>, // Reset all colors to defaults
|
||||
}
|
||||
|
||||
#[function_component(ColorEditorModal)]
|
||||
pub fn color_editor_modal(props: &ColorEditorModalProps) -> Html {
|
||||
let selected_color = use_state(|| props.current_color.clone());
|
||||
|
||||
// Reset selected color when modal opens with new color
|
||||
{
|
||||
let selected_color = selected_color.clone();
|
||||
use_effect_with(props.current_color.clone(), move |current_color| {
|
||||
selected_color.set(current_color.clone());
|
||||
});
|
||||
}
|
||||
|
||||
let on_color_input = {
|
||||
let selected_color = selected_color.clone();
|
||||
Callback::from(move |e: InputEvent| {
|
||||
if let Some(input) = e.target_dyn_into::<HtmlInputElement>() {
|
||||
selected_color.set(input.value());
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let on_save_click = {
|
||||
let selected_color = selected_color.clone();
|
||||
let on_save = props.on_save.clone();
|
||||
let color_index = props.color_index;
|
||||
Callback::from(move |_| {
|
||||
on_save.emit((color_index, (*selected_color).clone()));
|
||||
})
|
||||
};
|
||||
|
||||
let on_backdrop_click = {
|
||||
let on_close = props.on_close.clone();
|
||||
Callback::from(move |e: MouseEvent| {
|
||||
// Only close if clicking the backdrop, not the modal content
|
||||
if let Some(target) = e.target() {
|
||||
if let Some(element) = target.dyn_ref::<web_sys::Element>() {
|
||||
if element.class_list().contains("color-editor-backdrop") {
|
||||
on_close.emit(());
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
if !props.is_open {
|
||||
return html! {};
|
||||
}
|
||||
|
||||
// Predefined color suggestions
|
||||
let suggested_colors = vec![
|
||||
"#3B82F6", "#10B981", "#F59E0B", "#EF4444", "#8B5CF6", "#06B6D4",
|
||||
"#84CC16", "#F97316", "#EC4899", "#6366F1", "#14B8A6", "#F3B806",
|
||||
"#8B5A2B", "#6B7280", "#DC2626", "#7C3AED", "#F87171", "#34D399",
|
||||
"#FBBF24", "#A78BFA", "#60A5FA", "#2DD4BF", "#FB7185", "#FDBA74",
|
||||
];
|
||||
|
||||
html! {
|
||||
<div class="color-editor-backdrop" onclick={on_backdrop_click}>
|
||||
<div class="color-editor-modal">
|
||||
<div class="color-editor-header">
|
||||
<h3>{"Edit Color"}</h3>
|
||||
<button class="close-button" onclick={Callback::from({
|
||||
let on_close = props.on_close.clone();
|
||||
move |_| on_close.emit(())
|
||||
})}>
|
||||
{"×"}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="color-editor-content">
|
||||
<div class="current-color-preview">
|
||||
<div
|
||||
class="color-preview-large"
|
||||
style={format!("background-color: {}", *selected_color)}
|
||||
></div>
|
||||
<div class="color-preview-info">
|
||||
<span class="color-value">{&*selected_color}</span>
|
||||
<button class="reset-this-color-button" onclick={{
|
||||
let selected_color = selected_color.clone();
|
||||
let default_color = props.default_color.clone();
|
||||
Callback::from(move |_| {
|
||||
selected_color.set(default_color.clone());
|
||||
})
|
||||
}}>
|
||||
{"Reset This Color"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="color-input-section">
|
||||
<label for="color-picker">{"Custom Color:"}</label>
|
||||
<div class="color-input-group">
|
||||
<input
|
||||
type="color"
|
||||
id="color-picker"
|
||||
value={(*selected_color).clone()}
|
||||
oninput={on_color_input.clone()}
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
class="color-text-input"
|
||||
value={(*selected_color).clone()}
|
||||
oninput={on_color_input}
|
||||
placeholder="#000000"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="suggested-colors-section">
|
||||
<label>{"Suggested Colors:"}</label>
|
||||
<div class="suggested-colors-grid">
|
||||
{
|
||||
suggested_colors.iter().map(|color| {
|
||||
let color = color.to_string();
|
||||
let selected_color = selected_color.clone();
|
||||
let onclick = {
|
||||
let color = color.clone();
|
||||
Callback::from(move |_| {
|
||||
selected_color.set(color.clone());
|
||||
})
|
||||
};
|
||||
|
||||
html! {
|
||||
<div
|
||||
class="suggested-color"
|
||||
style={format!("background-color: {}", color)}
|
||||
onclick={onclick}
|
||||
title={color.clone()}
|
||||
></div>
|
||||
}
|
||||
}).collect::<Html>()
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="color-editor-footer">
|
||||
<button class="cancel-button" onclick={Callback::from({
|
||||
let on_close = props.on_close.clone();
|
||||
move |_| on_close.emit(())
|
||||
})}>
|
||||
{"Cancel"}
|
||||
</button>
|
||||
<button class="reset-all-button" onclick={Callback::from({
|
||||
let on_reset_all = props.on_reset_all.clone();
|
||||
let on_close = props.on_close.clone();
|
||||
move |_| {
|
||||
on_reset_all.emit(());
|
||||
on_close.emit(());
|
||||
}
|
||||
})}>
|
||||
{"Reset All Colors"}
|
||||
</button>
|
||||
<button class="save-button" onclick={on_save_click}>
|
||||
{"Save"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -238,12 +238,11 @@ pub fn create_event_modal(props: &CreateEventModalProps) -> Html {
|
||||
|
||||
// Convert VEvent to EventCreationData for editing
|
||||
fn vevent_to_creation_data(event: &crate::models::ical::VEvent, available_calendars: &[CalendarInfo]) -> EventCreationData {
|
||||
use chrono::Local;
|
||||
|
||||
// Convert start datetime from UTC to local
|
||||
let start_local = event.dtstart.with_timezone(&Local).naive_local();
|
||||
// VEvent fields are already local time (NaiveDateTime)
|
||||
let start_local = event.dtstart;
|
||||
let end_local = if let Some(dtend) = event.dtend {
|
||||
dtend.with_timezone(&Local).naive_local()
|
||||
dtend
|
||||
} else {
|
||||
// Default to 1 hour after start if no end time
|
||||
start_local + chrono::Duration::hours(1)
|
||||
@@ -258,7 +257,13 @@ fn vevent_to_creation_data(event: &crate::models::ical::VEvent, available_calend
|
||||
|
||||
// Timing
|
||||
start_date: start_local.date(),
|
||||
end_date: end_local.date(),
|
||||
end_date: if event.all_day {
|
||||
// For all-day events, subtract one day to convert from exclusive to inclusive end date
|
||||
// (UI expects inclusive dates, but iCalendar stores exclusive end dates)
|
||||
end_local.date() - chrono::Duration::days(1)
|
||||
} else {
|
||||
end_local.date()
|
||||
},
|
||||
start_time: start_local.time(),
|
||||
end_time: end_local.time(),
|
||||
|
||||
@@ -287,13 +292,15 @@ fn vevent_to_creation_data(event: &crate::models::ical::VEvent, available_calend
|
||||
// Categorization
|
||||
categories: event.categories.join(","),
|
||||
|
||||
// Reminders - TODO: Parse alarm from VEvent if needed
|
||||
reminder: ReminderType::None,
|
||||
// Reminders - Use VAlarms from the event
|
||||
alarms: event.alarms.clone(),
|
||||
|
||||
// Recurrence - Parse RRULE if present
|
||||
recurrence: if let Some(ref rrule_str) = event.rrule {
|
||||
web_sys::console::log_1(&format!("🐛 MODAL DEBUG: Event has RRULE: {}", rrule_str).into());
|
||||
parse_rrule_frequency(rrule_str)
|
||||
} else {
|
||||
web_sys::console::log_1(&"🐛 MODAL DEBUG: Event has no RRULE (singleton)".into());
|
||||
RecurrenceType::None
|
||||
},
|
||||
recurrence_interval: if let Some(ref rrule_str) = event.rrule {
|
||||
@@ -338,7 +345,10 @@ fn vevent_to_creation_data(event: &crate::models::ical::VEvent, available_calend
|
||||
},
|
||||
|
||||
// Edit tracking
|
||||
edit_scope: None, // Will be set by the modal after creation
|
||||
edit_scope: {
|
||||
web_sys::console::log_1(&"🐛 MODAL DEBUG: Setting edit_scope to None for vevent_to_creation_data".into());
|
||||
None // Will be set by the modal after creation
|
||||
},
|
||||
changed_fields: vec![],
|
||||
original_uid: Some(event.uid.clone()), // Preserve original UID for editing
|
||||
occurrence_date: Some(start_local.date()), // The occurrence date being edited
|
||||
|
||||
@@ -26,6 +26,7 @@ pub struct EventContextMenuProps {
|
||||
pub on_delete: Callback<DeleteAction>,
|
||||
pub on_view_details: Callback<VEvent>,
|
||||
pub on_close: Callback<()>,
|
||||
pub on_edit_singleton: Callback<VEvent>, // New callback for editing singleton events without scope
|
||||
}
|
||||
|
||||
#[function_component(EventContextMenu)]
|
||||
@@ -109,6 +110,18 @@ pub fn event_context_menu(props: &EventContextMenuProps) -> Html {
|
||||
})
|
||||
};
|
||||
|
||||
let create_singleton_edit_callback = {
|
||||
let on_edit_singleton = props.on_edit_singleton.clone();
|
||||
let on_close = props.on_close.clone();
|
||||
let event = props.event.clone();
|
||||
Callback::from(move |_: MouseEvent| {
|
||||
if let Some(event) = &event {
|
||||
on_edit_singleton.emit(event.clone());
|
||||
}
|
||||
on_close.emit(());
|
||||
})
|
||||
};
|
||||
|
||||
let create_delete_callback = |action: DeleteAction| {
|
||||
let on_delete = props.on_delete.clone();
|
||||
let on_close = props.on_close.clone();
|
||||
@@ -160,9 +173,9 @@ pub fn event_context_menu(props: &EventContextMenuProps) -> Html {
|
||||
</>
|
||||
}
|
||||
} else {
|
||||
// Regular single events - show edit option
|
||||
// Regular single events - show edit option without setting edit scope
|
||||
html! {
|
||||
<div class="context-menu-item" onclick={create_edit_callback(EditAction::EditThis)}>
|
||||
<div class="context-menu-item" onclick={create_singleton_edit_callback}>
|
||||
{"Edit Event"}
|
||||
</div>
|
||||
}
|
||||
|
||||
296
frontend/src/components/event_form/add_alarm_modal.rs
Normal file
296
frontend/src/components/event_form/add_alarm_modal.rs
Normal file
@@ -0,0 +1,296 @@
|
||||
use calendar_models::{VAlarm, AlarmAction, AlarmTrigger};
|
||||
use chrono::{Duration, DateTime, Utc, NaiveTime};
|
||||
use wasm_bindgen::JsCast;
|
||||
use web_sys::{HtmlSelectElement, HtmlInputElement};
|
||||
use yew::prelude::*;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum TriggerType {
|
||||
Relative, // Duration before/after event
|
||||
Absolute, // Specific date/time
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum RelativeTo {
|
||||
Start,
|
||||
End,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum TimeUnit {
|
||||
Minutes,
|
||||
Hours,
|
||||
Days,
|
||||
Weeks,
|
||||
}
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct AddAlarmModalProps {
|
||||
pub is_open: bool,
|
||||
pub editing_index: Option<usize>, // If editing an existing alarm
|
||||
pub initial_alarm: Option<VAlarm>, // For editing mode
|
||||
pub on_close: Callback<()>,
|
||||
pub on_save: Callback<VAlarm>,
|
||||
}
|
||||
|
||||
#[function_component(AddAlarmModal)]
|
||||
pub fn add_alarm_modal(props: &AddAlarmModalProps) -> Html {
|
||||
// Form state
|
||||
let trigger_type = use_state(|| TriggerType::Relative);
|
||||
let relative_to = use_state(|| RelativeTo::Start);
|
||||
let time_unit = use_state(|| TimeUnit::Minutes);
|
||||
let time_value = use_state(|| 15i32);
|
||||
let before_after = use_state(|| true); // true = before, false = after
|
||||
let absolute_date = use_state(|| chrono::Local::now().date_naive());
|
||||
let absolute_time = use_state(|| NaiveTime::from_hms_opt(9, 0, 0).unwrap());
|
||||
|
||||
// Initialize form with existing alarm data if editing
|
||||
{
|
||||
let trigger_type = trigger_type.clone();
|
||||
let time_value = time_value.clone();
|
||||
|
||||
use_effect_with(props.initial_alarm.clone(), move |initial_alarm| {
|
||||
if let Some(alarm) = initial_alarm {
|
||||
match &alarm.trigger {
|
||||
AlarmTrigger::Duration(duration) => {
|
||||
trigger_type.set(TriggerType::Relative);
|
||||
let minutes = duration.num_minutes().abs();
|
||||
time_value.set(minutes as i32);
|
||||
}
|
||||
AlarmTrigger::DateTime(_) => {
|
||||
trigger_type.set(TriggerType::Absolute);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let on_trigger_type_change = {
|
||||
let trigger_type = trigger_type.clone();
|
||||
Callback::from(move |e: Event| {
|
||||
if let Some(target) = e.target_dyn_into::<HtmlSelectElement>() {
|
||||
let new_type = match target.value().as_str() {
|
||||
"absolute" => TriggerType::Absolute,
|
||||
_ => TriggerType::Relative,
|
||||
};
|
||||
trigger_type.set(new_type);
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
let on_relative_to_change = {
|
||||
let relative_to = relative_to.clone();
|
||||
Callback::from(move |e: Event| {
|
||||
if let Some(target) = e.target_dyn_into::<HtmlSelectElement>() {
|
||||
let new_relative = match target.value().as_str() {
|
||||
"end" => RelativeTo::End,
|
||||
_ => RelativeTo::Start,
|
||||
};
|
||||
relative_to.set(new_relative);
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let on_time_unit_change = {
|
||||
let time_unit = time_unit.clone();
|
||||
Callback::from(move |e: Event| {
|
||||
if let Some(target) = e.target_dyn_into::<HtmlSelectElement>() {
|
||||
let new_unit = match target.value().as_str() {
|
||||
"hours" => TimeUnit::Hours,
|
||||
"days" => TimeUnit::Days,
|
||||
"weeks" => TimeUnit::Weeks,
|
||||
_ => TimeUnit::Minutes,
|
||||
};
|
||||
time_unit.set(new_unit);
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let on_time_value_change = {
|
||||
let time_value = time_value.clone();
|
||||
Callback::from(move |e: Event| {
|
||||
if let Some(target) = e.target_dyn_into::<HtmlInputElement>() {
|
||||
if let Ok(value) = target.value().parse::<i32>() {
|
||||
time_value.set(value.max(1)); // Minimum 1
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let on_before_after_change = {
|
||||
let before_after = before_after.clone();
|
||||
Callback::from(move |e: Event| {
|
||||
if let Some(target) = e.target_dyn_into::<HtmlSelectElement>() {
|
||||
let is_before = target.value() == "before";
|
||||
before_after.set(is_before);
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
|
||||
let on_save_click = {
|
||||
let trigger_type = trigger_type.clone();
|
||||
let time_unit = time_unit.clone();
|
||||
let time_value = time_value.clone();
|
||||
let before_after = before_after.clone();
|
||||
let absolute_date = absolute_date.clone();
|
||||
let absolute_time = absolute_time.clone();
|
||||
let on_save = props.on_save.clone();
|
||||
|
||||
Callback::from(move |_| {
|
||||
// Create the alarm trigger
|
||||
let trigger = match *trigger_type {
|
||||
TriggerType::Relative => {
|
||||
let minutes = match *time_unit {
|
||||
TimeUnit::Minutes => *time_value,
|
||||
TimeUnit::Hours => *time_value * 60,
|
||||
TimeUnit::Days => *time_value * 60 * 24,
|
||||
TimeUnit::Weeks => *time_value * 60 * 24 * 7,
|
||||
};
|
||||
|
||||
let signed_minutes = if *before_after { -minutes } else { minutes } as i64;
|
||||
AlarmTrigger::Duration(Duration::minutes(signed_minutes))
|
||||
}
|
||||
TriggerType::Absolute => {
|
||||
// Combine date and time to create a DateTime<Utc>
|
||||
let naive_datetime = absolute_date.and_time(*absolute_time);
|
||||
let utc_datetime = DateTime::from_naive_utc_and_offset(naive_datetime, Utc);
|
||||
AlarmTrigger::DateTime(utc_datetime)
|
||||
}
|
||||
};
|
||||
|
||||
// Create the VAlarm - always use Display action, no custom description
|
||||
let alarm = VAlarm {
|
||||
action: AlarmAction::Display,
|
||||
trigger,
|
||||
duration: None,
|
||||
repeat: None,
|
||||
description: None,
|
||||
summary: None,
|
||||
attendees: Vec::new(),
|
||||
attach: Vec::new(),
|
||||
};
|
||||
|
||||
on_save.emit(alarm);
|
||||
})
|
||||
};
|
||||
|
||||
let on_backdrop_click = {
|
||||
let on_close = props.on_close.clone();
|
||||
Callback::from(move |e: MouseEvent| {
|
||||
if let Some(target) = e.target() {
|
||||
if let Some(element) = target.dyn_ref::<web_sys::Element>() {
|
||||
if element.class_list().contains("add-alarm-backdrop") {
|
||||
on_close.emit(());
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
if !props.is_open {
|
||||
return html! {};
|
||||
}
|
||||
|
||||
html! {
|
||||
<div class="add-alarm-backdrop" onclick={on_backdrop_click}>
|
||||
<div class="add-alarm-modal">
|
||||
<div class="add-alarm-header">
|
||||
<h3>{
|
||||
if props.editing_index.is_some() {
|
||||
"Edit Reminder"
|
||||
} else {
|
||||
"Add Reminder"
|
||||
}
|
||||
}</h3>
|
||||
<button class="close-button" onclick={Callback::from({
|
||||
let on_close = props.on_close.clone();
|
||||
move |_| on_close.emit(())
|
||||
})}>
|
||||
{"×"}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="add-alarm-content">
|
||||
// Trigger Type Selection
|
||||
<div class="form-group">
|
||||
<label for="trigger-type">{"Trigger Type"}</label>
|
||||
<select id="trigger-type" class="form-input" onchange={on_trigger_type_change}>
|
||||
<option value="relative" selected={matches!(*trigger_type, TriggerType::Relative)}>
|
||||
{"Relative to event time"}
|
||||
</option>
|
||||
<option value="absolute" selected={matches!(*trigger_type, TriggerType::Absolute)}>
|
||||
{"Specific date and time"}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
// Relative Trigger Configuration
|
||||
if matches!(*trigger_type, TriggerType::Relative) {
|
||||
<div class="form-group">
|
||||
<label>{"When"}</label>
|
||||
<div class="relative-time-inputs">
|
||||
<input
|
||||
type="number"
|
||||
class="form-input time-value-input"
|
||||
value={time_value.to_string()}
|
||||
min="1"
|
||||
onchange={on_time_value_change}
|
||||
/>
|
||||
<select class="form-input time-unit-select" onchange={on_time_unit_change}>
|
||||
<option value="minutes" selected={matches!(*time_unit, TimeUnit::Minutes)}>{"minute(s)"}</option>
|
||||
<option value="hours" selected={matches!(*time_unit, TimeUnit::Hours)}>{"hour(s)"}</option>
|
||||
<option value="days" selected={matches!(*time_unit, TimeUnit::Days)}>{"day(s)"}</option>
|
||||
<option value="weeks" selected={matches!(*time_unit, TimeUnit::Weeks)}>{"week(s)"}</option>
|
||||
</select>
|
||||
<select class="form-input before-after-select" onchange={on_before_after_change}>
|
||||
<option value="before" selected={*before_after}>{"before"}</option>
|
||||
<option value="after" selected={!*before_after}>{"after"}</option>
|
||||
</select>
|
||||
<select class="form-input relative-to-select" onchange={on_relative_to_change}>
|
||||
<option value="start" selected={matches!(*relative_to, RelativeTo::Start)}>{"event start"}</option>
|
||||
<option value="end" selected={matches!(*relative_to, RelativeTo::End)}>{"event end"}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
// Absolute Trigger Configuration
|
||||
if matches!(*trigger_type, TriggerType::Absolute) {
|
||||
<div class="form-group">
|
||||
<label>{"Date and Time"}</label>
|
||||
<div class="absolute-time-inputs">
|
||||
<input
|
||||
type="date"
|
||||
class="form-input"
|
||||
value={absolute_date.format("%Y-%m-%d").to_string()}
|
||||
/>
|
||||
<input
|
||||
type="time"
|
||||
class="form-input"
|
||||
value={absolute_time.format("%H:%M").to_string()}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="add-alarm-footer">
|
||||
<button class="cancel-button" onclick={Callback::from({
|
||||
let on_close = props.on_close.clone();
|
||||
move |_| on_close.emit(())
|
||||
})}>
|
||||
{"Cancel"}
|
||||
</button>
|
||||
<button class="save-button" onclick={on_save_click}>
|
||||
{if props.editing_index.is_some() { "Update" } else { "Add Reminder" }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
133
frontend/src/components/event_form/alarm_list.rs
Normal file
133
frontend/src/components/event_form/alarm_list.rs
Normal file
@@ -0,0 +1,133 @@
|
||||
use calendar_models::{VAlarm, AlarmAction, AlarmTrigger};
|
||||
use chrono::Duration;
|
||||
use yew::prelude::*;
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct AlarmListProps {
|
||||
pub alarms: Vec<VAlarm>,
|
||||
pub on_alarm_delete: Callback<usize>, // Index of alarm to delete
|
||||
pub on_alarm_edit: Callback<usize>, // Index of alarm to edit
|
||||
}
|
||||
|
||||
#[function_component(AlarmList)]
|
||||
pub fn alarm_list(props: &AlarmListProps) -> Html {
|
||||
if props.alarms.is_empty() {
|
||||
return html! {
|
||||
<div class="alarm-list-empty">
|
||||
<p class="text-muted">{"No reminders set"}</p>
|
||||
<p class="text-small">{"Click 'Add Reminder' to create your first reminder"}</p>
|
||||
</div>
|
||||
};
|
||||
}
|
||||
|
||||
html! {
|
||||
<div class="alarm-list">
|
||||
<h6>{"Configured Reminders"}</h6>
|
||||
<div class="alarm-items">
|
||||
{
|
||||
props.alarms.iter().enumerate().map(|(index, alarm)| {
|
||||
let alarm_description = format_alarm_description(alarm);
|
||||
let action_icon = get_action_icon(&alarm.action);
|
||||
|
||||
let on_delete = {
|
||||
let on_alarm_delete = props.on_alarm_delete.clone();
|
||||
Callback::from(move |_| {
|
||||
on_alarm_delete.emit(index);
|
||||
})
|
||||
};
|
||||
|
||||
let on_edit = {
|
||||
let on_alarm_edit = props.on_alarm_edit.clone();
|
||||
Callback::from(move |_| {
|
||||
on_alarm_edit.emit(index);
|
||||
})
|
||||
};
|
||||
|
||||
html! {
|
||||
<div key={index} class="alarm-item">
|
||||
<div class="alarm-content">
|
||||
<span class="alarm-icon">{action_icon}</span>
|
||||
<span class="alarm-description">{alarm_description}</span>
|
||||
</div>
|
||||
<div class="alarm-actions">
|
||||
<button
|
||||
class="alarm-action-btn edit-btn"
|
||||
title="Edit reminder"
|
||||
onclick={on_edit}
|
||||
>
|
||||
<i class="fas fa-edit"></i>
|
||||
</button>
|
||||
<button
|
||||
class="alarm-action-btn delete-btn"
|
||||
title="Delete reminder"
|
||||
onclick={on_delete}
|
||||
>
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}).collect::<Html>()
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
/// Format alarm description for display
|
||||
fn format_alarm_description(alarm: &VAlarm) -> String {
|
||||
match &alarm.trigger {
|
||||
AlarmTrigger::Duration(duration) => {
|
||||
format_duration_description(duration)
|
||||
}
|
||||
AlarmTrigger::DateTime(datetime) => {
|
||||
format!("At {}", datetime.format("%Y-%m-%d %H:%M UTC"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Get icon for alarm action - always use bell for consistent notification type
|
||||
fn get_action_icon(_action: &AlarmAction) -> Html {
|
||||
html! { <i class="fas fa-bell"></i> }
|
||||
}
|
||||
|
||||
/// Format duration for human-readable description
|
||||
fn format_duration_description(duration: &Duration) -> String {
|
||||
let minutes = duration.num_minutes();
|
||||
|
||||
if minutes == 0 {
|
||||
return "At event time".to_string();
|
||||
}
|
||||
|
||||
let abs_minutes = minutes.abs();
|
||||
let before_or_after = if minutes < 0 { "before" } else { "after" };
|
||||
|
||||
// Convert to human-readable format
|
||||
if abs_minutes >= 60 * 24 * 7 {
|
||||
let weeks = abs_minutes / (60 * 24 * 7);
|
||||
let remainder = abs_minutes % (60 * 24 * 7);
|
||||
if remainder == 0 {
|
||||
format!("{} week{} {}", weeks, if weeks == 1 { "" } else { "s" }, before_or_after)
|
||||
} else {
|
||||
format!("{} minutes {}", abs_minutes, before_or_after)
|
||||
}
|
||||
} else if abs_minutes >= 60 * 24 {
|
||||
let days = abs_minutes / (60 * 24);
|
||||
let remainder = abs_minutes % (60 * 24);
|
||||
if remainder == 0 {
|
||||
format!("{} day{} {}", days, if days == 1 { "" } else { "s" }, before_or_after)
|
||||
} else {
|
||||
format!("{} minutes {}", abs_minutes, before_or_after)
|
||||
}
|
||||
} else if abs_minutes >= 60 {
|
||||
let hours = abs_minutes / 60;
|
||||
let remainder = abs_minutes % 60;
|
||||
if remainder == 0 {
|
||||
format!("{} hour{} {}", hours, if hours == 1 { "" } else { "s" }, before_or_after)
|
||||
} else {
|
||||
format!("{} minutes {}", abs_minutes, before_or_after)
|
||||
}
|
||||
} else {
|
||||
format!("{} minute{} {}", abs_minutes, if abs_minutes == 1 { "" } else { "s" }, before_or_after)
|
||||
}
|
||||
}
|
||||
@@ -99,26 +99,13 @@ pub fn basic_details_tab(props: &TabProps) -> Html {
|
||||
})
|
||||
};
|
||||
|
||||
let on_reminder_change = {
|
||||
let data = data.clone();
|
||||
Callback::from(move |e: Event| {
|
||||
if let Some(target) = e.target() {
|
||||
if let Ok(select) = target.dyn_into::<HtmlSelectElement>() {
|
||||
let mut event_data = (*data).clone();
|
||||
event_data.reminder = match select.value().as_str() {
|
||||
"15min" => ReminderType::Minutes15,
|
||||
"30min" => ReminderType::Minutes30,
|
||||
"1hour" => ReminderType::Hour1,
|
||||
"1day" => ReminderType::Day1,
|
||||
"2days" => ReminderType::Days2,
|
||||
"1week" => ReminderType::Week1,
|
||||
_ => ReminderType::None,
|
||||
};
|
||||
data.set(event_data);
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
// TODO: Replace with new alarm management UI
|
||||
// let on_reminder_change = {
|
||||
// let data = data.clone();
|
||||
// Callback::from(move |e: Event| {
|
||||
// // Will be replaced with VAlarm management
|
||||
// })
|
||||
// };
|
||||
|
||||
let on_recurrence_interval_change = {
|
||||
let data = data.clone();
|
||||
@@ -321,42 +308,31 @@ pub fn basic_details_tab(props: &TabProps) -> Html {
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="event-calendar">{"Calendar"}</label>
|
||||
<select
|
||||
id="event-calendar"
|
||||
class="form-input"
|
||||
onchange={on_calendar_change}
|
||||
>
|
||||
<option value="">{"Select Calendar"}</option>
|
||||
{
|
||||
props.available_calendars.iter().map(|calendar| {
|
||||
html! {
|
||||
<option
|
||||
key={calendar.path.clone()}
|
||||
value={calendar.path.clone()}
|
||||
selected={data.selected_calendar.as_ref() == Some(&calendar.path)}
|
||||
>
|
||||
{&calendar.display_name}
|
||||
</option>
|
||||
}
|
||||
}).collect::<Html>()
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="checkbox-label">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={data.all_day}
|
||||
onchange={on_all_day_change}
|
||||
/>
|
||||
{" All Day"}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="event-calendar">{"Calendar"}</label>
|
||||
<select
|
||||
id="event-calendar"
|
||||
class="form-input"
|
||||
onchange={on_calendar_change}
|
||||
>
|
||||
<option value="">{"Select Calendar"}</option>
|
||||
{
|
||||
props.available_calendars.iter().map(|calendar| {
|
||||
html! {
|
||||
<option
|
||||
key={calendar.path.clone()}
|
||||
value={calendar.path.clone()}
|
||||
selected={data.selected_calendar.as_ref() == Some(&calendar.path)}
|
||||
>
|
||||
{&calendar.display_name}
|
||||
</option>
|
||||
}
|
||||
}).collect::<Html>()
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="event-recurrence-basic">{"Repeat"}</label>
|
||||
<select
|
||||
@@ -371,21 +347,6 @@ pub fn basic_details_tab(props: &TabProps) -> Html {
|
||||
<option value="yearly" selected={matches!(data.recurrence, RecurrenceType::Yearly)}>{"Yearly"}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="event-reminder-basic">{"Reminder"}</label>
|
||||
<select
|
||||
id="event-reminder-basic"
|
||||
class="form-input"
|
||||
onchange={on_reminder_change}
|
||||
>
|
||||
<option value="none" selected={matches!(data.reminder, ReminderType::None)}>{"None"}</option>
|
||||
<option value="15min" selected={matches!(data.reminder, ReminderType::Minutes15)}>{"15 minutes before"}</option>
|
||||
<option value="30min" selected={matches!(data.reminder, ReminderType::Minutes30)}>{"30 minutes before"}</option>
|
||||
<option value="1hour" selected={matches!(data.reminder, ReminderType::Hour1)}>{"1 hour before"}</option>
|
||||
<option value="1day" selected={matches!(data.reminder, ReminderType::Day1)}>{"1 day before"}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
// RECURRENCE OPTIONS GO RIGHT HERE - directly below repeat/reminder!
|
||||
@@ -659,6 +620,18 @@ pub fn basic_details_tab(props: &TabProps) -> Html {
|
||||
</div>
|
||||
}
|
||||
|
||||
// All Day checkbox above date/time fields
|
||||
<div class="form-group">
|
||||
<label class="checkbox-label">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={data.all_day}
|
||||
onchange={on_all_day_change}
|
||||
/>
|
||||
{" All Day"}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
// Date and time fields go here AFTER recurrence options
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// Event form components module
|
||||
pub mod types;
|
||||
pub mod alarm_list;
|
||||
pub mod add_alarm_modal;
|
||||
pub mod basic_details;
|
||||
pub mod advanced;
|
||||
pub mod people;
|
||||
@@ -8,6 +10,8 @@ pub mod location;
|
||||
pub mod reminders;
|
||||
|
||||
pub use types::*;
|
||||
pub use alarm_list::AlarmList;
|
||||
pub use add_alarm_modal::AddAlarmModal;
|
||||
pub use basic_details::BasicDetailsTab;
|
||||
pub use advanced::AdvancedTab;
|
||||
pub use people::PeopleTab;
|
||||
|
||||
@@ -1,100 +1,116 @@
|
||||
use super::types::*;
|
||||
// Types are already imported from super::types::*
|
||||
use wasm_bindgen::JsCast;
|
||||
use web_sys::HtmlSelectElement;
|
||||
use super::{types::*, AlarmList, AddAlarmModal};
|
||||
use calendar_models::VAlarm;
|
||||
use yew::prelude::*;
|
||||
|
||||
#[function_component(RemindersTab)]
|
||||
pub fn reminders_tab(props: &TabProps) -> Html {
|
||||
let data = &props.data;
|
||||
|
||||
let on_reminder_change = {
|
||||
// Modal state
|
||||
let is_modal_open = use_state(|| false);
|
||||
let editing_index = use_state(|| None::<usize>);
|
||||
|
||||
// Add alarm callback
|
||||
let on_add_alarm = {
|
||||
let is_modal_open = is_modal_open.clone();
|
||||
let editing_index = editing_index.clone();
|
||||
Callback::from(move |_| {
|
||||
editing_index.set(None);
|
||||
is_modal_open.set(true);
|
||||
})
|
||||
};
|
||||
|
||||
// Edit alarm callback
|
||||
let on_alarm_edit = {
|
||||
let is_modal_open = is_modal_open.clone();
|
||||
let editing_index = editing_index.clone();
|
||||
Callback::from(move |index: usize| {
|
||||
editing_index.set(Some(index));
|
||||
is_modal_open.set(true);
|
||||
})
|
||||
};
|
||||
|
||||
// Delete alarm callback
|
||||
let on_alarm_delete = {
|
||||
let data = data.clone();
|
||||
Callback::from(move |e: Event| {
|
||||
if let Some(target) = e.target() {
|
||||
if let Ok(select) = target.dyn_into::<HtmlSelectElement>() {
|
||||
let mut event_data = (*data).clone();
|
||||
event_data.reminder = match select.value().as_str() {
|
||||
"15min" => ReminderType::Minutes15,
|
||||
"30min" => ReminderType::Minutes30,
|
||||
"1hour" => ReminderType::Hour1,
|
||||
"1day" => ReminderType::Day1,
|
||||
"2days" => ReminderType::Days2,
|
||||
"1week" => ReminderType::Week1,
|
||||
_ => ReminderType::None,
|
||||
};
|
||||
data.set(event_data);
|
||||
}
|
||||
Callback::from(move |index: usize| {
|
||||
let mut current_data = (*data).clone();
|
||||
if index < current_data.alarms.len() {
|
||||
current_data.alarms.remove(index);
|
||||
data.set(current_data);
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
// Close modal callback
|
||||
let on_modal_close = {
|
||||
let is_modal_open = is_modal_open.clone();
|
||||
let editing_index = editing_index.clone();
|
||||
Callback::from(move |_| {
|
||||
is_modal_open.set(false);
|
||||
editing_index.set(None);
|
||||
})
|
||||
};
|
||||
|
||||
// Save alarm callback
|
||||
let on_alarm_save = {
|
||||
let data = data.clone();
|
||||
let is_modal_open = is_modal_open.clone();
|
||||
let editing_index = editing_index.clone();
|
||||
Callback::from(move |alarm: VAlarm| {
|
||||
let mut current_data = (*data).clone();
|
||||
|
||||
if let Some(index) = *editing_index {
|
||||
// Edit existing alarm
|
||||
if index < current_data.alarms.len() {
|
||||
current_data.alarms[index] = alarm;
|
||||
}
|
||||
} else {
|
||||
// Add new alarm
|
||||
current_data.alarms.push(alarm);
|
||||
}
|
||||
|
||||
data.set(current_data);
|
||||
is_modal_open.set(false);
|
||||
editing_index.set(None);
|
||||
})
|
||||
};
|
||||
|
||||
// Get initial alarm for editing
|
||||
let initial_alarm = (*editing_index).and_then(|index| {
|
||||
data.alarms.get(index).cloned()
|
||||
});
|
||||
|
||||
html! {
|
||||
<div class="tab-panel">
|
||||
<div class="form-group">
|
||||
<label for="event-reminder-main">{"Primary Reminder"}</label>
|
||||
<select
|
||||
id="event-reminder-main"
|
||||
class="form-input"
|
||||
onchange={on_reminder_change}
|
||||
>
|
||||
<option value="none" selected={matches!(data.reminder, ReminderType::None)}>{"No reminder"}</option>
|
||||
<option value="15min" selected={matches!(data.reminder, ReminderType::Minutes15)}>{"15 minutes before"}</option>
|
||||
<option value="30min" selected={matches!(data.reminder, ReminderType::Minutes30)}>{"30 minutes before"}</option>
|
||||
<option value="1hour" selected={matches!(data.reminder, ReminderType::Hour1)}>{"1 hour before"}</option>
|
||||
<option value="1day" selected={matches!(data.reminder, ReminderType::Day1)}>{"1 day before"}</option>
|
||||
<option value="2days" selected={matches!(data.reminder, ReminderType::Days2)}>{"2 days before"}</option>
|
||||
<option value="1week" selected={matches!(data.reminder, ReminderType::Week1)}>{"1 week before"}</option>
|
||||
</select>
|
||||
<p class="form-help-text">{"Choose when you'd like to be reminded about this event"}</p>
|
||||
</div>
|
||||
|
||||
<div class="reminder-types">
|
||||
<h5>{"Reminder & Alarm Types"}</h5>
|
||||
<div class="alarm-examples">
|
||||
<div class="alarm-type">
|
||||
<strong>{"Display Alarm"}</strong>
|
||||
<p>{"Pop-up notification on your device"}</p>
|
||||
</div>
|
||||
<div class="alarm-type">
|
||||
<strong>{"Email Reminder"}</strong>
|
||||
<p>{"Email notification sent to your address"}</p>
|
||||
</div>
|
||||
<div class="alarm-type">
|
||||
<strong>{"Audio Alert"}</strong>
|
||||
<p>{"Sound notification with custom audio"}</p>
|
||||
</div>
|
||||
<div class="alarm-type">
|
||||
<strong>{"SMS/Text"}</strong>
|
||||
<p>{"Text message reminder (enterprise feature)"}</p>
|
||||
</div>
|
||||
<div class="alarm-management-header">
|
||||
<h5>{"Event Reminders"}</h5>
|
||||
<button
|
||||
class="add-alarm-button"
|
||||
onclick={on_add_alarm}
|
||||
type="button"
|
||||
>
|
||||
<i class="fas fa-plus"></i>
|
||||
{" Add Reminder"}
|
||||
</button>
|
||||
</div>
|
||||
<p class="form-help-text">{"Multiple alarm types follow RFC 5545 VALARM standards"}</p>
|
||||
<p class="form-help-text">{"Configure multiple reminders with custom timing and notification types"}</p>
|
||||
</div>
|
||||
|
||||
<div class="reminder-info">
|
||||
<h5>{"Advanced Reminder Features"}</h5>
|
||||
<ul>
|
||||
<li>{"Multiple reminders per event with different timing"}</li>
|
||||
<li>{"Custom reminder messages and descriptions"}</li>
|
||||
<li>{"Recurring reminders for recurring events"}</li>
|
||||
<li>{"Snooze and dismiss functionality"}</li>
|
||||
<li>{"Integration with system notifications"}</li>
|
||||
</ul>
|
||||
<AlarmList
|
||||
alarms={data.alarms.clone()}
|
||||
on_alarm_delete={on_alarm_delete}
|
||||
on_alarm_edit={on_alarm_edit}
|
||||
/>
|
||||
|
||||
<div class="attachments-section">
|
||||
<h6>{"File Attachments & Documents"}</h6>
|
||||
<p>{"Future attachment features will include:"}</p>
|
||||
<ul>
|
||||
<li>{"Drag-and-drop file uploads"}</li>
|
||||
<li>{"Document preview and thumbnails"}</li>
|
||||
<li>{"Cloud storage integration (Google Drive, OneDrive)"}</li>
|
||||
<li>{"Version control for updated documents"}</li>
|
||||
<li>{"Shared access permissions for attendees"}</li>
|
||||
</ul>
|
||||
<p class="form-help-text">{"Attachment functionality will be implemented in a future release."}</p>
|
||||
</div>
|
||||
</div>
|
||||
<AddAlarmModal
|
||||
is_open={*is_modal_open}
|
||||
editing_index={*editing_index}
|
||||
initial_alarm={initial_alarm}
|
||||
on_close={on_modal_close}
|
||||
on_save={on_alarm_save}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::services::calendar_service::CalendarInfo;
|
||||
use chrono::{Local, NaiveDate, NaiveTime};
|
||||
use yew::prelude::*;
|
||||
use calendar_models::VAlarm;
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub enum EventStatus {
|
||||
@@ -28,22 +29,6 @@ impl Default for EventClass {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub enum ReminderType {
|
||||
None,
|
||||
Minutes15,
|
||||
Minutes30,
|
||||
Hour1,
|
||||
Day1,
|
||||
Days2,
|
||||
Week1,
|
||||
}
|
||||
|
||||
impl Default for ReminderType {
|
||||
fn default() -> Self {
|
||||
ReminderType::None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub enum RecurrenceType {
|
||||
@@ -104,8 +89,8 @@ pub struct EventCreationData {
|
||||
// Categorization
|
||||
pub categories: String,
|
||||
|
||||
// Reminders
|
||||
pub reminder: ReminderType,
|
||||
// Reminders/Alarms
|
||||
pub alarms: Vec<VAlarm>,
|
||||
|
||||
// Recurrence
|
||||
pub recurrence: RecurrenceType,
|
||||
@@ -145,57 +130,49 @@ impl EventCreationData {
|
||||
String, // organizer
|
||||
String, // attendees
|
||||
String, // categories
|
||||
String, // reminder
|
||||
Vec<VAlarm>, // alarms
|
||||
String, // recurrence
|
||||
Vec<bool>, // recurrence_days
|
||||
Option<String>, // calendar_path
|
||||
u32, // recurrence_interval
|
||||
Option<u32>, // recurrence_count
|
||||
Option<String>, // recurrence_until
|
||||
Option<String>, // calendar_path
|
||||
String, // timezone
|
||||
) {
|
||||
use chrono::{Local, TimeZone};
|
||||
|
||||
// Convert local date/time to UTC for backend
|
||||
let (utc_start_date, utc_start_time, utc_end_date, utc_end_time) = if self.all_day {
|
||||
// For all-day events, just use the dates as-is (no time conversion needed)
|
||||
(
|
||||
self.start_date.format("%Y-%m-%d").to_string(),
|
||||
self.start_time.format("%H:%M").to_string(),
|
||||
self.end_date.format("%Y-%m-%d").to_string(),
|
||||
self.end_time.format("%H:%M").to_string(),
|
||||
)
|
||||
// Use local date/times and timezone - no UTC conversion
|
||||
let effective_end_date = if self.all_day {
|
||||
// For all-day events, add one day to convert from inclusive to exclusive end date
|
||||
// (iCalendar spec requires exclusive end dates for all-day events)
|
||||
self.end_date + chrono::Duration::days(1)
|
||||
} else {
|
||||
// Convert local date/time to UTC
|
||||
let start_local = Local.from_local_datetime(&self.start_date.and_time(self.start_time)).single();
|
||||
let end_local = Local.from_local_datetime(&self.end_date.and_time(self.end_time)).single();
|
||||
|
||||
if let (Some(start_dt), Some(end_dt)) = (start_local, end_local) {
|
||||
let start_utc = start_dt.with_timezone(&chrono::Utc);
|
||||
let end_utc = end_dt.with_timezone(&chrono::Utc);
|
||||
(
|
||||
start_utc.format("%Y-%m-%d").to_string(),
|
||||
start_utc.format("%H:%M").to_string(),
|
||||
end_utc.format("%Y-%m-%d").to_string(),
|
||||
end_utc.format("%H:%M").to_string(),
|
||||
)
|
||||
} else {
|
||||
// Fallback if timezone conversion fails - use local time as-is
|
||||
web_sys::console::warn_1(&"⚠️ Failed to convert local time to UTC, using local time".into());
|
||||
(
|
||||
self.start_date.format("%Y-%m-%d").to_string(),
|
||||
self.start_time.format("%H:%M").to_string(),
|
||||
self.end_date.format("%Y-%m-%d").to_string(),
|
||||
self.end_time.format("%H:%M").to_string(),
|
||||
)
|
||||
}
|
||||
self.end_date
|
||||
};
|
||||
|
||||
// Get the local timezone
|
||||
let timezone = {
|
||||
use js_sys::Date;
|
||||
let date = Date::new_0();
|
||||
let timezone_offset = date.get_timezone_offset(); // Minutes from UTC
|
||||
let hours = -(timezone_offset as i32) / 60; // Convert to hours, negate for proper sign
|
||||
let minutes = (timezone_offset as i32).abs() % 60;
|
||||
format!("{:+03}:{:02}", hours, minutes) // Format as +05:00 or -04:00
|
||||
};
|
||||
|
||||
let (start_date, start_time, end_date, end_time) = (
|
||||
self.start_date.format("%Y-%m-%d").to_string(),
|
||||
self.start_time.format("%H:%M").to_string(),
|
||||
effective_end_date.format("%Y-%m-%d").to_string(),
|
||||
self.end_time.format("%H:%M").to_string(),
|
||||
);
|
||||
|
||||
(
|
||||
self.title.clone(),
|
||||
self.description.clone(),
|
||||
utc_start_date,
|
||||
utc_start_time,
|
||||
utc_end_date,
|
||||
utc_end_time,
|
||||
start_date,
|
||||
start_time,
|
||||
end_date,
|
||||
end_time,
|
||||
self.location.clone(),
|
||||
self.all_day,
|
||||
format!("{:?}", self.status).to_uppercase(),
|
||||
@@ -204,12 +181,14 @@ impl EventCreationData {
|
||||
self.organizer.clone(),
|
||||
self.attendees.clone(),
|
||||
self.categories.clone(),
|
||||
format!("{:?}", self.reminder),
|
||||
self.alarms.clone(),
|
||||
format!("{:?}", self.recurrence),
|
||||
self.recurrence_days.clone(),
|
||||
self.selected_calendar.clone(),
|
||||
self.recurrence_interval,
|
||||
self.recurrence_count,
|
||||
self.recurrence_until.map(|d| d.format("%Y-%m-%d").to_string()),
|
||||
self.selected_calendar.clone(),
|
||||
timezone,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -236,7 +215,7 @@ impl Default for EventCreationData {
|
||||
organizer: String::new(),
|
||||
attendees: String::new(),
|
||||
categories: String::new(),
|
||||
reminder: ReminderType::default(),
|
||||
alarms: Vec::new(),
|
||||
recurrence: RecurrenceType::default(),
|
||||
recurrence_interval: 1,
|
||||
recurrence_until: None,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use crate::models::ical::VEvent;
|
||||
use chrono::{DateTime, Utc};
|
||||
use yew::prelude::*;
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
@@ -213,7 +212,7 @@ pub fn EventModal(props: &EventModalProps) -> Html {
|
||||
}
|
||||
}
|
||||
|
||||
fn format_datetime(dt: &DateTime<Utc>, all_day: bool) -> String {
|
||||
fn format_datetime(dt: &chrono::NaiveDateTime, all_day: bool) -> String {
|
||||
if all_day {
|
||||
dt.format("%B %d, %Y").to_string()
|
||||
} else {
|
||||
@@ -221,7 +220,7 @@ fn format_datetime(dt: &DateTime<Utc>, all_day: bool) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
fn format_datetime_end(dt: &DateTime<Utc>, all_day: bool) -> String {
|
||||
fn format_datetime_end(dt: &chrono::NaiveDateTime, all_day: bool) -> String {
|
||||
if all_day {
|
||||
// For all-day events, subtract one day from end date for display
|
||||
// RFC-5545 uses exclusive end dates, but users expect inclusive display
|
||||
|
||||
@@ -23,6 +23,9 @@ pub fn Login(props: &LoginProps) -> Html {
|
||||
// Remember checkboxes state - default to checked
|
||||
let remember_server = use_state(|| true);
|
||||
let remember_username = use_state(|| true);
|
||||
|
||||
// Password visibility toggle
|
||||
let show_password = use_state(|| false);
|
||||
|
||||
let server_url_ref = use_node_ref();
|
||||
let username_ref = use_node_ref();
|
||||
@@ -30,17 +33,31 @@ pub fn Login(props: &LoginProps) -> Html {
|
||||
|
||||
let on_server_url_change = {
|
||||
let server_url = server_url.clone();
|
||||
let remember_server = remember_server.clone();
|
||||
Callback::from(move |e: Event| {
|
||||
let target = e.target_unchecked_into::<HtmlInputElement>();
|
||||
server_url.set(target.value());
|
||||
let new_value = target.value();
|
||||
server_url.set(new_value.clone());
|
||||
|
||||
// Save to localStorage immediately if remember is checked
|
||||
if *remember_server {
|
||||
let _ = LocalStorage::set("remembered_server_url", new_value);
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let on_username_change = {
|
||||
let username = username.clone();
|
||||
let remember_username = remember_username.clone();
|
||||
Callback::from(move |e: Event| {
|
||||
let target = e.target_unchecked_into::<HtmlInputElement>();
|
||||
username.set(target.value());
|
||||
let new_value = target.value();
|
||||
username.set(new_value.clone());
|
||||
|
||||
// Save to localStorage immediately if remember is checked
|
||||
if *remember_username {
|
||||
let _ = LocalStorage::set("remembered_username", new_value);
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
@@ -83,6 +100,13 @@ pub fn Login(props: &LoginProps) -> Html {
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let on_toggle_password_visibility = {
|
||||
let show_password = show_password.clone();
|
||||
Callback::from(move |_| {
|
||||
show_password.set(!*show_password);
|
||||
})
|
||||
};
|
||||
|
||||
let on_submit = {
|
||||
let server_url = server_url.clone();
|
||||
@@ -90,6 +114,8 @@ pub fn Login(props: &LoginProps) -> Html {
|
||||
let password = password.clone();
|
||||
let error_message = error_message.clone();
|
||||
let is_loading = is_loading.clone();
|
||||
let remember_server = remember_server.clone();
|
||||
let remember_username = remember_username.clone();
|
||||
let on_login = props.on_login.clone();
|
||||
|
||||
Callback::from(move |e: SubmitEvent| {
|
||||
@@ -100,6 +126,8 @@ pub fn Login(props: &LoginProps) -> Html {
|
||||
let password = (*password).clone();
|
||||
let error_message = error_message.clone();
|
||||
let is_loading = is_loading.clone();
|
||||
let remember_server_value = *remember_server;
|
||||
let remember_username_value = *remember_username;
|
||||
let on_login = on_login.clone();
|
||||
|
||||
// Basic client-side validation
|
||||
@@ -140,6 +168,14 @@ pub fn Login(props: &LoginProps) -> Html {
|
||||
let _ = LocalStorage::set("user_preferences", &prefs_json);
|
||||
}
|
||||
|
||||
// Save server URL and username to LocalStorage if remember checkboxes are checked
|
||||
if remember_server_value {
|
||||
let _ = LocalStorage::set("remembered_server_url", server_url.clone());
|
||||
}
|
||||
if remember_username_value {
|
||||
let _ = LocalStorage::set("remembered_username", username.clone());
|
||||
}
|
||||
|
||||
is_loading.set(false);
|
||||
on_login.emit(token);
|
||||
}
|
||||
@@ -164,59 +200,79 @@ pub fn Login(props: &LoginProps) -> Html {
|
||||
<form onsubmit={on_submit}>
|
||||
<div class="form-group">
|
||||
<label for="server_url">{"CalDAV Server URL"}</label>
|
||||
<input
|
||||
ref={server_url_ref}
|
||||
type="text"
|
||||
id="server_url"
|
||||
placeholder="https://your-caldav-server.com/dav/"
|
||||
value={(*server_url).clone()}
|
||||
onchange={on_server_url_change}
|
||||
disabled={*is_loading}
|
||||
/>
|
||||
<div class="remember-checkbox">
|
||||
<div class="input-with-checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="remember_server"
|
||||
checked={*remember_server}
|
||||
onchange={on_remember_server_change}
|
||||
ref={server_url_ref}
|
||||
type="text"
|
||||
id="server_url"
|
||||
placeholder="https://your-caldav-server.com/dav/"
|
||||
value={(*server_url).clone()}
|
||||
onchange={on_server_url_change}
|
||||
disabled={*is_loading}
|
||||
tabindex="1"
|
||||
/>
|
||||
<label for="remember_server">{"Remember server"}</label>
|
||||
<div class="remember-checkbox">
|
||||
<label for="remember_server">{"Remember"}</label>
|
||||
<input
|
||||
type="checkbox"
|
||||
id="remember_server"
|
||||
checked={*remember_server}
|
||||
onchange={on_remember_server_change}
|
||||
tabindex="4"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="username">{"Username"}</label>
|
||||
<input
|
||||
ref={username_ref}
|
||||
type="text"
|
||||
id="username"
|
||||
placeholder="Enter your username"
|
||||
value={(*username).clone()}
|
||||
onchange={on_username_change}
|
||||
disabled={*is_loading}
|
||||
/>
|
||||
<div class="remember-checkbox">
|
||||
<div class="input-with-checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="remember_username"
|
||||
checked={*remember_username}
|
||||
onchange={on_remember_username_change}
|
||||
ref={username_ref}
|
||||
type="text"
|
||||
id="username"
|
||||
placeholder="Enter your username"
|
||||
value={(*username).clone()}
|
||||
onchange={on_username_change}
|
||||
disabled={*is_loading}
|
||||
tabindex="2"
|
||||
/>
|
||||
<label for="remember_username">{"Remember username"}</label>
|
||||
<div class="remember-checkbox">
|
||||
<label for="remember_username">{"Remember"}</label>
|
||||
<input
|
||||
type="checkbox"
|
||||
id="remember_username"
|
||||
checked={*remember_username}
|
||||
onchange={on_remember_username_change}
|
||||
tabindex="5"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">{"Password"}</label>
|
||||
<input
|
||||
ref={password_ref}
|
||||
type="password"
|
||||
id="password"
|
||||
placeholder="Enter your password"
|
||||
value={(*password).clone()}
|
||||
onchange={on_password_change}
|
||||
disabled={*is_loading}
|
||||
/>
|
||||
<div class="password-input-container">
|
||||
<input
|
||||
ref={password_ref}
|
||||
type={if *show_password { "text" } else { "password" }}
|
||||
id="password"
|
||||
placeholder="Enter your password"
|
||||
value={(*password).clone()}
|
||||
onchange={on_password_change}
|
||||
disabled={*is_loading}
|
||||
tabindex="3"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="password-toggle-btn"
|
||||
onclick={on_toggle_password_visibility}
|
||||
tabindex="6"
|
||||
title={if *show_password { "Hide password" } else { "Show password" }}
|
||||
>
|
||||
<i class={if *show_password { "fas fa-eye-slash" } else { "fas fa-eye" }}></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ pub mod calendar_context_menu;
|
||||
pub mod calendar_management_modal;
|
||||
pub mod calendar_header;
|
||||
pub mod calendar_list_item;
|
||||
pub mod color_editor_modal;
|
||||
pub mod context_menu;
|
||||
pub mod create_calendar_modal;
|
||||
pub mod create_event_modal;
|
||||
@@ -13,6 +14,7 @@ pub mod external_calendar_modal;
|
||||
pub mod login;
|
||||
pub mod mobile_warning_modal;
|
||||
pub mod month_view;
|
||||
pub mod print_preview_modal;
|
||||
pub mod recurring_edit_modal;
|
||||
pub mod route_handler;
|
||||
pub mod sidebar;
|
||||
@@ -23,6 +25,7 @@ pub use calendar_context_menu::CalendarContextMenu;
|
||||
pub use calendar_management_modal::CalendarManagementModal;
|
||||
pub use calendar_header::CalendarHeader;
|
||||
pub use calendar_list_item::CalendarListItem;
|
||||
pub use color_editor_modal::ColorEditorModal;
|
||||
pub use context_menu::ContextMenu;
|
||||
pub use create_event_modal::CreateEventModal;
|
||||
// Re-export event form types for backwards compatibility
|
||||
@@ -32,6 +35,7 @@ pub use event_modal::EventModal;
|
||||
pub use login::Login;
|
||||
pub use mobile_warning_modal::MobileWarningModal;
|
||||
pub use month_view::MonthView;
|
||||
pub use print_preview_modal::PrintPreviewModal;
|
||||
pub use recurring_edit_modal::{RecurringEditAction, RecurringEditModal};
|
||||
pub use route_handler::RouteHandler;
|
||||
pub use sidebar::{Sidebar, Theme, ViewMode};
|
||||
|
||||
@@ -113,6 +113,7 @@ pub fn month_view(props: &MonthViewProps) -> Html {
|
||||
"#3B82F6".to_string()
|
||||
};
|
||||
|
||||
|
||||
html! {
|
||||
<div class="calendar-grid">
|
||||
// Weekday headers
|
||||
@@ -212,7 +213,10 @@ pub fn month_view(props: &MonthViewProps) -> Html {
|
||||
{onclick}
|
||||
{oncontextmenu}
|
||||
>
|
||||
{event.summary.as_ref().unwrap_or(&"Untitled".to_string())}
|
||||
<span class="event-title">{event.summary.as_ref().unwrap_or(&"Untitled".to_string())}</span>
|
||||
if !event.alarms.is_empty() {
|
||||
<i class="fas fa-bell event-reminder-icon" title="Has reminders"></i>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}).collect::<Html>()
|
||||
|
||||
362
frontend/src/components/print_preview_modal.rs
Normal file
362
frontend/src/components/print_preview_modal.rs
Normal file
@@ -0,0 +1,362 @@
|
||||
use crate::components::{ViewMode, WeekView, MonthView};
|
||||
use crate::models::ical::VEvent;
|
||||
use crate::services::calendar_service::{UserInfo, ExternalCalendar};
|
||||
use chrono::NaiveDate;
|
||||
use std::collections::HashMap;
|
||||
use wasm_bindgen::{closure::Closure, JsCast};
|
||||
use yew::prelude::*;
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct PrintPreviewModalProps {
|
||||
pub on_close: Callback<()>,
|
||||
pub view_mode: ViewMode,
|
||||
pub current_date: NaiveDate,
|
||||
pub selected_date: NaiveDate,
|
||||
pub events: HashMap<NaiveDate, Vec<VEvent>>,
|
||||
pub user_info: Option<UserInfo>,
|
||||
pub external_calendars: Vec<ExternalCalendar>,
|
||||
pub time_increment: u32,
|
||||
pub today: NaiveDate,
|
||||
}
|
||||
|
||||
#[function_component]
|
||||
pub fn PrintPreviewModal(props: &PrintPreviewModalProps) -> Html {
|
||||
let start_hour = use_state(|| 6u32);
|
||||
let end_hour = use_state(|| 22u32);
|
||||
let zoom_level = use_state(|| 0.4f64); // Default 40% zoom
|
||||
|
||||
let close_modal = {
|
||||
let on_close = props.on_close.clone();
|
||||
Callback::from(move |_| {
|
||||
on_close.emit(());
|
||||
})
|
||||
};
|
||||
|
||||
let backdrop_click = {
|
||||
let on_close = props.on_close.clone();
|
||||
Callback::from(move |e: MouseEvent| {
|
||||
if e.target() == e.current_target() {
|
||||
on_close.emit(());
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let on_start_hour_change = {
|
||||
let start_hour = start_hour.clone();
|
||||
let end_hour = end_hour.clone();
|
||||
Callback::from(move |e: Event| {
|
||||
let target = e.target_dyn_into::<web_sys::HtmlSelectElement>();
|
||||
if let Some(select) = target {
|
||||
if let Ok(hour) = select.value().parse::<u32>() {
|
||||
if hour < *end_hour {
|
||||
start_hour.set(hour);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let on_end_hour_change = {
|
||||
let start_hour = start_hour.clone();
|
||||
let end_hour = end_hour.clone();
|
||||
Callback::from(move |e: Event| {
|
||||
let target = e.target_dyn_into::<web_sys::HtmlSelectElement>();
|
||||
if let Some(select) = target {
|
||||
if let Ok(hour) = select.value().parse::<u32>() {
|
||||
if hour > *start_hour && hour <= 24 {
|
||||
end_hour.set(hour);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
let format_hour = |hour: u32| -> String {
|
||||
if hour == 0 {
|
||||
"12 AM".to_string()
|
||||
} else if hour < 12 {
|
||||
format!("{} AM", hour)
|
||||
} else if hour == 12 {
|
||||
"12 PM".to_string()
|
||||
} else {
|
||||
format!("{} PM", hour - 12)
|
||||
}
|
||||
};
|
||||
|
||||
// Calculate dynamic base unit for print preview
|
||||
let calculate_print_dimensions = |start_hour: u32, end_hour: u32, time_increment: u32| -> (f64, f64, f64) {
|
||||
let visible_hours = (end_hour - start_hour) as f64;
|
||||
let slots_per_hour = if time_increment == 15 { 4.0 } else { 2.0 };
|
||||
let header_height = 50.0; // Fixed week header height in print preview
|
||||
let header_border = 2.0; // Week header bottom border (2px solid)
|
||||
let container_spacing = 8.0; // Additional container spacing/margins
|
||||
let total_overhead = header_height + header_border + container_spacing;
|
||||
let available_height = 720.0 - total_overhead; // Available for time content
|
||||
let base_unit = available_height / (visible_hours * slots_per_hour);
|
||||
let pixels_per_hour = base_unit * slots_per_hour;
|
||||
|
||||
(base_unit, pixels_per_hour, available_height)
|
||||
};
|
||||
|
||||
// Calculate print dimensions for the current hour range
|
||||
let (base_unit, pixels_per_hour, _available_height) = calculate_print_dimensions(*start_hour, *end_hour, props.time_increment);
|
||||
|
||||
// Effect to update print copy whenever modal renders or content changes
|
||||
{
|
||||
let start_hour = *start_hour;
|
||||
let end_hour = *end_hour;
|
||||
let time_increment = props.time_increment;
|
||||
let original_base_unit = base_unit;
|
||||
use_effect(move || {
|
||||
if let Some(window) = web_sys::window() {
|
||||
if let Some(document) = window.document() {
|
||||
// Set CSS variables on document root
|
||||
if let Some(document_element) = document.document_element() {
|
||||
if let Some(html_element) = document_element.dyn_ref::<web_sys::HtmlElement>() {
|
||||
let style = html_element.style();
|
||||
let _ = style.set_property("--print-start-hour", &start_hour.to_string());
|
||||
let _ = style.set_property("--print-end-hour", &end_hour.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// Copy content from print-preview-content to the hidden print-preview-copy div
|
||||
let copy_content = move || {
|
||||
if let Some(preview_content) = document.query_selector(".print-preview-content").ok().flatten() {
|
||||
if let Some(print_copy) = document.get_element_by_id("print-preview-copy") {
|
||||
// Clone the preview content
|
||||
if let Some(content_clone) = preview_content.clone_node_with_deep(true).ok() {
|
||||
// Clear the print copy div and add the cloned content
|
||||
print_copy.set_inner_html("");
|
||||
let _ = print_copy.append_child(&content_clone);
|
||||
|
||||
// Get the actual rendered height of the print copy div and recalculate base-unit
|
||||
if let Some(print_copy_html) = print_copy.dyn_ref::<web_sys::HtmlElement>() {
|
||||
// Temporarily make visible to measure height, then hide again
|
||||
let original_display = print_copy_html.style().get_property_value("display").unwrap_or_default();
|
||||
let _ = print_copy_html.style().set_property("display", "block");
|
||||
let _ = print_copy_html.style().set_property("visibility", "hidden");
|
||||
let _ = print_copy_html.style().set_property("position", "absolute");
|
||||
let _ = print_copy_html.style().set_property("top", "-9999px");
|
||||
|
||||
// Now measure the height
|
||||
let actual_height = print_copy_html.client_height() as f64;
|
||||
|
||||
// Restore original display
|
||||
let _ = print_copy_html.style().set_property("display", &original_display);
|
||||
let _ = print_copy_html.style().remove_property("visibility");
|
||||
let _ = print_copy_html.style().remove_property("position");
|
||||
let _ = print_copy_html.style().remove_property("top");
|
||||
|
||||
// Recalculate base-unit and pixels-per-hour based on actual height
|
||||
let visible_hours = (end_hour - start_hour) as f64;
|
||||
let slots_per_hour = if time_increment == 15 { 4.0 } else { 2.0 };
|
||||
let header_height = 50.0;
|
||||
let header_border = 2.0;
|
||||
let container_spacing = 8.0;
|
||||
let total_overhead = header_height + header_border + container_spacing;
|
||||
let available_height = actual_height - total_overhead;
|
||||
let actual_base_unit = available_height / (visible_hours * slots_per_hour);
|
||||
let actual_pixels_per_hour = actual_base_unit * slots_per_hour;
|
||||
|
||||
|
||||
// Set CSS variables with recalculated values
|
||||
let style = print_copy_html.style();
|
||||
let _ = style.set_property("--print-base-unit", &format!("{:.2}", actual_base_unit));
|
||||
let _ = style.set_property("--print-pixels-per-hour", &format!("{:.2}", actual_pixels_per_hour));
|
||||
let _ = style.set_property("--print-start-hour", &start_hour.to_string());
|
||||
let _ = style.set_property("--print-end-hour", &end_hour.to_string());
|
||||
|
||||
// Copy data attributes
|
||||
let _ = print_copy.set_attribute("data-start-hour", &start_hour.to_string());
|
||||
let _ = print_copy.set_attribute("data-end-hour", &end_hour.to_string());
|
||||
|
||||
// Recalculate event positions using the new base-unit
|
||||
let events = print_copy.query_selector_all(".week-event").unwrap();
|
||||
let scale_factor = actual_base_unit / original_base_unit;
|
||||
|
||||
for i in 0..events.length() {
|
||||
if let Some(event_element) = events.get(i) {
|
||||
if let Some(event_html) = event_element.dyn_ref::<web_sys::HtmlElement>() {
|
||||
let event_style = event_html.style();
|
||||
|
||||
// Get current positioning values and recalculate
|
||||
if let Ok(current_top) = event_style.get_property_value("top") {
|
||||
if current_top.ends_with("px") {
|
||||
if let Ok(top_px) = current_top[..current_top.len()-2].parse::<f64>() {
|
||||
let new_top = top_px * scale_factor;
|
||||
let _ = event_style.set_property("top", &format!("{:.2}px", new_top));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(current_height) = event_style.get_property_value("height") {
|
||||
if current_height.ends_with("px") {
|
||||
if let Ok(height_px) = current_height[..current_height.len()-2].parse::<f64>() {
|
||||
let new_height = height_px * scale_factor;
|
||||
let _ = event_style.set_property("height", &format!("{:.2}px", new_height));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
web_sys::console::log_1(&format!("Height: {:.2}, Original base-unit: {:.2}, New base-unit: {:.2}, Scale factor: {:.2}",
|
||||
actual_height, original_base_unit, actual_base_unit, scale_factor).into());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Copy content immediately
|
||||
copy_content();
|
||||
|
||||
// Also set up a small delay to catch any async rendering
|
||||
let copy_callback = Closure::wrap(Box::new(copy_content) as Box<dyn FnMut()>);
|
||||
let _ = window.set_timeout_with_callback_and_timeout_and_arguments_0(
|
||||
copy_callback.as_ref().unchecked_ref(),
|
||||
100
|
||||
);
|
||||
copy_callback.forget();
|
||||
}
|
||||
}
|
||||
|| ()
|
||||
});
|
||||
}
|
||||
|
||||
let on_print = {
|
||||
Callback::from(move |_: MouseEvent| {
|
||||
if let Some(window) = web_sys::window() {
|
||||
// Print copy is already updated by the use_effect, just trigger print
|
||||
let _ = window.print();
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
html! {
|
||||
<div class="modal-backdrop print-preview-modal-backdrop" onclick={backdrop_click}>
|
||||
<div class="modal-content print-preview-modal">
|
||||
<div class="modal-header">
|
||||
<h3>{"Print Preview"}</h3>
|
||||
<button class="modal-close" onclick={close_modal.clone()}>{"×"}</button>
|
||||
</div>
|
||||
<div class="modal-body print-preview-body">
|
||||
<div class="print-preview-controls">
|
||||
{
|
||||
if props.view_mode == ViewMode::Week {
|
||||
html! {
|
||||
<>
|
||||
<div class="control-group">
|
||||
<label for="start-hour">{"Start Hour:"}</label>
|
||||
<select id="start-hour" onchange={on_start_hour_change}>
|
||||
{
|
||||
(0..24).map(|hour| {
|
||||
html! {
|
||||
<option value={hour.to_string()} selected={hour == *start_hour}>
|
||||
{format_hour(hour)}
|
||||
</option>
|
||||
}
|
||||
}).collect::<Html>()
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label for="end-hour">{"End Hour:"}</label>
|
||||
<select id="end-hour" onchange={on_end_hour_change}>
|
||||
{
|
||||
(1..=24).map(|hour| {
|
||||
html! {
|
||||
<option value={hour.to_string()} selected={hour == *end_hour}>
|
||||
{if hour == 24 { "12 AM".to_string() } else { format_hour(hour) }}
|
||||
</option>
|
||||
}
|
||||
}).collect::<Html>()
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="hour-range-info">
|
||||
{format!("Will print from {} to {}",
|
||||
format_hour(*start_hour),
|
||||
if *end_hour == 24 { "12 AM".to_string() } else { format_hour(*end_hour) }
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
} else {
|
||||
html! {
|
||||
<div class="month-info">
|
||||
{"Will print entire month view"}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
<div class="zoom-display-info">
|
||||
<label>{"Zoom: "}</label>
|
||||
<span>{format!("{}%", (*zoom_level * 100.0) as i32)}</span>
|
||||
<span class="zoom-hint">{"(scroll to zoom)"}</span>
|
||||
</div>
|
||||
<div class="preview-actions">
|
||||
<button class="btn-primary" onclick={on_print}>{"Print"}</button>
|
||||
<button class="btn-secondary" onclick={close_modal}>{"Cancel"}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="print-preview-display" onwheel={{
|
||||
let zoom_level = zoom_level.clone();
|
||||
Callback::from(move |e: WheelEvent| {
|
||||
e.prevent_default(); // Prevent page scroll
|
||||
let delta_y = e.delta_y();
|
||||
let zoom_change = if delta_y < 0.0 { 1.1 } else { 1.0 / 1.1 };
|
||||
let new_zoom = (*zoom_level * zoom_change).clamp(0.2, 1.5);
|
||||
zoom_level.set(new_zoom);
|
||||
})
|
||||
}}>
|
||||
<div class="print-preview-paper"
|
||||
data-start-hour={start_hour.to_string()}
|
||||
data-end-hour={end_hour.to_string()}
|
||||
style={format!(
|
||||
"--print-start-hour: {}; --print-end-hour: {}; --print-base-unit: {:.2}; --print-pixels-per-hour: {:.2}; transform: scale({}); transform-origin: top center;",
|
||||
*start_hour, *end_hour, base_unit, pixels_per_hour, *zoom_level
|
||||
)}>
|
||||
<div class="print-preview-content">
|
||||
{
|
||||
match props.view_mode {
|
||||
ViewMode::Week => html! {
|
||||
<WeekView
|
||||
key={format!("week-preview-{}-{}", *start_hour, *end_hour)}
|
||||
current_date={props.current_date}
|
||||
today={props.today}
|
||||
events={props.events.clone()}
|
||||
on_event_click={Callback::noop()}
|
||||
user_info={props.user_info.clone()}
|
||||
external_calendars={props.external_calendars.clone()}
|
||||
time_increment={props.time_increment}
|
||||
print_mode={true}
|
||||
print_pixels_per_hour={Some(pixels_per_hour)}
|
||||
print_start_hour={Some(*start_hour)}
|
||||
/>
|
||||
},
|
||||
ViewMode::Month => html! {
|
||||
<MonthView
|
||||
key={format!("month-preview-{}-{}", *start_hour, *end_hour)}
|
||||
current_month={props.current_date}
|
||||
selected_date={Some(props.selected_date)}
|
||||
today={props.today}
|
||||
events={props.events.clone()}
|
||||
on_day_select={None::<Callback<NaiveDate>>}
|
||||
on_event_click={Callback::noop()}
|
||||
user_info={props.user_info.clone()}
|
||||
external_calendars={props.external_calendars.clone()}
|
||||
/>
|
||||
},
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ pub struct RouteHandlerProps {
|
||||
chrono::NaiveDateTime,
|
||||
chrono::NaiveDateTime,
|
||||
bool,
|
||||
Option<chrono::DateTime<chrono::Utc>>,
|
||||
Option<chrono::NaiveDateTime>,
|
||||
Option<String>,
|
||||
Option<String>,
|
||||
)>,
|
||||
@@ -136,7 +136,7 @@ pub struct CalendarViewProps {
|
||||
chrono::NaiveDateTime,
|
||||
chrono::NaiveDateTime,
|
||||
bool,
|
||||
Option<chrono::DateTime<chrono::Utc>>,
|
||||
Option<chrono::NaiveDateTime>,
|
||||
Option<String>,
|
||||
Option<String>,
|
||||
)>,
|
||||
|
||||
@@ -2,17 +2,7 @@ use crate::components::CalendarListItem;
|
||||
use crate::services::calendar_service::{UserInfo, ExternalCalendar};
|
||||
use web_sys::HtmlSelectElement;
|
||||
use yew::prelude::*;
|
||||
use yew_router::prelude::*;
|
||||
|
||||
#[derive(Clone, Routable, PartialEq)]
|
||||
pub enum Route {
|
||||
#[at("/")]
|
||||
Home,
|
||||
#[at("/login")]
|
||||
Login,
|
||||
#[at("/calendar")]
|
||||
Calendar,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum ViewMode {
|
||||
@@ -109,6 +99,7 @@ pub struct SidebarProps {
|
||||
pub on_color_change: Callback<(String, String)>,
|
||||
pub on_color_picker_toggle: Callback<String>,
|
||||
pub available_colors: Vec<String>,
|
||||
pub on_color_editor_open: Callback<(usize, String)>, // (index, current_color)
|
||||
pub refreshing_calendar_id: Option<i32>,
|
||||
pub on_calendar_context_menu: Callback<(MouseEvent, String)>,
|
||||
pub on_calendar_visibility_toggle: Callback<String>,
|
||||
@@ -219,6 +210,7 @@ pub fn sidebar(props: &SidebarProps) -> Html {
|
||||
on_color_change={props.on_color_change.clone()}
|
||||
on_color_picker_toggle={props.on_color_picker_toggle.clone()}
|
||||
available_colors={props.available_colors.clone()}
|
||||
on_color_editor_open={props.on_color_editor_open.clone()}
|
||||
on_context_menu={props.on_calendar_context_menu.clone()}
|
||||
on_visibility_toggle={props.on_calendar_visibility_toggle.clone()}
|
||||
/>
|
||||
@@ -299,6 +291,17 @@ pub fn sidebar(props: &SidebarProps) -> Html {
|
||||
let on_color_select = Callback::from(move |_: MouseEvent| {
|
||||
on_color_change.emit((external_id.clone(), color_str.clone()));
|
||||
});
|
||||
|
||||
let on_color_right_click = {
|
||||
let on_color_editor_open = props.on_color_editor_open.clone();
|
||||
let color_index = props.available_colors.iter().position(|c| c == color).unwrap_or(0);
|
||||
let color_str = color.clone();
|
||||
Callback::from(move |e: MouseEvent| {
|
||||
e.prevent_default();
|
||||
e.stop_propagation();
|
||||
on_color_editor_open.emit((color_index, color_str.clone()));
|
||||
})
|
||||
};
|
||||
|
||||
let is_selected = cal.color == *color;
|
||||
|
||||
@@ -308,6 +311,7 @@ pub fn sidebar(props: &SidebarProps) -> Html {
|
||||
class={if is_selected { "color-option selected" } else { "color-option" }}
|
||||
style={format!("background-color: {}", color)}
|
||||
onclick={on_color_select}
|
||||
oncontextmenu={on_color_right_click}
|
||||
/>
|
||||
}
|
||||
}).collect::<Html>()
|
||||
@@ -350,9 +354,9 @@ pub fn sidebar(props: &SidebarProps) -> Html {
|
||||
>
|
||||
{
|
||||
if props.refreshing_calendar_id == Some(cal.id) {
|
||||
"⏳" // Loading spinner
|
||||
html! { <i class="fas fa-spinner fa-spin"></i> }
|
||||
} else {
|
||||
"🔄" // Normal refresh icon
|
||||
html! { <i class="fas fa-sync-alt"></i> }
|
||||
}
|
||||
}
|
||||
</button>
|
||||
|
||||
@@ -33,7 +33,7 @@ pub struct WeekViewProps {
|
||||
NaiveDateTime,
|
||||
NaiveDateTime,
|
||||
bool,
|
||||
Option<chrono::DateTime<chrono::Utc>>,
|
||||
Option<chrono::NaiveDateTime>,
|
||||
Option<String>,
|
||||
Option<String>,
|
||||
)>,
|
||||
@@ -42,6 +42,12 @@ pub struct WeekViewProps {
|
||||
pub context_menus_open: bool,
|
||||
#[prop_or_default]
|
||||
pub time_increment: u32,
|
||||
#[prop_or_default]
|
||||
pub print_mode: bool,
|
||||
#[prop_or_default]
|
||||
pub print_pixels_per_hour: Option<f64>,
|
||||
#[prop_or_default]
|
||||
pub print_start_hour: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
@@ -279,18 +285,14 @@ pub fn week_view(props: &WeekViewProps) -> Html {
|
||||
|
||||
// Calculate the day before this occurrence for UNTIL clause
|
||||
let until_date =
|
||||
edit.event.dtstart.date_naive() - chrono::Duration::days(1);
|
||||
edit.event.dtstart.date() - chrono::Duration::days(1);
|
||||
let until_datetime = until_date
|
||||
.and_time(chrono::NaiveTime::from_hms_opt(23, 59, 59).unwrap());
|
||||
let until_utc =
|
||||
chrono::DateTime::<chrono::Utc>::from_naive_utc_and_offset(
|
||||
until_datetime,
|
||||
chrono::Utc,
|
||||
);
|
||||
let until_naive = until_datetime; // Use local time directly
|
||||
|
||||
web_sys::console::log_1(&format!("🔄 Will set UNTIL {} for original series to end before occurrence {}",
|
||||
until_utc.format("%Y-%m-%d %H:%M:%S UTC"),
|
||||
edit.event.dtstart.format("%Y-%m-%d %H:%M:%S UTC")).into());
|
||||
until_naive.format("%Y-%m-%d %H:%M:%S"),
|
||||
edit.event.dtstart.format("%Y-%m-%d %H:%M:%S")).into());
|
||||
|
||||
// Critical: Use the dragged times (new_start/new_end) not the original series times
|
||||
// This ensures the new series reflects the user's drag operation
|
||||
@@ -311,7 +313,7 @@ pub fn week_view(props: &WeekViewProps) -> Html {
|
||||
new_start, // Dragged start time for new series
|
||||
new_end, // Dragged end time for new series
|
||||
true, // preserve_rrule = true
|
||||
Some(until_utc), // UNTIL date for original series
|
||||
Some(until_naive), // UNTIL date for original series
|
||||
Some("this_and_future".to_string()), // Update scope
|
||||
Some(occurrence_date), // Date of occurrence being modified
|
||||
));
|
||||
@@ -346,6 +348,7 @@ pub fn week_view(props: &WeekViewProps) -> Html {
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
html! {
|
||||
<div class="week-view-container">
|
||||
// Header with weekday names and dates
|
||||
@@ -438,13 +441,13 @@ pub fn week_view(props: &WeekViewProps) -> Html {
|
||||
// Time labels
|
||||
<div class={classes!("time-labels", if props.time_increment == 15 { Some("quarter-mode") } else { None })}>
|
||||
{
|
||||
time_labels.iter().map(|time| {
|
||||
time_labels.iter().enumerate().map(|(hour, time)| {
|
||||
let is_quarter_mode = props.time_increment == 15;
|
||||
html! {
|
||||
<div class={classes!(
|
||||
"time-label",
|
||||
if is_quarter_mode { Some("quarter-mode") } else { None }
|
||||
)}>
|
||||
)} data-hour={hour.to_string()}>
|
||||
{time}
|
||||
</div>
|
||||
}
|
||||
@@ -611,10 +614,9 @@ pub fn week_view(props: &WeekViewProps) -> Html {
|
||||
|
||||
// Keep the original end time
|
||||
let original_end = if let Some(end) = event.dtend {
|
||||
end.with_timezone(&chrono::Local).naive_local()
|
||||
} else {
|
||||
end } else {
|
||||
// If no end time, use start time + 1 hour as default
|
||||
event.dtstart.with_timezone(&chrono::Local).naive_local() + chrono::Duration::hours(1)
|
||||
event.dtstart + chrono::Duration::hours(1)
|
||||
};
|
||||
|
||||
let new_start_datetime = NaiveDateTime::new(current_drag.start_date, new_start_time);
|
||||
@@ -645,8 +647,8 @@ pub fn week_view(props: &WeekViewProps) -> Html {
|
||||
// Calculate new end time based on drag position
|
||||
let new_end_time = pixels_to_time(current_drag.current_y, time_increment);
|
||||
|
||||
// Keep the original start time
|
||||
let original_start = event.dtstart.with_timezone(&chrono::Local).naive_local();
|
||||
// Keep the original start time (already local)
|
||||
let original_start = event.dtstart;
|
||||
|
||||
let new_end_datetime = NaiveDateTime::new(current_drag.start_date, new_end_time);
|
||||
|
||||
@@ -701,10 +703,10 @@ pub fn week_view(props: &WeekViewProps) -> Html {
|
||||
>
|
||||
// Time slot backgrounds - 24 hour slots to represent full day
|
||||
{
|
||||
(0..24).map(|_hour| {
|
||||
(0..24).map(|hour| {
|
||||
let slots_per_hour = 60 / props.time_increment;
|
||||
html! {
|
||||
<div class={classes!("time-slot", if props.time_increment == 15 { Some("quarter-mode") } else { None })}>
|
||||
<div class={classes!("time-slot", if props.time_increment == 15 { Some("quarter-mode") } else { None })} data-hour={hour.to_string()}>
|
||||
{
|
||||
(0..slots_per_hour).map(|_slot| {
|
||||
let slot_class = if props.time_increment == 15 {
|
||||
@@ -726,7 +728,7 @@ pub fn week_view(props: &WeekViewProps) -> Html {
|
||||
<div class="events-container">
|
||||
{
|
||||
day_events.iter().enumerate().filter_map(|(event_idx, event)| {
|
||||
let (start_pixels, duration_pixels, is_all_day) = calculate_event_position(event, *date, props.time_increment);
|
||||
let (start_pixels, duration_pixels, is_all_day) = calculate_event_position(event, *date, props.time_increment, props.print_pixels_per_hour, props.print_start_hour);
|
||||
|
||||
// Skip all-day events (they're rendered in the header)
|
||||
if is_all_day {
|
||||
@@ -755,6 +757,8 @@ pub fn week_view(props: &WeekViewProps) -> Html {
|
||||
let event_for_drag = event.clone();
|
||||
let date_for_drag = *date;
|
||||
let time_increment = props.time_increment;
|
||||
let print_pixels_per_hour = props.print_pixels_per_hour;
|
||||
let print_start_hour = props.print_start_hour;
|
||||
Callback::from(move |e: MouseEvent| {
|
||||
e.stop_propagation(); // Prevent drag-to-create from starting on event clicks
|
||||
|
||||
@@ -768,7 +772,7 @@ pub fn week_view(props: &WeekViewProps) -> Html {
|
||||
let click_y_relative = if click_y_relative > 0.0 { click_y_relative } else { e.offset_y() as f64 };
|
||||
|
||||
// Get event's current position in day column coordinates
|
||||
let (event_start_pixels, _, _) = calculate_event_position(&event_for_drag, date_for_drag, time_increment);
|
||||
let (event_start_pixels, _, _) = calculate_event_position(&event_for_drag, date_for_drag, time_increment, print_pixels_per_hour, print_start_hour);
|
||||
let event_start_pixels = event_start_pixels as f64;
|
||||
|
||||
// Convert click position to day column coordinates
|
||||
@@ -819,9 +823,9 @@ pub fn week_view(props: &WeekViewProps) -> Html {
|
||||
let time_display = if event.all_day {
|
||||
"All Day".to_string()
|
||||
} else {
|
||||
let local_start = event.dtstart.with_timezone(&Local);
|
||||
let local_start = event.dtstart;
|
||||
if let Some(end) = event.dtend {
|
||||
let local_end = end.with_timezone(&Local);
|
||||
let local_end = end;
|
||||
|
||||
// Check if both times are in same AM/PM period to avoid redundancy
|
||||
let start_is_am = local_start.hour() < 12;
|
||||
@@ -964,7 +968,12 @@ pub fn week_view(props: &WeekViewProps) -> Html {
|
||||
|
||||
// Event content
|
||||
<div class="event-content">
|
||||
<div class="event-title">{event.summary.as_ref().unwrap_or(&"Untitled".to_string())}</div>
|
||||
<div class="event-title-row">
|
||||
<span class="event-title">{event.summary.as_ref().unwrap_or(&"Untitled".to_string())}</span>
|
||||
if !event.alarms.is_empty() {
|
||||
<i class="fas fa-bell event-reminder-icon" title="Has reminders"></i>
|
||||
}
|
||||
</div>
|
||||
{if !is_all_day && duration_pixels > 30.0 {
|
||||
html! { <div class="event-time">{time_display}</div> }
|
||||
} else {
|
||||
@@ -1048,14 +1057,13 @@ pub fn week_view(props: &WeekViewProps) -> Html {
|
||||
// Show the event being resized from the start
|
||||
let new_start_time = pixels_to_time(drag.current_y, props.time_increment);
|
||||
let original_end = if let Some(end) = event.dtend {
|
||||
end.with_timezone(&chrono::Local).naive_local()
|
||||
} else {
|
||||
event.dtstart.with_timezone(&chrono::Local).naive_local() + chrono::Duration::hours(1)
|
||||
end } else {
|
||||
event.dtstart + chrono::Duration::hours(1)
|
||||
};
|
||||
|
||||
// Calculate positions for the preview
|
||||
let (original_start_pixels, _, _) = calculate_event_position(event, drag.start_date, props.time_increment);
|
||||
let original_duration = original_end.signed_duration_since(event.dtstart.with_timezone(&chrono::Local).naive_local());
|
||||
let (original_start_pixels, _, _) = calculate_event_position(event, drag.start_date, props.time_increment, props.print_pixels_per_hour, props.print_start_hour);
|
||||
let original_duration = original_end.signed_duration_since(event.dtstart);
|
||||
let original_end_pixels = original_start_pixels + (original_duration.num_minutes() as f32);
|
||||
|
||||
let new_start_pixels = drag.current_y;
|
||||
@@ -1081,10 +1089,10 @@ pub fn week_view(props: &WeekViewProps) -> Html {
|
||||
DragType::ResizeEventEnd(event) => {
|
||||
// Show the event being resized from the end
|
||||
let new_end_time = pixels_to_time(drag.current_y, props.time_increment);
|
||||
let original_start = event.dtstart.with_timezone(&chrono::Local).naive_local();
|
||||
let original_start = event.dtstart;
|
||||
|
||||
// Calculate positions for the preview
|
||||
let (original_start_pixels, _, _) = calculate_event_position(event, drag.start_date, props.time_increment);
|
||||
let (original_start_pixels, _, _) = calculate_event_position(event, drag.start_date, props.time_increment, props.print_pixels_per_hour, props.print_start_hour);
|
||||
|
||||
let new_end_pixels = drag.current_y;
|
||||
let new_height = (new_end_pixels - original_start_pixels as f64).max(20.0);
|
||||
@@ -1218,18 +1226,15 @@ fn pixels_to_time(pixels: f64, time_increment: u32) -> NaiveTime {
|
||||
NaiveTime::from_hms_opt(hours, minutes, 0).unwrap_or(NaiveTime::from_hms_opt(0, 0, 0).unwrap())
|
||||
}
|
||||
|
||||
fn calculate_event_position(event: &VEvent, date: NaiveDate, time_increment: u32) -> (f32, f32, bool) {
|
||||
// Convert UTC times to local time for display
|
||||
let local_start = event.dtstart.with_timezone(&Local);
|
||||
let event_date = local_start.date_naive();
|
||||
|
||||
// Position events based on when they appear in local time, not their original date
|
||||
// For timezone issues: an event created at 10 PM Sunday might be stored as Monday UTC
|
||||
// but should still display on Sunday's column since that's when the user sees it
|
||||
let should_display_here = event_date == date ||
|
||||
(event_date == date - chrono::Duration::days(1) && local_start.hour() >= 20);
|
||||
fn calculate_event_position(event: &VEvent, date: NaiveDate, time_increment: u32, print_pixels_per_hour: Option<f64>, print_start_hour: Option<u32>) -> (f32, f32, bool) {
|
||||
// Events are already in local time
|
||||
let local_start = event.dtstart;
|
||||
|
||||
if !should_display_here {
|
||||
// Events should display based on their local date, since we now store proper UTC times
|
||||
// Convert the UTC stored time back to local time to determine display date
|
||||
let event_date = local_start.date();
|
||||
|
||||
if event_date != date {
|
||||
return (0.0, 0.0, false); // Event not on this date
|
||||
}
|
||||
|
||||
@@ -1238,32 +1243,44 @@ fn calculate_event_position(event: &VEvent, date: NaiveDate, time_increment: u32
|
||||
return (0.0, 30.0, true); // Position at top, 30px height, is_all_day = true
|
||||
}
|
||||
|
||||
// Calculate start position in pixels from midnight
|
||||
// Calculate start position in pixels
|
||||
let start_hour = local_start.hour() as f32;
|
||||
let start_minute = local_start.minute() as f32;
|
||||
let pixels_per_hour = if time_increment == 15 { 120.0 } else { 60.0 };
|
||||
let start_pixels = (start_hour + start_minute / 60.0) * pixels_per_hour;
|
||||
let pixels_per_hour = if let Some(print_pph) = print_pixels_per_hour {
|
||||
print_pph as f32 // Use the dynamic print mode calculation
|
||||
} else {
|
||||
if time_increment == 15 { 120.0 } else { 60.0 } // Default values
|
||||
};
|
||||
|
||||
// In print mode, offset by the start hour to show relative position within visible range
|
||||
let hour_offset = if let Some(print_start) = print_start_hour {
|
||||
print_start as f32
|
||||
} else {
|
||||
0.0 // No offset for normal view (starts at midnight)
|
||||
};
|
||||
|
||||
let start_pixels = ((start_hour + start_minute / 60.0) - hour_offset) * pixels_per_hour;
|
||||
|
||||
// Calculate duration and height
|
||||
let duration_pixels = if let Some(end) = event.dtend {
|
||||
let local_end = end.with_timezone(&Local);
|
||||
let end_date = local_end.date_naive();
|
||||
let local_end = end;
|
||||
let end_date = local_end.date();
|
||||
|
||||
// Handle events that span multiple days by capping at midnight
|
||||
if end_date > date {
|
||||
// Event continues past midnight, cap at 24:00
|
||||
let max_pixels = 24.0 * pixels_per_hour;
|
||||
max_pixels - start_pixels
|
||||
// Event continues past midnight, cap at end of visible range
|
||||
let max_hour = if let Some(_print_start) = print_start_hour { 24.0 } else { 24.0 };
|
||||
let max_pixels = (max_hour - hour_offset) * pixels_per_hour;
|
||||
(max_pixels - start_pixels).max(20.0)
|
||||
} else {
|
||||
let end_hour = local_end.hour() as f32;
|
||||
let end_minute = local_end.minute() as f32;
|
||||
let end_pixels = (end_hour + end_minute / 60.0) * pixels_per_hour;
|
||||
let end_pixels = ((end_hour + end_minute / 60.0) - hour_offset) * pixels_per_hour;
|
||||
(end_pixels - start_pixels).max(20.0) // Minimum 20px height
|
||||
}
|
||||
} else {
|
||||
pixels_per_hour // Default 1 hour if no end time
|
||||
};
|
||||
|
||||
(start_pixels, duration_pixels, false) // is_all_day = false
|
||||
}
|
||||
|
||||
@@ -1274,16 +1291,16 @@ fn events_overlap(event1: &VEvent, event2: &VEvent) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
let start1 = event1.dtstart.with_timezone(&Local).naive_local();
|
||||
let start1 = event1.dtstart;
|
||||
let end1 = if let Some(end) = event1.dtend {
|
||||
end.with_timezone(&Local).naive_local()
|
||||
end
|
||||
} else {
|
||||
start1 + chrono::Duration::hours(1) // Default 1 hour duration
|
||||
};
|
||||
|
||||
let start2 = event2.dtstart.with_timezone(&Local).naive_local();
|
||||
let start2 = event2.dtstart;
|
||||
let end2 = if let Some(end) = event2.dtend {
|
||||
end.with_timezone(&Local).naive_local()
|
||||
end
|
||||
} else {
|
||||
start2 + chrono::Duration::hours(1) // Default 1 hour duration
|
||||
};
|
||||
@@ -1304,9 +1321,9 @@ fn calculate_event_layout(events: &[VEvent], date: NaiveDate, time_increment: u3
|
||||
return None;
|
||||
}
|
||||
|
||||
let (_, _, _) = calculate_event_position(event, date, time_increment);
|
||||
let local_start = event.dtstart.with_timezone(&Local);
|
||||
let event_date = local_start.date_naive();
|
||||
let (_, _, _) = calculate_event_position(event, date, time_increment, None, None);
|
||||
let local_start = event.dtstart;
|
||||
let event_date = local_start.date();
|
||||
if event_date == date ||
|
||||
(event_date == date - chrono::Duration::days(1) && local_start.hour() >= 20) {
|
||||
Some((idx, event))
|
||||
@@ -1317,7 +1334,7 @@ fn calculate_event_layout(events: &[VEvent], date: NaiveDate, time_increment: u3
|
||||
.collect();
|
||||
|
||||
// Sort by start time
|
||||
day_events.sort_by_key(|(_, event)| event.dtstart.with_timezone(&Local).naive_local());
|
||||
day_events.sort_by_key(|(_, event)| event.dtstart);
|
||||
|
||||
// For each event, find all events it overlaps with
|
||||
let mut event_columns = vec![(0, 1); events.len()]; // (column_idx, total_columns)
|
||||
@@ -1342,7 +1359,7 @@ fn calculate_event_layout(events: &[VEvent], date: NaiveDate, time_increment: u3
|
||||
} else {
|
||||
// This event overlaps - we need to calculate column layout
|
||||
// Sort the overlapping group by start time
|
||||
overlapping_events.sort_by_key(|&idx| day_events[idx].1.dtstart.with_timezone(&Local).naive_local());
|
||||
overlapping_events.sort_by_key(|&idx| day_events[idx].1.dtstart);
|
||||
|
||||
// Assign columns using a greedy algorithm
|
||||
let mut columns: Vec<Vec<usize>> = Vec::new();
|
||||
@@ -1390,19 +1407,19 @@ fn event_spans_date(event: &VEvent, date: NaiveDate) -> bool {
|
||||
let start_date = if event.all_day {
|
||||
// For all-day events, extract date directly from UTC without timezone conversion
|
||||
// since all-day events are stored at noon UTC to avoid timezone boundary issues
|
||||
event.dtstart.date_naive()
|
||||
event.dtstart.date()
|
||||
} else {
|
||||
event.dtstart.with_timezone(&Local).date_naive()
|
||||
event.dtstart.date()
|
||||
};
|
||||
|
||||
let end_date = if let Some(dtend) = event.dtend {
|
||||
if event.all_day {
|
||||
// For all-day events, dtend is set to the day after the last day (RFC 5545)
|
||||
// Extract date directly from UTC and subtract a day to get actual last day
|
||||
dtend.date_naive() - chrono::Duration::days(1)
|
||||
dtend.date() - chrono::Duration::days(1)
|
||||
} else {
|
||||
// For timed events, use timezone conversion
|
||||
dtend.with_timezone(&Local).date_naive()
|
||||
dtend.date()
|
||||
}
|
||||
} else {
|
||||
// Single day event
|
||||
|
||||
299
frontend/src/services/alarm_scheduler.rs
Normal file
299
frontend/src/services/alarm_scheduler.rs
Normal file
@@ -0,0 +1,299 @@
|
||||
use calendar_models::{VAlarm, AlarmAction, AlarmTrigger, VEvent};
|
||||
use chrono::{Duration, Local, NaiveDateTime};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use crate::services::{NotificationManager, AlarmNotification};
|
||||
use gloo_storage::{LocalStorage, Storage};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ScheduledAlarm {
|
||||
pub id: String, // Unique alarm ID
|
||||
pub event_uid: String, // Event this alarm belongs to
|
||||
pub event_summary: String, // Event title for notification
|
||||
pub event_location: Option<String>, // Event location for notification
|
||||
pub event_start: NaiveDateTime, // Event start time (local)
|
||||
pub trigger_time: NaiveDateTime, // When alarm should trigger (local)
|
||||
pub alarm_action: AlarmAction, // Type of alarm
|
||||
pub status: AlarmStatus, // Current status
|
||||
pub created_at: NaiveDateTime, // When alarm was scheduled
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub enum AlarmStatus {
|
||||
Pending, // Waiting to trigger
|
||||
Triggered, // Has been triggered
|
||||
Dismissed, // User dismissed
|
||||
Expired, // Past due (event ended)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AlarmScheduler {
|
||||
scheduled_alarms: HashMap<String, ScheduledAlarm>,
|
||||
notification_manager: NotificationManager,
|
||||
}
|
||||
|
||||
const ALARMS_STORAGE_KEY: &str = "scheduled_alarms";
|
||||
|
||||
impl AlarmScheduler {
|
||||
pub fn new() -> Self {
|
||||
let mut scheduler = Self {
|
||||
scheduled_alarms: HashMap::new(),
|
||||
notification_manager: NotificationManager::new(),
|
||||
};
|
||||
|
||||
// Load alarms from localStorage
|
||||
scheduler.load_alarms_from_storage();
|
||||
scheduler
|
||||
}
|
||||
|
||||
/// Load alarms from localStorage
|
||||
fn load_alarms_from_storage(&mut self) {
|
||||
if let Ok(alarms) = LocalStorage::get::<HashMap<String, ScheduledAlarm>>(ALARMS_STORAGE_KEY) {
|
||||
self.scheduled_alarms = alarms;
|
||||
}
|
||||
}
|
||||
|
||||
/// Save alarms to localStorage
|
||||
fn save_alarms_to_storage(&self) {
|
||||
if let Err(e) = LocalStorage::set(ALARMS_STORAGE_KEY, &self.scheduled_alarms) {
|
||||
web_sys::console::error_1(
|
||||
&format!("Failed to save alarms to localStorage: {:?}", e).into()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Schedule alarms for an event
|
||||
pub fn schedule_event_alarms(&mut self, event: &VEvent) {
|
||||
// Check notification permission before scheduling
|
||||
let permission = NotificationManager::get_permission();
|
||||
if permission != web_sys::NotificationPermission::Granted && !event.alarms.is_empty() {
|
||||
// Try to force request permission asynchronously
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
let _ = NotificationManager::force_request_permission().await;
|
||||
});
|
||||
}
|
||||
|
||||
// Remove any existing alarms for this event
|
||||
self.remove_event_alarms(&event.uid);
|
||||
|
||||
// Get event details
|
||||
let event_summary = event.summary.as_ref().unwrap_or(&"Untitled Event".to_string()).clone();
|
||||
let event_location = event.location.clone();
|
||||
let event_start = event.dtstart;
|
||||
|
||||
// Schedule each alarm
|
||||
for alarm in &event.alarms {
|
||||
if let Some(scheduled_alarm) = self.create_scheduled_alarm(
|
||||
event,
|
||||
alarm,
|
||||
&event_summary,
|
||||
&event_location,
|
||||
event_start,
|
||||
) {
|
||||
self.scheduled_alarms.insert(scheduled_alarm.id.clone(), scheduled_alarm);
|
||||
}
|
||||
}
|
||||
|
||||
// Save to localStorage
|
||||
self.save_alarms_to_storage();
|
||||
}
|
||||
|
||||
/// Create a scheduled alarm from a VAlarm
|
||||
fn create_scheduled_alarm(
|
||||
&self,
|
||||
event: &VEvent,
|
||||
valarm: &VAlarm,
|
||||
event_summary: &str,
|
||||
event_location: &Option<String>,
|
||||
event_start: NaiveDateTime,
|
||||
) -> Option<ScheduledAlarm> {
|
||||
// Only handle Display alarms for now
|
||||
if valarm.action != AlarmAction::Display {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Calculate trigger time
|
||||
let trigger_time = match &valarm.trigger {
|
||||
AlarmTrigger::Duration(duration) => {
|
||||
// Duration relative to event start
|
||||
let trigger_time = event_start + *duration;
|
||||
|
||||
// Ensure trigger time is not in the past (with 30 second tolerance)
|
||||
let now = Local::now().naive_local();
|
||||
if trigger_time < now - Duration::seconds(30) {
|
||||
web_sys::console::warn_1(
|
||||
&format!("Skipping past alarm for event: {} (trigger: {})",
|
||||
event_summary,
|
||||
trigger_time.format("%Y-%m-%d %H:%M:%S")
|
||||
).into()
|
||||
);
|
||||
return None;
|
||||
}
|
||||
|
||||
trigger_time
|
||||
}
|
||||
AlarmTrigger::DateTime(datetime) => {
|
||||
// Absolute datetime - convert to local time
|
||||
let local_trigger = datetime.with_timezone(&Local).naive_local();
|
||||
|
||||
// Ensure trigger time is not in the past
|
||||
let now = Local::now().naive_local();
|
||||
if local_trigger < now - Duration::seconds(30) {
|
||||
web_sys::console::warn_1(
|
||||
&format!("Skipping past absolute alarm for event: {} (trigger: {})",
|
||||
event_summary,
|
||||
local_trigger.format("%Y-%m-%d %H:%M:%S")
|
||||
).into()
|
||||
);
|
||||
return None;
|
||||
}
|
||||
|
||||
local_trigger
|
||||
}
|
||||
};
|
||||
|
||||
// Generate unique alarm ID
|
||||
let alarm_id = format!("{}_{}", event.uid, trigger_time.and_utc().timestamp());
|
||||
|
||||
Some(ScheduledAlarm {
|
||||
id: alarm_id,
|
||||
event_uid: event.uid.clone(),
|
||||
event_summary: event_summary.to_string(),
|
||||
event_location: event_location.clone(),
|
||||
event_start,
|
||||
trigger_time,
|
||||
alarm_action: valarm.action.clone(),
|
||||
status: AlarmStatus::Pending,
|
||||
created_at: Local::now().naive_local(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Remove all alarms for an event
|
||||
pub fn remove_event_alarms(&mut self, event_uid: &str) {
|
||||
let alarm_ids: Vec<String> = self.scheduled_alarms
|
||||
.iter()
|
||||
.filter(|(_, alarm)| alarm.event_uid == event_uid)
|
||||
.map(|(id, _)| id.clone())
|
||||
.collect();
|
||||
|
||||
for alarm_id in alarm_ids {
|
||||
self.scheduled_alarms.remove(&alarm_id);
|
||||
}
|
||||
|
||||
// Also close any active notifications for this event
|
||||
self.notification_manager.close_notification(event_uid);
|
||||
|
||||
// Save to localStorage
|
||||
self.save_alarms_to_storage();
|
||||
}
|
||||
|
||||
/// Check for alarms that should trigger now and trigger them
|
||||
pub fn check_and_trigger_alarms(&mut self) -> usize {
|
||||
// Reload alarms from localStorage to ensure we have the latest data
|
||||
self.load_alarms_from_storage();
|
||||
|
||||
let now = Local::now().naive_local();
|
||||
let mut triggered_count = 0;
|
||||
|
||||
// Find alarms that should trigger (within 30 seconds tolerance)
|
||||
let alarms_to_trigger: Vec<ScheduledAlarm> = self.scheduled_alarms
|
||||
.values()
|
||||
.filter(|alarm| {
|
||||
alarm.status == AlarmStatus::Pending &&
|
||||
alarm.trigger_time <= now + Duration::seconds(30) &&
|
||||
alarm.trigger_time >= now - Duration::seconds(30)
|
||||
})
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
for alarm in alarms_to_trigger {
|
||||
if self.trigger_alarm(&alarm) {
|
||||
// Mark alarm as triggered
|
||||
if let Some(scheduled_alarm) = self.scheduled_alarms.get_mut(&alarm.id) {
|
||||
scheduled_alarm.status = AlarmStatus::Triggered;
|
||||
}
|
||||
triggered_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up expired alarms (events that ended more than 1 hour ago)
|
||||
self.cleanup_expired_alarms();
|
||||
|
||||
// Save to localStorage if any changes were made
|
||||
if triggered_count > 0 {
|
||||
self.save_alarms_to_storage();
|
||||
}
|
||||
|
||||
triggered_count
|
||||
}
|
||||
|
||||
/// Trigger a specific alarm
|
||||
fn trigger_alarm(&mut self, alarm: &ScheduledAlarm) -> bool {
|
||||
// Don't trigger if already showing notification for this event
|
||||
if self.notification_manager.has_notification(&alarm.event_uid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let alarm_notification = AlarmNotification {
|
||||
event_uid: alarm.event_uid.clone(),
|
||||
event_summary: alarm.event_summary.clone(),
|
||||
event_location: alarm.event_location.clone(),
|
||||
alarm_time: alarm.event_start,
|
||||
};
|
||||
|
||||
match self.notification_manager.show_alarm_notification(alarm_notification) {
|
||||
Ok(()) => true,
|
||||
Err(err) => {
|
||||
web_sys::console::error_1(
|
||||
&format!("Failed to trigger alarm: {:?}", err).into()
|
||||
);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Clean up expired alarms
|
||||
fn cleanup_expired_alarms(&mut self) {
|
||||
let now = Local::now().naive_local();
|
||||
let cutoff_time = now - Duration::hours(1);
|
||||
|
||||
let expired_alarm_ids: Vec<String> = self.scheduled_alarms
|
||||
.iter()
|
||||
.filter(|(_, alarm)| {
|
||||
// Mark as expired if event ended more than 1 hour ago
|
||||
alarm.event_start < cutoff_time
|
||||
})
|
||||
.map(|(id, _)| id.clone())
|
||||
.collect();
|
||||
|
||||
for alarm_id in &expired_alarm_ids {
|
||||
if let Some(alarm) = self.scheduled_alarms.get_mut(alarm_id) {
|
||||
alarm.status = AlarmStatus::Expired;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove expired alarms from memory
|
||||
let had_expired = !expired_alarm_ids.is_empty();
|
||||
for alarm_id in expired_alarm_ids {
|
||||
self.scheduled_alarms.remove(&alarm_id);
|
||||
}
|
||||
|
||||
// Save to localStorage if any expired alarms were removed
|
||||
if had_expired {
|
||||
self.save_alarms_to_storage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Request notification permission
|
||||
pub async fn request_notification_permission(&self) -> Result<web_sys::NotificationPermission, wasm_bindgen::JsValue> {
|
||||
NotificationManager::request_permission().await
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Default for AlarmScheduler {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
use chrono::{DateTime, Datelike, Duration, NaiveDate, TimeZone, Utc, Weekday};
|
||||
use chrono::{DateTime, Datelike, Duration, NaiveDate, Utc, Weekday};
|
||||
use gloo_storage::{LocalStorage, Storage};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
@@ -6,8 +6,8 @@ use wasm_bindgen::JsCast;
|
||||
use wasm_bindgen_futures::JsFuture;
|
||||
use web_sys::{Request, RequestInit, RequestMode, Response};
|
||||
|
||||
// Import RFC 5545 compliant VEvent from shared library
|
||||
use calendar_models::VEvent;
|
||||
// Import RFC 5545 compliant VEvent and VAlarm from shared library
|
||||
use calendar_models::{VEvent, VAlarm};
|
||||
|
||||
// Create type alias for backward compatibility
|
||||
pub type CalendarEvent = VEvent;
|
||||
@@ -247,6 +247,8 @@ impl CalendarService {
|
||||
if resp.ok() {
|
||||
let events: Vec<CalendarEvent> = serde_json::from_str(&text_string)
|
||||
.map_err(|e| format!("JSON parsing failed: {}", e))?;
|
||||
|
||||
|
||||
Ok(events)
|
||||
} else {
|
||||
Err(format!(
|
||||
@@ -275,47 +277,66 @@ impl CalendarService {
|
||||
grouped
|
||||
}
|
||||
|
||||
/// Convert UTC events to local timezone for display
|
||||
fn convert_utc_to_local(mut event: VEvent) -> VEvent {
|
||||
// All-day events should not have timezone conversions applied
|
||||
if event.all_day {
|
||||
return event;
|
||||
}
|
||||
|
||||
// Check if event times are in UTC (legacy events from before timezone migration)
|
||||
let is_utc_event = event.dtstart_tzid.as_ref().map_or(true, |tz| tz == "UTC");
|
||||
|
||||
if is_utc_event {
|
||||
|
||||
// Get current timezone offset (convert from UTC to local)
|
||||
let date = js_sys::Date::new_0();
|
||||
let timezone_offset_minutes = date.get_timezone_offset() as i32;
|
||||
|
||||
// Convert start time from UTC to local
|
||||
// getTimezoneOffset() returns minutes UTC is ahead of local time
|
||||
// To convert UTC to local, we subtract the offset (add negative offset)
|
||||
let local_start = event.dtstart + chrono::Duration::minutes(-timezone_offset_minutes as i64);
|
||||
event.dtstart = local_start;
|
||||
event.dtstart_tzid = None; // Clear UTC timezone indicator
|
||||
|
||||
// Convert end time if present
|
||||
if let Some(end_utc) = event.dtend {
|
||||
let local_end = end_utc + chrono::Duration::minutes(-timezone_offset_minutes as i64);
|
||||
event.dtend = Some(local_end);
|
||||
event.dtend_tzid = None; // Clear UTC timezone indicator
|
||||
}
|
||||
|
||||
// Convert created/modified times if present
|
||||
if let Some(created_utc) = event.created {
|
||||
event.created = Some(created_utc + chrono::Duration::minutes(-timezone_offset_minutes as i64));
|
||||
event.created_tzid = None;
|
||||
}
|
||||
|
||||
if let Some(modified_utc) = event.last_modified {
|
||||
event.last_modified = Some(modified_utc + chrono::Duration::minutes(-timezone_offset_minutes as i64));
|
||||
event.last_modified_tzid = None;
|
||||
}
|
||||
}
|
||||
|
||||
event
|
||||
}
|
||||
|
||||
/// Expand recurring events using VEvent (RFC 5545 compliant)
|
||||
pub fn expand_recurring_events(events: Vec<VEvent>) -> Vec<VEvent> {
|
||||
let mut expanded_events = Vec::new();
|
||||
let today = chrono::Utc::now().date_naive();
|
||||
let today = chrono::Local::now().date_naive();
|
||||
let start_range = today - Duration::days(36500); // Show past 100 years (to catch any historical yearly events)
|
||||
let end_range = today + Duration::days(36500); // Show next 100 years
|
||||
|
||||
for event in events {
|
||||
// Convert UTC events to local time for proper display
|
||||
let event = Self::convert_utc_to_local(event);
|
||||
if let Some(ref rrule) = event.rrule {
|
||||
web_sys::console::log_1(
|
||||
&format!(
|
||||
"📅 Processing recurring VEvent '{}' with RRULE: {}",
|
||||
event.summary.as_deref().unwrap_or("Untitled"),
|
||||
rrule
|
||||
)
|
||||
.into(),
|
||||
);
|
||||
|
||||
// Log if event has exception dates
|
||||
if !event.exdate.is_empty() {
|
||||
web_sys::console::log_1(
|
||||
&format!(
|
||||
"📅 VEvent '{}' has {} exception dates: {:?}",
|
||||
event.summary.as_deref().unwrap_or("Untitled"),
|
||||
event.exdate.len(),
|
||||
event.exdate
|
||||
)
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
|
||||
// Generate occurrences for recurring events using VEvent
|
||||
let occurrences = Self::generate_occurrences(&event, rrule, start_range, end_range);
|
||||
web_sys::console::log_1(
|
||||
&format!(
|
||||
"📅 Generated {} occurrences for VEvent '{}'",
|
||||
occurrences.len(),
|
||||
event.summary.as_deref().unwrap_or("Untitled")
|
||||
)
|
||||
.into(),
|
||||
);
|
||||
expanded_events.extend(occurrences);
|
||||
} else {
|
||||
// Non-recurring event - add as-is
|
||||
@@ -337,7 +358,6 @@ 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(';')
|
||||
@@ -372,17 +392,18 @@ impl CalendarService {
|
||||
|
||||
// Get UNTIL date if specified
|
||||
let until_date = components.get("UNTIL").and_then(|until_str| {
|
||||
// Parse UNTIL date in YYYYMMDDTHHMMSSZ format
|
||||
// Parse UNTIL date in YYYYMMDDTHHMMSSZ format (treat as local time)
|
||||
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))
|
||||
Some(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))
|
||||
// Convert UTC to local (naive) time for consistency
|
||||
Some(dt.naive_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()))
|
||||
Some(date.and_hms_opt(23, 59, 59).unwrap())
|
||||
} else {
|
||||
web_sys::console::log_1(
|
||||
&format!("⚠️ Failed to parse UNTIL date: {}", until_str).into(),
|
||||
@@ -391,11 +412,10 @@ impl CalendarService {
|
||||
}
|
||||
});
|
||||
|
||||
if let Some(until) = until_date {
|
||||
web_sys::console::log_1(&format!("📅 RRULE has UNTIL: {}", until).into());
|
||||
if let Some(_until) = until_date {
|
||||
}
|
||||
|
||||
let start_date = base_event.dtstart.date_naive();
|
||||
let start_date = base_event.dtstart.date();
|
||||
let mut current_date = start_date;
|
||||
let mut occurrence_count = 0;
|
||||
|
||||
@@ -406,10 +426,6 @@ impl CalendarService {
|
||||
let current_datetime = base_event.dtstart
|
||||
+ 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;
|
||||
}
|
||||
}
|
||||
@@ -422,8 +438,8 @@ impl CalendarService {
|
||||
// Check if this occurrence is in the exception dates (EXDATE)
|
||||
let is_exception = base_event.exdate.iter().any(|exception_date| {
|
||||
// Compare dates ignoring sub-second precision
|
||||
let exception_naive = exception_date.naive_utc();
|
||||
let occurrence_naive = occurrence_datetime.naive_utc();
|
||||
let exception_naive = exception_date.and_utc();
|
||||
let occurrence_naive = occurrence_datetime.and_utc();
|
||||
|
||||
// Check if dates match (within a minute to handle minor time differences)
|
||||
let diff = occurrence_naive - exception_naive;
|
||||
@@ -555,7 +571,7 @@ impl CalendarService {
|
||||
interval: i32,
|
||||
start_range: NaiveDate,
|
||||
end_range: NaiveDate,
|
||||
until_date: Option<chrono::DateTime<chrono::Utc>>,
|
||||
until_date: Option<chrono::NaiveDateTime>,
|
||||
count: usize,
|
||||
) -> Vec<VEvent> {
|
||||
let mut occurrences = Vec::new();
|
||||
@@ -565,7 +581,7 @@ impl CalendarService {
|
||||
return occurrences;
|
||||
}
|
||||
|
||||
let start_date = base_event.dtstart.date_naive();
|
||||
let start_date = base_event.dtstart.date();
|
||||
|
||||
// Find the Monday of the week containing the start_date (reference week)
|
||||
let reference_week_start =
|
||||
@@ -606,13 +622,6 @@ impl CalendarService {
|
||||
let days_diff = occurrence_date.signed_duration_since(start_date).num_days();
|
||||
let occurrence_datetime = base_event.dtstart + Duration::days(days_diff);
|
||||
if occurrence_datetime > until {
|
||||
web_sys::console::log_1(
|
||||
&format!(
|
||||
"🛑 Stopping at {} due to UNTIL {}",
|
||||
occurrence_datetime, until
|
||||
)
|
||||
.into(),
|
||||
);
|
||||
return occurrences;
|
||||
}
|
||||
}
|
||||
@@ -623,8 +632,8 @@ impl CalendarService {
|
||||
|
||||
// Check if this occurrence is in the exception dates (EXDATE)
|
||||
let is_exception = base_event.exdate.iter().any(|exception_date| {
|
||||
let exception_naive = exception_date.naive_utc();
|
||||
let occurrence_naive = occurrence_datetime.naive_utc();
|
||||
let exception_naive = exception_date.and_utc();
|
||||
let occurrence_naive = occurrence_datetime.and_utc();
|
||||
let diff = occurrence_naive - exception_naive;
|
||||
let matches = diff.num_seconds().abs() < 60;
|
||||
|
||||
@@ -675,7 +684,7 @@ impl CalendarService {
|
||||
interval: i32,
|
||||
start_range: NaiveDate,
|
||||
end_range: NaiveDate,
|
||||
until_date: Option<chrono::DateTime<chrono::Utc>>,
|
||||
until_date: Option<chrono::NaiveDateTime>,
|
||||
count: usize,
|
||||
) -> Vec<VEvent> {
|
||||
let mut occurrences = Vec::new();
|
||||
@@ -691,7 +700,7 @@ impl CalendarService {
|
||||
return occurrences;
|
||||
}
|
||||
|
||||
let start_date = base_event.dtstart.date_naive();
|
||||
let start_date = base_event.dtstart.date();
|
||||
let mut current_month_start =
|
||||
NaiveDate::from_ymd_opt(start_date.year(), start_date.month(), 1).unwrap();
|
||||
let mut total_occurrences = 0;
|
||||
@@ -732,13 +741,6 @@ impl CalendarService {
|
||||
occurrence_date.signed_duration_since(start_date).num_days();
|
||||
let occurrence_datetime = base_event.dtstart + Duration::days(days_diff);
|
||||
if occurrence_datetime > until {
|
||||
web_sys::console::log_1(
|
||||
&format!(
|
||||
"🛑 Stopping at {} due to UNTIL {}",
|
||||
occurrence_datetime, until
|
||||
)
|
||||
.into(),
|
||||
);
|
||||
return occurrences;
|
||||
}
|
||||
}
|
||||
@@ -749,9 +751,7 @@ impl CalendarService {
|
||||
|
||||
// Check if this occurrence is in the exception dates (EXDATE)
|
||||
let is_exception = base_event.exdate.iter().any(|exception_date| {
|
||||
let exception_naive = exception_date.naive_utc();
|
||||
let occurrence_naive = occurrence_datetime.naive_utc();
|
||||
let diff = occurrence_naive - exception_naive;
|
||||
let diff = occurrence_datetime - *exception_date;
|
||||
diff.num_seconds().abs() < 60
|
||||
});
|
||||
|
||||
@@ -792,14 +792,14 @@ impl CalendarService {
|
||||
interval: i32,
|
||||
start_range: NaiveDate,
|
||||
end_range: NaiveDate,
|
||||
until_date: Option<chrono::DateTime<chrono::Utc>>,
|
||||
until_date: Option<chrono::NaiveDateTime>,
|
||||
count: usize,
|
||||
) -> Vec<VEvent> {
|
||||
let mut occurrences = Vec::new();
|
||||
|
||||
// Parse BYDAY for monthly (e.g., "1MO" = first Monday, "-1FR" = last Friday)
|
||||
if let Some((position, weekday)) = Self::parse_monthly_byday(byday) {
|
||||
let start_date = base_event.dtstart.date_naive();
|
||||
let start_date = base_event.dtstart.date();
|
||||
let mut current_month_start =
|
||||
NaiveDate::from_ymd_opt(start_date.year(), start_date.month(), 1).unwrap();
|
||||
let mut total_occurrences = 0;
|
||||
@@ -830,9 +830,7 @@ impl CalendarService {
|
||||
|
||||
// Check EXDATE
|
||||
let is_exception = base_event.exdate.iter().any(|exception_date| {
|
||||
let exception_naive = exception_date.naive_utc();
|
||||
let occurrence_naive = occurrence_datetime.naive_utc();
|
||||
let diff = occurrence_naive - exception_naive;
|
||||
let diff = occurrence_datetime - *exception_date;
|
||||
diff.num_seconds().abs() < 60
|
||||
});
|
||||
|
||||
@@ -871,7 +869,7 @@ impl CalendarService {
|
||||
interval: i32,
|
||||
start_range: NaiveDate,
|
||||
end_range: NaiveDate,
|
||||
until_date: Option<chrono::DateTime<chrono::Utc>>,
|
||||
until_date: Option<chrono::NaiveDateTime>,
|
||||
count: usize,
|
||||
) -> Vec<VEvent> {
|
||||
let mut occurrences = Vec::new();
|
||||
@@ -887,7 +885,7 @@ impl CalendarService {
|
||||
return occurrences;
|
||||
}
|
||||
|
||||
let start_date = base_event.dtstart.date_naive();
|
||||
let start_date = base_event.dtstart.date();
|
||||
let mut current_year = start_date.year();
|
||||
let mut total_occurrences = 0;
|
||||
|
||||
@@ -930,9 +928,7 @@ impl CalendarService {
|
||||
|
||||
// Check EXDATE
|
||||
let is_exception = base_event.exdate.iter().any(|exception_date| {
|
||||
let exception_naive = exception_date.naive_utc();
|
||||
let occurrence_naive = occurrence_datetime.naive_utc();
|
||||
let diff = occurrence_naive - exception_naive;
|
||||
let diff = occurrence_datetime - *exception_date;
|
||||
diff.num_seconds().abs() < 60
|
||||
});
|
||||
|
||||
@@ -1254,12 +1250,14 @@ impl CalendarService {
|
||||
organizer: String,
|
||||
attendees: String,
|
||||
categories: String,
|
||||
reminder: String,
|
||||
alarms: Vec<VAlarm>,
|
||||
recurrence: String,
|
||||
recurrence_days: Vec<bool>,
|
||||
recurrence_interval: u32,
|
||||
recurrence_count: Option<u32>,
|
||||
recurrence_until: Option<String>,
|
||||
calendar_path: Option<String>,
|
||||
timezone: String,
|
||||
) -> Result<(), String> {
|
||||
let window = web_sys::window().ok_or("No global window exists")?;
|
||||
|
||||
@@ -1287,13 +1285,14 @@ impl CalendarService {
|
||||
"organizer": organizer,
|
||||
"attendees": attendees,
|
||||
"categories": categories,
|
||||
"reminder": reminder,
|
||||
"alarms": alarms,
|
||||
"recurrence": recurrence,
|
||||
"recurrence_days": recurrence_days,
|
||||
"recurrence_interval": 1_u32, // Default interval
|
||||
"recurrence_interval": recurrence_interval,
|
||||
"recurrence_end_date": recurrence_until,
|
||||
"recurrence_count": recurrence_count,
|
||||
"calendar_path": calendar_path
|
||||
"calendar_path": calendar_path,
|
||||
"timezone": timezone
|
||||
});
|
||||
let url = format!("{}/calendar/events/series/create", self.base_url);
|
||||
(body, url)
|
||||
@@ -1314,10 +1313,11 @@ impl CalendarService {
|
||||
"organizer": organizer,
|
||||
"attendees": attendees,
|
||||
"categories": categories,
|
||||
"reminder": reminder,
|
||||
"alarms": alarms,
|
||||
"recurrence": recurrence,
|
||||
"recurrence_days": recurrence_days,
|
||||
"calendar_path": calendar_path
|
||||
"calendar_path": calendar_path,
|
||||
"timezone": timezone
|
||||
});
|
||||
let url = format!("{}/calendar/events/create", self.base_url);
|
||||
(body, url)
|
||||
@@ -1391,13 +1391,14 @@ impl CalendarService {
|
||||
organizer: String,
|
||||
attendees: String,
|
||||
categories: String,
|
||||
reminder: String,
|
||||
alarms: Vec<VAlarm>,
|
||||
recurrence: String,
|
||||
recurrence_days: Vec<bool>,
|
||||
recurrence_interval: u32,
|
||||
recurrence_count: Option<u32>,
|
||||
recurrence_until: Option<String>,
|
||||
calendar_path: Option<String>,
|
||||
exception_dates: Vec<DateTime<Utc>>,
|
||||
update_action: Option<String>,
|
||||
until_date: Option<DateTime<Utc>>,
|
||||
timezone: String,
|
||||
) -> Result<(), String> {
|
||||
// Forward to update_event_with_scope with default scope
|
||||
self.update_event_with_scope(
|
||||
@@ -1418,13 +1419,14 @@ impl CalendarService {
|
||||
organizer,
|
||||
attendees,
|
||||
categories,
|
||||
reminder,
|
||||
alarms,
|
||||
recurrence,
|
||||
recurrence_days,
|
||||
recurrence_interval,
|
||||
recurrence_count,
|
||||
recurrence_until,
|
||||
calendar_path,
|
||||
exception_dates,
|
||||
update_action,
|
||||
until_date,
|
||||
timezone,
|
||||
)
|
||||
.await
|
||||
}
|
||||
@@ -1448,13 +1450,14 @@ impl CalendarService {
|
||||
organizer: String,
|
||||
attendees: String,
|
||||
categories: String,
|
||||
reminder: String,
|
||||
alarms: Vec<VAlarm>,
|
||||
recurrence: String,
|
||||
recurrence_days: Vec<bool>,
|
||||
recurrence_interval: u32,
|
||||
recurrence_count: Option<u32>,
|
||||
recurrence_until: Option<String>,
|
||||
calendar_path: Option<String>,
|
||||
exception_dates: Vec<DateTime<Utc>>,
|
||||
update_action: Option<String>,
|
||||
until_date: Option<DateTime<Utc>>,
|
||||
timezone: String,
|
||||
) -> Result<(), String> {
|
||||
let window = web_sys::window().ok_or("No global window exists")?;
|
||||
|
||||
@@ -1479,14 +1482,14 @@ impl CalendarService {
|
||||
"organizer": organizer,
|
||||
"attendees": attendees,
|
||||
"categories": categories,
|
||||
"reminder": reminder,
|
||||
"alarms": alarms,
|
||||
"recurrence": recurrence,
|
||||
"recurrence_days": recurrence_days,
|
||||
"recurrence_interval": recurrence_interval,
|
||||
"recurrence_count": recurrence_count,
|
||||
"recurrence_end_date": recurrence_until,
|
||||
"calendar_path": calendar_path,
|
||||
"update_action": update_action,
|
||||
"occurrence_date": null,
|
||||
"exception_dates": exception_dates.iter().map(|dt| dt.to_rfc3339()).collect::<Vec<String>>(),
|
||||
"until_date": until_date.as_ref().map(|dt| dt.to_rfc3339())
|
||||
"timezone": timezone
|
||||
});
|
||||
let url = format!("{}/calendar/events/update", self.base_url);
|
||||
|
||||
@@ -1684,14 +1687,16 @@ impl CalendarService {
|
||||
organizer: String,
|
||||
attendees: String,
|
||||
categories: String,
|
||||
reminder: String,
|
||||
alarms: Vec<VAlarm>,
|
||||
recurrence: String,
|
||||
recurrence_days: Vec<bool>,
|
||||
recurrence_interval: u32,
|
||||
recurrence_count: Option<u32>,
|
||||
recurrence_until: Option<String>,
|
||||
calendar_path: Option<String>,
|
||||
update_scope: String,
|
||||
occurrence_date: Option<String>,
|
||||
timezone: String,
|
||||
) -> Result<(), String> {
|
||||
let window = web_sys::window().ok_or("No global window exists")?;
|
||||
|
||||
@@ -1715,15 +1720,16 @@ impl CalendarService {
|
||||
"organizer": organizer,
|
||||
"attendees": attendees,
|
||||
"categories": categories,
|
||||
"reminder": reminder,
|
||||
"alarms": alarms,
|
||||
"recurrence": recurrence,
|
||||
"recurrence_days": recurrence_days,
|
||||
"recurrence_interval": 1_u32, // Default interval - could be enhanced to be a parameter
|
||||
"recurrence_interval": recurrence_interval,
|
||||
"recurrence_end_date": recurrence_until,
|
||||
"recurrence_count": recurrence_count,
|
||||
"calendar_path": calendar_path,
|
||||
"update_scope": update_scope,
|
||||
"occurrence_date": occurrence_date
|
||||
"occurrence_date": occurrence_date,
|
||||
"timezone": timezone
|
||||
});
|
||||
|
||||
let url = format!("{}/calendar/events/series/update", self.base_url);
|
||||
@@ -2095,7 +2101,6 @@ impl CalendarService {
|
||||
#[derive(Deserialize)]
|
||||
struct ExternalCalendarEventsResponse {
|
||||
events: Vec<VEvent>,
|
||||
last_fetched: chrono::DateTime<chrono::Utc>,
|
||||
}
|
||||
|
||||
let response: ExternalCalendarEventsResponse = serde_wasm_bindgen::from_value(json)
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
pub mod calendar_service;
|
||||
pub mod preferences;
|
||||
pub mod notification_manager;
|
||||
pub mod alarm_scheduler;
|
||||
|
||||
pub use calendar_service::CalendarService;
|
||||
pub use notification_manager::{NotificationManager, AlarmNotification};
|
||||
pub use alarm_scheduler::AlarmScheduler;
|
||||
|
||||
189
frontend/src/services/notification_manager.rs
Normal file
189
frontend/src/services/notification_manager.rs
Normal file
@@ -0,0 +1,189 @@
|
||||
use web_sys::{window, Notification, NotificationOptions, NotificationPermission};
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen_futures::JsFuture;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct NotificationManager {
|
||||
// Track displayed notifications to prevent duplicates
|
||||
active_notifications: HashMap<String, Notification>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AlarmNotification {
|
||||
pub event_uid: String,
|
||||
pub event_summary: String,
|
||||
pub event_location: Option<String>,
|
||||
pub alarm_time: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
impl NotificationManager {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
active_notifications: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if the browser supports notifications
|
||||
pub fn is_supported() -> bool {
|
||||
// Check if the Notification constructor exists on the window
|
||||
if let Some(window) = window() {
|
||||
let has_notification = js_sys::Reflect::has(&window, &"Notification".into()).unwrap_or(false);
|
||||
|
||||
// Additional check - try to access Notification directly via JsValue
|
||||
let window_js: &wasm_bindgen::JsValue = window.as_ref();
|
||||
let direct_check = js_sys::Reflect::get(window_js, &"Notification".into()).unwrap_or(wasm_bindgen::JsValue::UNDEFINED);
|
||||
let has_direct = !direct_check.is_undefined();
|
||||
|
||||
// Use either check
|
||||
has_notification || has_direct
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Get current notification permission status
|
||||
pub fn get_permission() -> NotificationPermission {
|
||||
if Self::is_supported() {
|
||||
Notification::permission()
|
||||
} else {
|
||||
NotificationPermission::Denied
|
||||
}
|
||||
}
|
||||
|
||||
/// Force request notification permission (even if previously denied)
|
||||
pub async fn force_request_permission() -> Result<NotificationPermission, JsValue> {
|
||||
if !Self::is_supported() {
|
||||
return Ok(NotificationPermission::Denied);
|
||||
}
|
||||
|
||||
// Always request permission, regardless of current status
|
||||
let promise = Notification::request_permission()?;
|
||||
let js_value = JsFuture::from(promise).await?;
|
||||
|
||||
// Convert JS string back to NotificationPermission
|
||||
if let Some(permission_str) = js_value.as_string() {
|
||||
match permission_str.as_str() {
|
||||
"granted" => Ok(NotificationPermission::Granted),
|
||||
"denied" => Ok(NotificationPermission::Denied),
|
||||
_ => Ok(NotificationPermission::Default),
|
||||
}
|
||||
} else {
|
||||
Ok(NotificationPermission::Denied)
|
||||
}
|
||||
}
|
||||
|
||||
/// Request notification permission from the user
|
||||
pub async fn request_permission() -> Result<NotificationPermission, JsValue> {
|
||||
if !Self::is_supported() {
|
||||
return Ok(NotificationPermission::Denied);
|
||||
}
|
||||
|
||||
// Check current permission status
|
||||
let current_permission = Notification::permission();
|
||||
if current_permission != NotificationPermission::Default {
|
||||
return Ok(current_permission);
|
||||
}
|
||||
|
||||
// Request permission
|
||||
let promise = Notification::request_permission()?;
|
||||
let js_value = JsFuture::from(promise).await?;
|
||||
|
||||
// Convert JS string back to NotificationPermission
|
||||
if let Some(permission_str) = js_value.as_string() {
|
||||
match permission_str.as_str() {
|
||||
"granted" => Ok(NotificationPermission::Granted),
|
||||
"denied" => Ok(NotificationPermission::Denied),
|
||||
_ => Ok(NotificationPermission::Default),
|
||||
}
|
||||
} else {
|
||||
Ok(NotificationPermission::Denied)
|
||||
}
|
||||
}
|
||||
|
||||
/// Display a notification for an alarm
|
||||
pub fn show_alarm_notification(&mut self, alarm: AlarmNotification) -> Result<(), JsValue> {
|
||||
// Check permission
|
||||
if Self::get_permission() != NotificationPermission::Granted {
|
||||
return Ok(()); // Don't error, just skip
|
||||
}
|
||||
|
||||
// Check if notification already exists for this event
|
||||
if self.active_notifications.contains_key(&alarm.event_uid) {
|
||||
return Ok(()); // Already showing notification for this event
|
||||
}
|
||||
|
||||
// Create notification options
|
||||
let options = NotificationOptions::new();
|
||||
|
||||
// Set notification body with time and location
|
||||
let body = if let Some(location) = &alarm.event_location {
|
||||
format!("📅 {}\n📍 {}",
|
||||
alarm.alarm_time.format("%H:%M"),
|
||||
location
|
||||
)
|
||||
} else {
|
||||
format!("📅 {}", alarm.alarm_time.format("%H:%M"))
|
||||
};
|
||||
options.set_body(&body);
|
||||
|
||||
// Set icon
|
||||
options.set_icon("/favicon.ico");
|
||||
|
||||
// Set tag to prevent duplicates
|
||||
options.set_tag(&alarm.event_uid);
|
||||
|
||||
// Set require interaction to keep notification visible
|
||||
options.set_require_interaction(true);
|
||||
|
||||
// Create and show notification
|
||||
let notification = Notification::new_with_options(&alarm.event_summary, &options)?;
|
||||
|
||||
// Store reference to track active notifications
|
||||
self.active_notifications.insert(alarm.event_uid.clone(), notification.clone());
|
||||
|
||||
// Set up click handler to focus the calendar app
|
||||
let _event_uid = alarm.event_uid.clone();
|
||||
let onclick_closure = Closure::wrap(Box::new(move |_event: web_sys::Event| {
|
||||
// Focus the window when notification is clicked
|
||||
if let Some(window) = window() {
|
||||
let _ = window.focus();
|
||||
}
|
||||
|
||||
}) as Box<dyn FnMut(_)>);
|
||||
|
||||
notification.set_onclick(Some(onclick_closure.as_ref().unchecked_ref()));
|
||||
onclick_closure.forget(); // Keep closure alive
|
||||
|
||||
// Set up close handler to clean up tracking
|
||||
let event_uid_close = alarm.event_uid.clone();
|
||||
let mut active_notifications_close = self.active_notifications.clone();
|
||||
let onclose_closure = Closure::wrap(Box::new(move |_event: web_sys::Event| {
|
||||
active_notifications_close.remove(&event_uid_close);
|
||||
}) as Box<dyn FnMut(_)>);
|
||||
|
||||
notification.set_onclose(Some(onclose_closure.as_ref().unchecked_ref()));
|
||||
onclose_closure.forget(); // Keep closure alive
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Close notification for a specific event
|
||||
pub fn close_notification(&mut self, event_uid: &str) {
|
||||
if let Some(notification) = self.active_notifications.remove(event_uid) {
|
||||
notification.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Check if notification exists for event
|
||||
pub fn has_notification(&self, event_uid: &str) -> bool {
|
||||
self.active_notifications.contains_key(event_uid)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for NotificationManager {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
@@ -18,19 +18,10 @@
|
||||
--shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
|
||||
--shadow-md: 0 4px 6px rgba(0,0,0,0.1);
|
||||
--shadow-lg: 0 8px 25px rgba(0,0,0,0.15);
|
||||
--border-light: 1px solid #e9ecef;
|
||||
--border-medium: 1px solid #dee2e6;
|
||||
--transition-fast: 0.15s ease;
|
||||
--transition-normal: 0.2s ease;
|
||||
--transition-slow: 0.3s ease;
|
||||
|
||||
/* Common Glass/Glassmorphism Effects */
|
||||
--glass-bg: var(--glass-bg);
|
||||
--glass-bg-light: var(--glass-bg-light);
|
||||
--glass-bg-lighter: var(--glass-bg-lighter);
|
||||
--glass-border: 1px solid var(--glass-bg-light);
|
||||
--glass-border-light: 1px solid var(--glass-bg-lighter);
|
||||
|
||||
/* Standard Control Dimensions */
|
||||
--control-height: 40px;
|
||||
--control-padding: 0.875rem;
|
||||
@@ -39,12 +30,54 @@
|
||||
|
||||
/* Common Transition */
|
||||
--standard-transition: all 0.2s ease;
|
||||
|
||||
/* Default Light Theme Colors */
|
||||
--background-primary: #f8f9fa;
|
||||
--background-secondary: #ffffff;
|
||||
--background-tertiary: #f1f3f4;
|
||||
--text-primary: #333333;
|
||||
--text-secondary: #6c757d;
|
||||
--text-inverse: #ffffff;
|
||||
--border-primary: #e9ecef;
|
||||
--border-secondary: #dee2e6;
|
||||
--border-light: #f8f9fa;
|
||||
--error-color: #dc3545;
|
||||
--success-color: #28a745;
|
||||
--warning-color: #ffc107;
|
||||
--info-color: #17a2b8;
|
||||
|
||||
/* Modal Colors */
|
||||
--modal-background: #ffffff;
|
||||
--modal-text: #333333;
|
||||
--modal-header-background: #ffffff;
|
||||
--modal-header-border: #e5e7eb;
|
||||
|
||||
/* Button Colors */
|
||||
--button-primary-bg: #667eea;
|
||||
--button-primary-text: #ffffff;
|
||||
--button-secondary-bg: #6c757d;
|
||||
--button-secondary-text: #ffffff;
|
||||
--button-danger-bg: #dc3545;
|
||||
--button-danger-text: #ffffff;
|
||||
|
||||
/* Input Colors */
|
||||
--input-background: #ffffff;
|
||||
--input-border: #ced4da;
|
||||
--input-border-focus: #80bdff;
|
||||
--input-text: #495057;
|
||||
|
||||
/* Glass/Glassmorphism Effects */
|
||||
--glass-bg: rgba(255, 255, 255, 0.1);
|
||||
--glass-bg-light: rgba(255, 255, 255, 0.2);
|
||||
--glass-bg-lighter: rgba(255, 255, 255, 0.3);
|
||||
--glass-border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
--glass-border-light: 1px solid rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background-color: #f8f9fa;
|
||||
color: #333;
|
||||
background-color: var(--background-primary);
|
||||
color: var(--text-primary);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
@@ -115,6 +148,44 @@ input, select, textarea, button {
|
||||
[data-theme="dark"] {
|
||||
--primary-color: #374151;
|
||||
--primary-gradient: linear-gradient(135deg, #374151 0%, #1f2937 100%);
|
||||
|
||||
/* Dark Theme Overrides */
|
||||
--background-primary: #111827;
|
||||
--background-secondary: #1f2937;
|
||||
--background-tertiary: #374151;
|
||||
--text-primary: #f9fafb;
|
||||
--text-secondary: #d1d5db;
|
||||
--text-inverse: #111827;
|
||||
--border-primary: #374151;
|
||||
--border-secondary: #4b5563;
|
||||
--border-light: #6b7280;
|
||||
|
||||
/* Modal Colors - Dark */
|
||||
--modal-background: #1f2937;
|
||||
--modal-text: #f3f4f6;
|
||||
--modal-header-background: #1f2937;
|
||||
--modal-header-border: #374151;
|
||||
|
||||
/* Button Colors - Dark */
|
||||
--button-primary-bg: #4f46e5;
|
||||
--button-primary-text: #ffffff;
|
||||
--button-secondary-bg: #4b5563;
|
||||
--button-secondary-text: #ffffff;
|
||||
--button-danger-bg: #dc2626;
|
||||
--button-danger-text: #ffffff;
|
||||
|
||||
/* Input Colors - Dark */
|
||||
--input-background: #374151;
|
||||
--input-border: #4b5563;
|
||||
--input-border-focus: #6366f1;
|
||||
--input-text: #f9fafb;
|
||||
|
||||
/* Glass Effects - Dark */
|
||||
--glass-bg: rgba(0, 0, 0, 0.2);
|
||||
--glass-bg-light: rgba(0, 0, 0, 0.3);
|
||||
--glass-bg-lighter: rgba(0, 0, 0, 0.4);
|
||||
--glass-border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
--glass-border-light: 1px solid rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
[data-theme="rose"] {
|
||||
@@ -133,8 +204,8 @@ input, select, textarea, button {
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background-color: #f8f9fa;
|
||||
color: #333;
|
||||
background-color: var(--background-primary);
|
||||
color: var(--text-primary);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
@@ -381,7 +452,7 @@ body {
|
||||
border-radius: var(--border-radius-medium);
|
||||
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
.login-form h2, .register-form h2 {
|
||||
@@ -421,30 +492,83 @@ body {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.remember-checkbox {
|
||||
.input-with-checkbox {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
margin-top: 0.375rem;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.input-with-checkbox input[type="text"],
|
||||
.input-with-checkbox input[type="password"] {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.remember-checkbox {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.1rem;
|
||||
opacity: 0.7;
|
||||
white-space: nowrap;
|
||||
min-width: 80px;
|
||||
}
|
||||
|
||||
.remember-checkbox input[type="checkbox"] {
|
||||
width: auto;
|
||||
margin: 0;
|
||||
cursor: pointer;
|
||||
transform: scale(0.85);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.remember-checkbox label {
|
||||
margin: 0;
|
||||
font-size: 0.75rem;
|
||||
font-size: 0.55rem;
|
||||
color: #888;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.password-input-container {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.password-input-container input {
|
||||
padding-right: 3rem !important;
|
||||
}
|
||||
|
||||
.password-toggle-btn {
|
||||
position: absolute;
|
||||
right: 0.75rem;
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: #888;
|
||||
cursor: pointer;
|
||||
padding: 0.25rem;
|
||||
font-size: 1rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: color 0.2s ease;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.password-toggle-btn:hover {
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.password-toggle-btn:focus {
|
||||
outline: none;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.login-button, .register-button {
|
||||
width: 100%;
|
||||
padding: var(--control-padding);
|
||||
@@ -637,6 +761,25 @@ body {
|
||||
background: rgba(255,255,255,0.3);
|
||||
}
|
||||
|
||||
.print-button {
|
||||
background: rgba(255,255,255,0.2);
|
||||
border: none;
|
||||
color: white;
|
||||
font-size: 1rem;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: background 0.2s ease;
|
||||
}
|
||||
|
||||
.print-button:hover {
|
||||
background: rgba(255,255,255,0.3);
|
||||
}
|
||||
|
||||
.calendar-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, 1fr);
|
||||
@@ -886,8 +1029,6 @@ body {
|
||||
font-weight: 500;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* Disable pointer events on existing events when creating a new event */
|
||||
@@ -1007,11 +1148,41 @@ body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center; /* Center the content horizontally */
|
||||
text-align: center; /* Center text within elements */
|
||||
pointer-events: auto;
|
||||
z-index: 5;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.week-event .event-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center; /* Center the title and icon */
|
||||
gap: 4px;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.week-event .event-title {
|
||||
flex: 1;
|
||||
min-width: 0 !important;
|
||||
max-width: calc(100% - 16px) !important; /* This was needed for ellipsis */
|
||||
white-space: nowrap !important;
|
||||
overflow: hidden !important;
|
||||
text-overflow: ellipsis !important;
|
||||
font-weight: 600;
|
||||
margin-bottom: 2px;
|
||||
display: block !important; /* This was also needed */
|
||||
text-align: center; /* Center the text within the title element */
|
||||
}
|
||||
|
||||
.week-event .event-reminder-icon {
|
||||
font-size: 0.6rem;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* Left-click drag handles */
|
||||
.resize-handle {
|
||||
position: absolute;
|
||||
@@ -1052,13 +1223,7 @@ body {
|
||||
}
|
||||
|
||||
|
||||
.week-event .event-title {
|
||||
font-weight: 600;
|
||||
margin-bottom: 2px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
/* Moved to .week-event .event-header .event-title for better specificity */
|
||||
|
||||
.week-event .event-time {
|
||||
font-size: 0.65rem;
|
||||
@@ -1427,9 +1592,6 @@ body {
|
||||
border-radius: 3px;
|
||||
font-size: 0.7rem;
|
||||
line-height: 1.2;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
transition: var(--standard-transition);
|
||||
border: 1px solid rgba(255,255,255,0.2);
|
||||
@@ -1437,6 +1599,10 @@ body {
|
||||
font-weight: 500;
|
||||
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.event-box:hover {
|
||||
@@ -1736,7 +1902,7 @@ body {
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 0.75rem;
|
||||
margin-bottom: 0.4rem;
|
||||
color: #374151;
|
||||
font-weight: 600;
|
||||
font-size: 0.95rem;
|
||||
@@ -3684,10 +3850,37 @@ body {
|
||||
}
|
||||
|
||||
.external-calendar-info input[type="checkbox"] {
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
accent-color: rgba(255, 255, 255, 0.8);
|
||||
background: transparent;
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.external-calendar-info input[type="checkbox"]:hover {
|
||||
border-color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
.external-calendar-info input[type="checkbox"]:checked {
|
||||
border-color: rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
|
||||
.external-calendar-info input[type="checkbox"]:checked::after {
|
||||
content: "✓";
|
||||
position: absolute;
|
||||
top: 45%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.external-calendar-color {
|
||||
@@ -3762,10 +3955,37 @@ body {
|
||||
}
|
||||
|
||||
.calendar-info input[type="checkbox"] {
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
accent-color: rgba(255, 255, 255, 0.8);
|
||||
background: transparent;
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.calendar-info input[type="checkbox"]:hover {
|
||||
border-color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
.calendar-info input[type="checkbox"]:checked {
|
||||
border-color: rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
|
||||
.calendar-info input[type="checkbox"]:checked::after {
|
||||
content: "✓";
|
||||
position: absolute;
|
||||
top: 45%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
/* Create External Calendar Button */
|
||||
@@ -3989,3 +4209,480 @@ body {
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
/* Color Editor Modal */
|
||||
.color-editor-backdrop {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
backdrop-filter: blur(4px);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.color-editor-modal {
|
||||
background: var(--modal-background);
|
||||
color: var(--modal-text);
|
||||
border-radius: var(--border-radius-medium);
|
||||
box-shadow: var(--shadow-lg);
|
||||
max-width: 400px;
|
||||
width: 95%;
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
position: relative;
|
||||
animation: modalAppear 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.color-editor-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: var(--spacing-md);
|
||||
border-bottom: 1px solid var(--modal-header-border);
|
||||
background: var(--modal-header-background);
|
||||
border-radius: var(--border-radius-medium) var(--border-radius-medium) 0 0;
|
||||
}
|
||||
|
||||
.color-editor-header h3 {
|
||||
margin: 0;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.close-button {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1.5rem;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
padding: var(--spacing-xs);
|
||||
line-height: 1;
|
||||
border-radius: var(--border-radius-small);
|
||||
transition: var(--transition-fast);
|
||||
}
|
||||
|
||||
.close-button:hover {
|
||||
background: var(--background-tertiary);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.color-editor-content {
|
||||
padding: var(--spacing-md);
|
||||
}
|
||||
|
||||
.current-color-preview {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-md);
|
||||
margin-bottom: var(--spacing-md);
|
||||
padding: var(--spacing-md);
|
||||
background: var(--background-tertiary);
|
||||
border-radius: var(--border-radius-medium);
|
||||
}
|
||||
|
||||
.color-preview-large {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: var(--border-radius-medium);
|
||||
border: 2px solid var(--border-secondary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.color-preview-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-sm);
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.color-value {
|
||||
font-family: monospace;
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-secondary);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.reset-this-color-button {
|
||||
background: var(--background-secondary);
|
||||
color: var(--text-secondary);
|
||||
border: 1px solid var(--border-secondary);
|
||||
border-radius: var(--border-radius-small);
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
cursor: pointer;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 500;
|
||||
transition: var(--transition-fast);
|
||||
align-self: flex-start;
|
||||
}
|
||||
|
||||
.reset-this-color-button:hover {
|
||||
background: var(--background-tertiary);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--text-primary);
|
||||
}
|
||||
|
||||
.color-input-section {
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.color-input-section label {
|
||||
display: block;
|
||||
margin-bottom: var(--spacing-sm);
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.color-input-group {
|
||||
display: flex;
|
||||
gap: var(--spacing-sm);
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.color-input-group input[type="color"] {
|
||||
width: 48px;
|
||||
height: 40px;
|
||||
border: 1px solid var(--border-secondary);
|
||||
border-radius: var(--border-radius-small);
|
||||
cursor: pointer;
|
||||
background: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.color-text-input {
|
||||
flex: 1;
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
border: 1px solid var(--border-secondary);
|
||||
border-radius: var(--border-radius-small);
|
||||
font-family: monospace;
|
||||
font-size: 0.9rem;
|
||||
background: var(--background-secondary);
|
||||
color: var(--text-primary);
|
||||
transition: var(--transition-fast);
|
||||
}
|
||||
|
||||
.color-text-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--info-color);
|
||||
box-shadow: 0 0 0 2px rgba(23, 162, 184, 0.2);
|
||||
}
|
||||
|
||||
.suggested-colors-section label {
|
||||
display: block;
|
||||
margin-bottom: var(--spacing-sm);
|
||||
font-weight: 500;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.suggested-colors-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(8, 1fr);
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.suggested-color {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: var(--border-radius-small);
|
||||
border: 2px solid var(--border-secondary);
|
||||
cursor: pointer;
|
||||
transition: var(--transition-fast);
|
||||
}
|
||||
|
||||
.suggested-color:hover {
|
||||
transform: scale(1.1);
|
||||
border-color: var(--text-primary);
|
||||
}
|
||||
|
||||
.color-editor-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: var(--spacing-sm);
|
||||
padding: var(--spacing-md);
|
||||
border-top: 1px solid var(--modal-header-border);
|
||||
background: var(--background-tertiary);
|
||||
border-radius: 0 0 var(--border-radius-medium) var(--border-radius-medium);
|
||||
}
|
||||
|
||||
.cancel-button, .reset-all-button, .save-button {
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
border: 1px solid var(--border-secondary);
|
||||
border-radius: var(--border-radius-small);
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
transition: var(--transition-fast);
|
||||
}
|
||||
|
||||
.cancel-button {
|
||||
background: var(--background-secondary);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.cancel-button:hover {
|
||||
background: var(--background-tertiary);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.reset-all-button {
|
||||
background: var(--warning-color);
|
||||
color: white;
|
||||
border-color: var(--warning-color);
|
||||
margin-left: auto;
|
||||
margin-right: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.reset-all-button:hover {
|
||||
background: #e0a800;
|
||||
border-color: #e0a800;
|
||||
}
|
||||
|
||||
.save-button {
|
||||
background: var(--info-color);
|
||||
color: white;
|
||||
border-color: var(--info-color);
|
||||
}
|
||||
|
||||
.save-button:hover {
|
||||
background: #138496;
|
||||
border-color: #138496;
|
||||
}
|
||||
|
||||
/* Alarm List Component */
|
||||
.alarm-list {
|
||||
margin-bottom: var(--spacing-lg);
|
||||
}
|
||||
|
||||
.alarm-list h6 {
|
||||
margin: 0 0 var(--spacing-sm) 0;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.alarm-list-empty {
|
||||
text-align: center;
|
||||
padding: var(--spacing-lg);
|
||||
background: var(--background-tertiary);
|
||||
border: 1px dashed var(--border-secondary);
|
||||
border-radius: var(--border-radius-medium);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.alarm-list-empty p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.alarm-list-empty .text-small {
|
||||
font-size: 0.8rem;
|
||||
margin-top: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.alarm-items {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.alarm-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
background: var(--background-secondary);
|
||||
border: 1px solid var(--border-secondary);
|
||||
border-radius: var(--border-radius-small);
|
||||
transition: var(--transition-fast);
|
||||
}
|
||||
|
||||
.alarm-item:hover {
|
||||
background: var(--background-tertiary);
|
||||
border-color: var(--border-primary);
|
||||
}
|
||||
|
||||
.alarm-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.alarm-icon {
|
||||
font-size: 1.1rem;
|
||||
min-width: 24px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.alarm-description {
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-primary);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.alarm-actions {
|
||||
display: flex;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.alarm-action-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
padding: var(--spacing-xs);
|
||||
border-radius: var(--border-radius-small);
|
||||
cursor: pointer;
|
||||
color: var(--text-secondary);
|
||||
transition: var(--transition-fast);
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.alarm-action-btn:hover {
|
||||
background: var(--background-tertiary);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.alarm-action-btn.edit-btn:hover {
|
||||
background: var(--info-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.alarm-action-btn.delete-btn:hover {
|
||||
background: var(--error-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.alarm-action-btn i {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
/* Alarm Management Header */
|
||||
.alarm-management-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.alarm-management-header h5 {
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.add-alarm-button {
|
||||
background: var(--primary-color);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
border-radius: var(--border-radius-small);
|
||||
font-size: 0.85rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: var(--transition-fast);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.add-alarm-button:hover {
|
||||
background: #1d4ed8;
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 2px 8px rgba(29, 78, 216, 0.25);
|
||||
}
|
||||
|
||||
.add-alarm-button i {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
/* Alarm Types Info */
|
||||
.alarm-types-info {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: var(--spacing-sm);
|
||||
margin: var(--spacing-md) 0;
|
||||
}
|
||||
|
||||
.alarm-type-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
padding: var(--spacing-sm);
|
||||
background: var(--background-secondary);
|
||||
border: 1px solid var(--border-secondary);
|
||||
border-radius: var(--border-radius-small);
|
||||
transition: var(--transition-fast);
|
||||
}
|
||||
|
||||
.alarm-type-info:hover {
|
||||
background: var(--background-tertiary);
|
||||
border-color: var(--border-primary);
|
||||
}
|
||||
|
||||
.alarm-type-info .alarm-icon {
|
||||
font-size: 1.2rem;
|
||||
min-width: 24px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.alarm-type-info div {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.alarm-type-info strong {
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.alarm-type-info span:not(.alarm-icon) {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
/* Event Reminder Icon */
|
||||
.event-reminder-icon {
|
||||
font-size: 0.7rem;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
margin-left: auto;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.event-box .event-title {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.event-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.event-content .event-title {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.event-content .event-reminder-icon {
|
||||
margin-left: auto;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,51 +0,0 @@
|
||||
/* Base Styles - Always Loaded */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background-color: #f8f9fa;
|
||||
color: #333;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.app {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.login-layout {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Base Layout */
|
||||
.main-content {
|
||||
flex: 1;
|
||||
margin-left: 280px;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
/* Basic Form Elements */
|
||||
input, select, textarea, button {
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
/* Utility Classes */
|
||||
.loading {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #dc3545;
|
||||
}
|
||||
|
||||
.success {
|
||||
color: #28a745;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user