Add allow_self option to PostShiftConstraint and PreShiftConstraint for flexible shift assignment

This commit is contained in:
Ross
2025-12-08 17:47:19 +00:00
parent 3f4d8068eb
commit 4a8c478a73
3 changed files with 47 additions and 7 deletions
+36 -4
View File
@@ -550,6 +550,7 @@ $(document).on("change", "input[name='worker-filter-checkbox']", function() {
renderShiftTimetable();
});
let showWeekStart = false;
// Add a checkbox to show/hide shift names in the shift timetable section
$("#shift-timetable-options").prepend(`
<div id="shift-timetable-show-shift-names" style="margin-bottom:8px;">
@@ -558,7 +559,15 @@ $("#shift-timetable-options").prepend(`
Show shift names in timetable
</label>
</div>
`).prepend(`
<div id="week-start-control" style="margin:8px 0;">
<label>
<input type="checkbox" id="show-week-start-checkbox">
Show week start dates in grid view
</label>
</div>
`);
// Add a button to remove all shift timetable colours (set to white)
$("#shift-colour-controls").append(
`<button id="remove-shift-colours" style="margin-left:10px;">Remove Shift Colours</button>`
@@ -581,6 +590,12 @@ $("#show-shift-names-checkbox").on("change", function() {
renderShiftTimetable();
});
$("#show-week-start-checkbox").on("change", function () {
showWeekStart = $(this).is(":checked");
renderShiftTimetable();
});
// Patch renderShiftTimetable to show shift names if enabled
function renderShiftTimetable() {
console.log("Render shift timetable");
@@ -663,6 +678,18 @@ function renderShiftTimetable() {
});
weeks = weeks.sort((a, b) => parseInt(a) - parseInt(b));
// Build week -> start date map (earliest date in that week)
let weekStartDates = {};
$("table#main-table td[data-week][data-date]").each(function () {
let wk = $(this).attr("data-week");
let d = $(this).attr("data-date");
if (!wk || !d) return;
if (!weekStartDates[wk] || new Date(d) < new Date(weekStartDates[wk])) {
weekStartDates[wk] = d;
}
});
let workerIds = [];
let workerIdToName = {};
$("table#main-table td.worker").each(function () {
@@ -703,9 +730,14 @@ function renderShiftTimetable() {
weeks.forEach(week => {
let row = $(`<tr></tr>`);
row.append(`<td style="border:1px solid #888; min-width:60px; width:80px; font-weight:bold;">${week}</td>`);
// Show week number and (optionally) the week's start date
let weekLabel = [week];
if (showWeekStart && weekStartDates[week]) {
weekLabel += `<div style="font-size:0.85em; color:#444;">${weekStartDates[week]}</div>`;
}
row.append(`<td style="border:1px solid #888; min-width:60px; width:120px; font-weight:bold; vertical-align:middle;">${weekLabel}</td>`);
daysOfWeek.forEach(day => {
let cellContent = "";
let cellContent = [];
for (const workerId of workerIds) {
let worker = cellMap[workerId];
let shifts = (worker.cells[week] && worker.cells[week][day]) || [];
@@ -720,10 +752,10 @@ function renderShiftTimetable() {
color = `linear-gradient(90deg, ${shiftColors[matchedShifts[0]]} 0 50%, ${shiftColors[matchedShifts[1]]} 50% 100%)`;
if (showShiftNames) shiftLabel = `<span style="font-size:0.9em; color:#333;"> (${matchedShifts.join(", ")})</span>`;
}
cellContent += `<div style="background:${color};margin:1px 0;padding:0 2px;border-radius:3px;display:inline-block;">${worker.name}${shiftLabel}</div> `;
cellContent.push(`<div style="background:${color};margin:1px 0;padding:0 2px;border-radius:3px;display:inline-block;">${worker.name}${shiftLabel}</div>`);
}
}
row.append(`<td style="border:1px solid #888; min-width:40px; text-align:center;">${cellContent}</td>`);
row.append(`<td style="border:1px solid #888; min-width:40px; text-align:center;">${cellContent.join(" / ")}</td>`);
});
gridTable.append(row);
});