Adds work week configuration feature

Implements configurable work week presets, allowing users to customize the days displayed in the calendar.

This includes:
- Defining work week settings (work days, day names, total days).
- Providing predefined work week presets (standard, compressed, weekend, full week).
- Adding UI elements to switch between presets.
- Updating grid and header rendering logic to reflect the selected work week.
- Emitting events when the work week changes, triggering necessary UI updates and data re-renders.

This provides a more flexible and personalized calendar experience.
This commit is contained in:
Janus Knudsen 2025-08-18 22:27:17 +02:00
parent 26f0cb8aaa
commit d017d48bd6
11 changed files with 283 additions and 34 deletions

View file

@ -27,18 +27,19 @@ export class DateHeaderRenderer implements HeaderRenderer {
render(calendarHeader: HTMLElement, context: HeaderRenderContext): void {
const { currentWeek, config, allDayEvents = [] } = context;
const dates = this.getWeekDates(currentWeek);
const dates = this.getWeekDates(currentWeek, config);
const weekDays = config.get('weekDays');
const daysToShow = dates.slice(0, weekDays);
daysToShow.forEach((date) => {
const workWeekSettings = config.getWorkWeekSettings();
daysToShow.forEach((date, index) => {
const header = document.createElement('swp-day-header');
if (this.isToday(date)) {
(header as any).dataset.today = 'true';
}
header.innerHTML = `
<swp-day-name>${this.getDayName(date)}</swp-day-name>
<swp-day-name>${workWeekSettings.dayNames[index]}</swp-day-name>
<swp-day-date>${date.getDate()}</swp-day-date>
`;
(header as any).dataset.date = this.formatDate(date);
@ -53,7 +54,7 @@ export class DateHeaderRenderer implements HeaderRenderer {
private renderAllDayEvents(calendarHeader: HTMLElement, context: HeaderRenderContext): void {
const { currentWeek, config, allDayEvents = [] } = context;
const dates = this.getWeekDates(currentWeek);
const dates = this.getWeekDates(currentWeek, config);
const weekDays = config.get('weekDays');
const daysToShow = dates.slice(0, weekDays);
@ -101,13 +102,20 @@ export class DateHeaderRenderer implements HeaderRenderer {
});
}
private getWeekDates(weekStart: Date): Date[] {
private getWeekDates(weekStart: Date, config: CalendarConfig): Date[] {
const dates: Date[] = [];
for (let i = 0; i < 7; i++) {
const workWeekSettings = config.getWorkWeekSettings();
// Calculate dates based on actual work days (e.g., [1,2,3,4] for Mon-Thu)
workWeekSettings.workDays.forEach(dayOfWeek => {
const date = new Date(weekStart);
date.setDate(weekStart.getDate() + i);
// Set to the start of the week (Sunday = 0)
date.setDate(weekStart.getDate() - weekStart.getDay());
// Add the specific day of week
date.setDate(date.getDate() + dayOfWeek);
dates.push(date);
}
});
return dates;
}
@ -120,10 +128,6 @@ export class DateHeaderRenderer implements HeaderRenderer {
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
}
private getDayName(date: Date): string {
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
return days[date.getDay()];
}
}
/**