Calendar/wwwroot/js/datasources/DateColumnDataSource.js

94 lines
2.7 KiB
JavaScript
Raw Normal View History

2026-02-03 00:02:25 +01:00
/**
* DateColumnDataSource - Provides date-based columns
*
* Calculates which dates to display based on:
* - Current date
* - Current view (day/week/month)
* - Workweek settings
*/
export class DateColumnDataSource {
constructor(dateService, config, currentDate, currentView) {
this.dateService = dateService;
this.config = config;
this.currentDate = currentDate;
this.currentView = currentView;
}
/**
* Get columns (dates) to display
*/
getColumns() {
switch (this.currentView) {
case 'week':
return this.getWeekDates();
case 'month':
return this.getMonthDates();
case 'day':
return [this.currentDate];
default:
return this.getWeekDates();
}
}
/**
* Get type of datasource
*/
getType() {
return 'date';
}
/**
* Update current date
*/
setCurrentDate(date) {
this.currentDate = date;
}
/**
* Update current view
*/
setCurrentView(view) {
this.currentView = view;
}
/**
* Get dates for week view based on workweek settings
*/
getWeekDates() {
const weekStart = this.getISOWeekStart(this.currentDate);
const workWeekSettings = this.config.getWorkWeekSettings();
return this.dateService.getWorkWeekDates(weekStart, workWeekSettings.workDays);
}
/**
* Get all dates in current month
*/
getMonthDates() {
const dates = [];
const monthStart = this.getMonthStart(this.currentDate);
const monthEnd = this.getMonthEnd(this.currentDate);
const totalDays = Math.ceil((monthEnd.getTime() - monthStart.getTime()) / (1000 * 60 * 60 * 24)) + 1;
for (let i = 0; i < totalDays; i++) {
dates.push(this.dateService.addDays(monthStart, i));
}
return dates;
}
/**
* Get ISO week start (Monday)
*/
getISOWeekStart(date) {
const weekBounds = this.dateService.getWeekBounds(date);
return this.dateService.startOfDay(weekBounds.start);
}
/**
* Get month start
*/
getMonthStart(date) {
const year = date.getFullYear();
const month = date.getMonth();
return this.dateService.startOfDay(new Date(year, month, 1));
}
/**
* Get month end
*/
getMonthEnd(date) {
const nextMonth = this.dateService.addMonths(date, 1);
const firstOfNextMonth = this.getMonthStart(nextMonth);
return this.dateService.endOfDay(this.dateService.addDays(firstOfNextMonth, -1));
}
}
//# sourceMappingURL=DateColumnDataSource.js.map