Auto-select active menu based on current time, allow manual override

When multiple menus exist, checks current time and day against menu
schedules. If exactly one menu matches, auto-selects it. If times
overlap or none match, shows all categories. User can still manually
select any menu or 'All Menus' from the dropdown.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
John Mizerek 2026-01-28 18:13:44 -08:00
parent 41ef1631ef
commit 9091461079
2 changed files with 35 additions and 1 deletions

View file

@ -82,6 +82,40 @@ try {
"MenuSortOrder": qMenus.MenuSortOrder[m]
});
}
// Auto-select menu based on current time when no specific menu requested
if (menuID == 0 && qMenus.recordCount > 1) {
now = timeFormat(now(), "HH:mm");
dayOfWeek = dayOfWeek(now()); // 1=Sun, 2=Mon, ... 7=Sat
dayBit = 2 ^ (dayOfWeek - 1); // bitmask: 1=Sun, 2=Mon, 4=Tue, etc.
activeMenuIds = [];
for (m = 1; m <= qMenus.recordCount; m++) {
// Check if menu is active today (days bitmask)
menuDays = qMenus.MenuDaysActive[m];
if (bitAnd(menuDays, dayBit) == 0) continue;
// Check time range
hasStart = !isNull(qMenus.MenuStartTime[m]);
hasEnd = !isNull(qMenus.MenuEndTime[m]);
if (hasStart && hasEnd) {
startT = timeFormat(qMenus.MenuStartTime[m], "HH:mm");
endT = timeFormat(qMenus.MenuEndTime[m], "HH:mm");
if (now >= startT && now <= endT) {
arrayAppend(activeMenuIds, qMenus.MenuID[m]);
}
} else {
// No time restriction = always active
arrayAppend(activeMenuIds, qMenus.MenuID[m]);
}
}
// If exactly one menu is active now, auto-select it
if (arrayLen(activeMenuIds) == 1) {
menuID = activeMenuIds[1];
}
// If multiple match (overlap) or none match, show all (menuID stays 0)
}
} catch (any e) {
// Menus table might not exist yet
}

View file

@ -3343,7 +3343,7 @@
const selector = document.getElementById('menuSelector');
if (!selector) return;
let options = '<option value="0">All Categories</option>';
let options = '<option value="0">All Menus</option>';
for (const menu of this.menus) {
const selected = menu.MenuID === this.selectedMenuId ? 'selected' : '';
options += `<option value="${menu.MenuID}" ${selected}>${this.escapeHtml(menu.MenuName)}</option>`;