Add functionality to handle missing shifts in RotaBuilder and include worker grades in the timetable

This commit is contained in:
Ross
2026-01-07 22:14:43 +00:00
parent 277f14747a
commit 64c4189d5f
3 changed files with 205 additions and 151 deletions
+33 -5
View File
@@ -921,6 +921,9 @@ function renderWorkerCheckboxes() {
let workerFilterSet = new Set();
// Store the current setting
let showShiftNames = false;
// Controls for rendering
let showWeekStart = false;
let showGrades = false;
// Call this after the DOM is ready and after timetable is rendered
renderWorkerCheckboxes();
@@ -938,8 +941,20 @@ $(document).on("change", "input[name='worker-filter-checkbox']", function() {
);
renderShiftTimetable();
});
// Add a checkbox to show/hide worker grades in the shift timetable
$("#shift-timetable-options").prepend(`
<div id="shift-timetable-show-grades" style="margin-bottom:8px;">
<label>
<input type="checkbox" id="show-grades-checkbox">
Show worker grades in timetable
</label>
</div>
`);
let showWeekStart = false;
$(document).on("change", "#show-grades-checkbox", function() {
showGrades = $(this).is(":checked");
renderShiftTimetable();
});
// 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;">
@@ -1022,7 +1037,7 @@ function renderShiftTimetable() {
row.append(`<td>${day}</td>`);
let workerCells = [];
$(`table#main-table td[data-date='${date}']`).filter(function () {
$(`table#main-table td[data-date='${date}']`).filter(function () {
let shifts = $(this).attr("data-shift");
if (!shifts) return false;
let cell_shifts = shifts.split(",").map(s => s.trim());
@@ -1030,6 +1045,14 @@ function renderShiftTimetable() {
}).each((n, td) => {
let workerTd = $(td).closest("tr").children("td:first");
let workerName = workerTd.find("span.name").text().trim();
// grade may be provided as a data attribute; if not, try to parse from visible text
let workerGrade = workerTd.attr('data-grade') || '';
if (!workerGrade) {
// attempt to parse e.g. "Name (4) [100]" -> capture 4
let txt = workerTd.text();
let m = txt.match(/\(([^)]+)\)/);
if (m) workerGrade = m[1].trim();
}
let workerId = workerTd.attr("data-worker-id");
if (!workerMatchesFilter(workerId)) return;
let cell_shifts = $(td).attr("data-shift").split(",").map(s => s.trim());
@@ -1043,7 +1066,8 @@ 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>`;
}
workerCells.push(`<td style="background:${color}">${workerName}${shiftLabel}</td>`);
let gradeTextLinear = showGrades ? ` <span style="font-size:0.85em;color:#444;">(${workerGrade})</span>` : '';
workerCells.push(`<td style="background:${color}">${workerName}${gradeTextLinear}${shiftLabel}</td>`);
});
if (workerCells.length === 0) {
@@ -1084,10 +1108,12 @@ function renderShiftTimetable() {
$("table#main-table td.worker").each(function () {
let workerId = $(this).attr("data-worker-id");
let workerName = $(this).find("span.name").text().trim();
let workerGrade = $(this).attr('data-grade') || '';
if (workerId && !workerIds.includes(workerId)) {
if (workerMatchesFilter(workerId)) {
workerIds.push(workerId);
workerIdToName[workerId] = workerName;
workerIdToName[workerId + '_grade'] = workerGrade;
}
}
});
@@ -1096,7 +1122,8 @@ function renderShiftTimetable() {
$("table#main-table td.worker").each(function () {
let workerId = $(this).attr("data-worker-id");
let workerName = $(this).find("span.name").text().trim();
if (!cellMap[workerId]) cellMap[workerId] = { name: workerName, cells: {} };
let workerGrade = $(this).attr('data-grade') || '';
if (!cellMap[workerId]) cellMap[workerId] = { name: workerName, grade: workerGrade, cells: {} };
});
$("table#main-table td[data-week][data-day]").each(function () {
let td = $(this);
@@ -1141,7 +1168,8 @@ 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.push(`<div style="background:${color};margin:1px 0;padding:0 2px;border-radius:3px;display:inline-block;">${worker.name}${shiftLabel}</div>`);
let gradeText = showGrades ? ` <span style="font-size:0.85em;color:#444;">(${worker.grade||''})</span>` : '';
cellContent.push(`<div style="background:${color};margin:1px 0;padding:0 2px;border-radius:3px;display:inline-block;">${worker.name}${gradeText}${shiftLabel}</div>`);
}
}
row.append(`<td style="border:1px solid #888; min-width:40px; text-align:center;">${cellContent.join(" / ")}</td>`);