From 078d74f09ff546d47f48d309ee3ad26c383881bd Mon Sep 17 00:00:00 2001 From: Ferdinand Urban Date: Tue, 28 Apr 2026 11:26:53 +0000 Subject: [PATCH] feat(calendar): pass slotsPerDay to generator, show skipped-dates warning --- js/calendar.js | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/js/calendar.js b/js/calendar.js index 6329128..d7e8661 100644 --- a/js/calendar.js +++ b/js/calendar.js @@ -80,6 +80,11 @@ export function renderCalendar() { 'Betriebsurlaub'; container.appendChild(legend); + const warnBox = document.createElement('div'); + warnBox.id = 'skipped-warning'; + warnBox.style.display = 'none'; + container.appendChild(warnBox); + // Calendar grid wrapper const wrapper = document.createElement('div'); wrapper.className = 'calendar-outer'; @@ -114,12 +119,15 @@ export function renderCalendar() { } const workdays = getWorkdays(currentYear, currentMonth, state.calendar.holidays, state.calendar.companyClosures); - const prefix = currentYear + '-' + String(currentMonth).padStart(2,'0'); + const prefix = currentYear + '-' + String(currentMonth).padStart(2, '0'); const historyWithoutMonth = state.history.filter(h => !h.date.startsWith(prefix)); - const result = generatePlan(workdays, state.employees, historyWithoutMonth); + // Reset month entries from history so dedup-by-(date,employeeId) doesn't keep stale rows + state.history = historyWithoutMonth; + const result = generatePlan(workdays, state.employees, historyWithoutMonth, Math.random, state.settings.moderatorsPerDay); currentPlan = result.assignments; addHistoryEntries(state, currentPlan); saveState(); + renderSkippedWarning(warnBox, result.skippedDates); renderGrid(wrapper, exportBtn); }); @@ -291,3 +299,33 @@ function renderGrid(wrapper, exportBtn) { wrapper.appendChild(bodyGrid); exportBtn.style.display = currentPlan.length > 0 ? 'inline-block' : 'none'; } + +function renderSkippedWarning(box, skippedDates) { + box.replaceChildren(); + if (!skippedDates || skippedDates.length === 0) { + box.style.display = 'none'; + return; + } + box.style.display = 'flex'; + box.className = 'skipped-warning'; + + const formatted = skippedDates.map(d => { + const [y, m, day] = d.split('-'); + return day + '.' + m + '.'; + }).join(', '); + + const text = document.createElement('span'); + text.textContent = skippedDates.length === 1 + ? '1 Tag konnte nicht vollständig besetzt werden: ' + formatted + : skippedDates.length + ' Tage konnten nicht vollständig besetzt werden: ' + formatted; + box.appendChild(text); + + const closeBtn = document.createElement('button'); + closeBtn.type = 'button'; + closeBtn.textContent = '✕'; + closeBtn.addEventListener('click', () => { + box.replaceChildren(); + box.style.display = 'none'; + }); + box.appendChild(closeBtn); +}