108 lines
3.9 KiB
JavaScript
108 lines
3.9 KiB
JavaScript
|
|
// Work hours management for per-column scheduling
|
||
|
|
/**
|
||
|
|
* Manages work hours scheduling with weekly defaults and date-specific overrides
|
||
|
|
*/
|
||
|
|
export class WorkHoursManager {
|
||
|
|
constructor(dateService, config, positionUtils) {
|
||
|
|
this.dateService = dateService;
|
||
|
|
this.config = config;
|
||
|
|
this.positionUtils = positionUtils;
|
||
|
|
// Default work schedule - will be loaded from JSON later
|
||
|
|
this.workSchedule = {
|
||
|
|
weeklyDefault: {
|
||
|
|
monday: { start: 9, end: 17 },
|
||
|
|
tuesday: { start: 9, end: 17 },
|
||
|
|
wednesday: { start: 9, end: 17 },
|
||
|
|
thursday: { start: 9, end: 17 },
|
||
|
|
friday: { start: 9, end: 15 },
|
||
|
|
saturday: 'off',
|
||
|
|
sunday: 'off'
|
||
|
|
},
|
||
|
|
dateOverrides: {
|
||
|
|
'2025-01-20': { start: 10, end: 16 },
|
||
|
|
'2025-01-21': { start: 8, end: 14 },
|
||
|
|
'2025-01-22': 'off'
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Get work hours for a specific date
|
||
|
|
*/
|
||
|
|
getWorkHoursForDate(date) {
|
||
|
|
const dateString = this.dateService.formatISODate(date);
|
||
|
|
// Check for date-specific override first
|
||
|
|
if (this.workSchedule.dateOverrides[dateString]) {
|
||
|
|
return this.workSchedule.dateOverrides[dateString];
|
||
|
|
}
|
||
|
|
// Fall back to weekly default
|
||
|
|
const dayName = this.getDayName(date);
|
||
|
|
return this.workSchedule.weeklyDefault[dayName];
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Get work hours for multiple dates (used by GridManager)
|
||
|
|
*/
|
||
|
|
getWorkHoursForDateRange(dates) {
|
||
|
|
const workHoursMap = new Map();
|
||
|
|
dates.forEach(date => {
|
||
|
|
const dateString = this.dateService.formatISODate(date);
|
||
|
|
const workHours = this.getWorkHoursForDate(date);
|
||
|
|
workHoursMap.set(dateString, workHours);
|
||
|
|
});
|
||
|
|
return workHoursMap;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Calculate CSS custom properties for non-work hour overlays using PositionUtils
|
||
|
|
*/
|
||
|
|
calculateNonWorkHoursStyle(workHours) {
|
||
|
|
if (workHours === 'off') {
|
||
|
|
return null; // Full day will be colored via CSS background
|
||
|
|
}
|
||
|
|
const gridSettings = this.config.gridSettings;
|
||
|
|
const dayStartHour = gridSettings.dayStartHour;
|
||
|
|
const hourHeight = gridSettings.hourHeight;
|
||
|
|
// Before work: from day start to work start
|
||
|
|
const beforeWorkHeight = (workHours.start - dayStartHour) * hourHeight;
|
||
|
|
// After work: from work end to day end
|
||
|
|
const afterWorkTop = (workHours.end - dayStartHour) * hourHeight;
|
||
|
|
return {
|
||
|
|
beforeWorkHeight: Math.max(0, beforeWorkHeight),
|
||
|
|
afterWorkTop: Math.max(0, afterWorkTop)
|
||
|
|
};
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Calculate CSS custom properties for work hours overlay using PositionUtils
|
||
|
|
*/
|
||
|
|
calculateWorkHoursStyle(workHours) {
|
||
|
|
if (workHours === 'off') {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
// Create dummy time strings for start and end of work hours
|
||
|
|
const startTime = `${workHours.start.toString().padStart(2, '0')}:00`;
|
||
|
|
const endTime = `${workHours.end.toString().padStart(2, '0')}:00`;
|
||
|
|
// Use PositionUtils for consistent position calculation
|
||
|
|
const position = this.positionUtils.calculateEventPosition(startTime, endTime);
|
||
|
|
return { top: position.top, height: position.height };
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Load work schedule from JSON (future implementation)
|
||
|
|
*/
|
||
|
|
async loadWorkSchedule(jsonData) {
|
||
|
|
this.workSchedule = jsonData;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Get current work schedule configuration
|
||
|
|
*/
|
||
|
|
getWorkSchedule() {
|
||
|
|
return this.workSchedule;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Convert Date to day name key
|
||
|
|
*/
|
||
|
|
getDayName(date) {
|
||
|
|
const dayNames = [
|
||
|
|
'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'
|
||
|
|
];
|
||
|
|
return dayNames[date.getDay()];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
//# sourceMappingURL=WorkHoursManager.js.map
|