diff --git a/agenda/calendar.py b/agenda/calendar.py index bc00d75..2dd7978 100644 --- a/agenda/calendar.py +++ b/agenda/calendar.py @@ -2,78 +2,106 @@ import typing from datetime import timedelta +import uuid from .event import Event -event_type_color_map = { - "bank_holiday": "success-subtle", - "conference": "primary-subtle", - "us_holiday": "secondary-subtle", - "birthday": "info-subtle", - "waste_schedule": "danger-subtle", +# A map to associate event types with a specific calendar ID +event_type_calendar_map = { + "bank_holiday": "uk_holidays", + "conference": "conferences", + "us_holiday": "us_holidays", + "birthday": "birthdays", + "waste_schedule": "home", + "accommodation": "travel", + "market": "markets", } -colors = { - "primary-subtle": "#cfe2ff", - "secondary-subtle": "#e2e3e5", - "success-subtle": "#d1e7dd", - "info-subtle": "#cff4fc", - "warning-subtle": "#fff3cd", - "danger-subtle": "#f8d7da", -} +# Define the calendars (categories) for TOAST UI +# These will be passed to the frontend to configure colors and names +toastui_calendars = [ + {"id": "default", "name": "General", "backgroundColor": "#00a9ff"}, + {"id": "uk_holidays", "name": "UK Bank Holiday", "backgroundColor": "#28a745"}, + {"id": "us_holidays", "name": "US Holiday", "backgroundColor": "#6c757d"}, + {"id": "conferences", "name": "Conference", "backgroundColor": "#007bff"}, + {"id": "birthdays", "name": "Birthday", "backgroundColor": "#17a2b8"}, + {"id": "home", "name": "Home", "backgroundColor": "#dc3545"}, + {"id": "travel", "name": "Travel", "backgroundColor": "#ffc107", "color": "#000"}, + {"id": "markets", "name": "Markets", "backgroundColor": "#e2e3e5", "color": "#000"}, +] -def build_events(events: list[Event]) -> list[dict[str, typing.Any]]: - """Build list of events for FullCalendar.""" +def build_toastui_events(events: list[Event]) -> list[dict[str, typing.Any]]: + """Build a list of event objects for TOAST UI Calendar.""" items: list[dict[str, typing.Any]] = [] - one_day = timedelta(days=1) for e in events: if e.name == "today": continue + + # Determine the calendar ID for the event, defaulting if not mapped + calendar_id = event_type_calendar_map.get(e.name, "default") + + # Handle special case for 'accommodation' if e.name == "accommodation": assert e.title and e.end_date - item = { - "allDay": True, - "title": e.title_with_emoji, - "start": e.as_date.isoformat(), - "end": (e.end_as_date + one_day).isoformat(), - "url": e.url, - } - items.append(item) - - item = { - "allDay": False, - "title": "check-in: " + e.title, - "start": e.date.isoformat(), - "url": e.url, - } - items.append(item) - item = { - "allDay": False, - "title": "checkout: " + e.title, - "start": e.end_date.isoformat(), - "url": e.url, - } - items.append(item) - + # All-day event for the duration of the stay + items.append( + { + "id": str(uuid.uuid4()), + "calendarId": calendar_id, + "title": e.title_with_emoji, + "start": e.as_date.isoformat(), + "end": (e.end_as_date + one_day).isoformat(), + "isAllday": True, + "raw": {"url": e.url}, + } + ) + # Timed event for check-in + items.append( + { + "id": str(uuid.uuid4()), + "calendarId": calendar_id, + "title": f"Check-in: {e.title}", + "start": e.date.isoformat(), + "end": (e.date + timedelta(hours=1)).isoformat(), + "isAllday": False, + "raw": {"url": e.url}, + } + ) + # Timed event for check-out + items.append( + { + "id": str(uuid.uuid4()), + "calendarId": calendar_id, + "title": f"Checkout: {e.title}", + "start": e.end_date.isoformat(), + "end": (e.end_date + timedelta(hours=1)).isoformat(), + "isAllday": False, + "raw": {"url": e.url}, + } + ) continue + # Handle all other events + start_iso = e.date.isoformat() if e.has_time: - end = e.end_date or e.date + timedelta(minutes=30) + end_iso = (e.end_date or e.date + timedelta(minutes=30)).isoformat() else: - end = (e.end_as_date if e.end_date else e.as_date) + one_day + end_date = (e.end_as_date if e.end_date else e.as_date) + one_day + end_iso = end_date.isoformat() + item = { - "allDay": not e.has_time, + "id": str(uuid.uuid4()), + "calendarId": calendar_id, "title": e.title_with_emoji, - "start": e.date.isoformat(), - "end": end.isoformat(), + "start": start_iso, + "end": end_iso, + "isAllday": not e.has_time, } - if e.name in event_type_color_map: - item["color"] = colors[event_type_color_map[e.name]] - item["textColor"] = "black" if e.url: - item["url"] = e.url + item["raw"] = {"url": e.url} items.append(item) + return items diff --git a/templates/calendar.html b/templates/calendar.html index 31067ce..fb6013c 100644 --- a/templates/calendar.html +++ b/templates/calendar.html @@ -7,69 +7,18 @@ - - - - - + + + {% set event_labels = { @@ -91,16 +40,6 @@ } %} -{%set class_map = { - "bank_holiday": "bg-success-subtle", - "conference": "bg-primary-subtle", - "us_holiday": "bg-secondary-subtle", - "birthday": "bg-info-subtle", - "waste_schedule": "bg-danger-subtle", -} %} - - - {% from "navbar.html" import navbar with context %}
{{ navbar() }} @@ -108,7 +47,7 @@ - + +