#865: CalendarView.kt

projectforge-business/src/main/kotlin/org/projectforge/business/calendar/CalendarView.kt Type: Kotlin enum class
Purpose: Maps ProjectForge calendar view modes to FullCalendar view keys
Source path: projectforge-business/src/main/kotlin/org/projectforge/business/calendar/CalendarView.kt 54 lines · 19 code · 25 comments · 10 blank

CalendarView is an enum that bridges ProjectForge's calendar view concepts with the FullCalendar JavaScript library's view name conventions. Each enum value carries a key property that is the string used to request a specific view from FullCalendar. The companion object provides a from() factory that resolves both enum names and FullCalendar keys, with a fallback to MONTH.

Enum Values

Enum ValueFullCalendar KeyDescription
MONTHdayGridMonthStandard month grid view.
WORK_MONTHdayGridWorkingMonthMonth grid showing only working days (custom extension).
WEEKtimeGridWeekFull week with time grid (7 days, hourly slots).
WORK_WEEKtimeGridWorkingWeekWorking week — typically Monday–Friday — with time grid.
DAYtimeGridDaySingle day with time grid (hourly slots).
WEEK_LISTdayGridWeekWeek displayed as a day-grid (no time slots), useful as a compact list.
AGENDAlistWeekList/agenda view for a single week.
MONTH_AGENDAlistMonthList/agenda view spanning a full month.

Companion Object

from(name: String?): CalendarView

Looks up a CalendarView by either its enum name (e.g., "WEEK") or its FullCalendar key (e.g., "timeGridWeek"). If the input is null or not found, returns MONTH as the safe default. This makes it resilient to mismatches between stored view preferences and current enum definitions.

Git History

Design Rationale

The dual-keyed from() lookup (accepting both enum names and FullCalendar keys) provides flexibility in both serialization and migration. When stored preferences use the FullCalendar key (as they might after a library upgrade), the enum still resolves correctly. The default fallback to MONTH prevents crashes from unrecognized values, ensuring the calendar always renders something. The key property on each enum value is the single source of truth for how FullCalendar views are addressed, centralizing what would otherwise be string constants scattered across frontend and backend code.