mirror of
https://github.com/GuySandler/CanvasRefined.git
synced 2026-11-03 22:07:18 +01:00
fixed missing overdues on timeframe
This commit is contained in:
parent
6aa05b268d
commit
4e7f66d5f7
@ -2316,17 +2316,35 @@ function getTodoTimeframePastDays() {
|
|||||||
return TODO_TIMEFRAME_LOOKBACK_DAYS;
|
return TODO_TIMEFRAME_LOOKBACK_DAYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// True when the item's due date is before today (start of day), matching the
|
||||||
|
// "Overdue" group (-1) in the task list. Used so overdue work bypasses the
|
||||||
|
// timeframe window: overdue items are current workload and must always stay
|
||||||
|
// visible, no matter which timeframe is selected (or how far the pager has
|
||||||
|
// been advanced).
|
||||||
|
function isTodoOverdueItem(item) {
|
||||||
|
const due = new Date(item?.plannable_date);
|
||||||
|
if (isNaN(due.getTime())) return false;
|
||||||
|
due.setHours(0, 0, 0, 0);
|
||||||
|
const today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
return due.getTime() < today.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
// Better Todo timeframe filter, shared by the task list and the progress
|
// Better Todo timeframe filter, shared by the task list and the progress
|
||||||
// display so their counts always agree: keeps items due inside the current
|
// display so their counts always agree: keeps items due inside the current
|
||||||
// window. Offset 0 runs from the lookback bound (1 week back for presets,
|
// window. Offset 0 runs from the lookback bound (1 week back for presets,
|
||||||
// "X days ago" for custom) through the future edge, so recently overdue work
|
// "X days ago" for custom) through the future edge; offset N>0 shows only the
|
||||||
// stays visible while older backlog is cut; offset N>0 shows only the strict
|
// strict window (now+N*span, now+(N+1)*span] so the current timeframe can be
|
||||||
// window (now+N*span, now+(N+1)*span] so the current timeframe can be paged
|
// paged through with the look-ahead arrows. "all" keeps everything. Overdue
|
||||||
// through with the look-ahead arrows. "all" keeps everything.
|
// items always pass the filter regardless of the window (see
|
||||||
|
// isTodoOverdueItem) — the timeframe only bounds upcoming work, it never
|
||||||
|
// hides overdue backlog.
|
||||||
// `lenientPast` (Announcements / Completed tabs): on the current window those
|
// `lenientPast` (Announcements / Completed tabs): on the current window those
|
||||||
// tabs keep everything on/before the cutoff — completed history and unread
|
// tabs keep everything on/before the cutoff — completed history and unread
|
||||||
// announcements older than the lookback are still meaningful there — while
|
// announcements older than the lookback are still meaningful there — while
|
||||||
// paging forward uses the same strict windows as Tasks.
|
// paging forward uses the same strict windows as Tasks. The overdue bypass
|
||||||
|
// only applies to the Tasks tab: old announcements/completed history have
|
||||||
|
// past dates but are not overdue work.
|
||||||
function applyTodoTimeframe(items, lenientPast) {
|
function applyTodoTimeframe(items, lenientPast) {
|
||||||
betterTodoTimeframe = getTodoTimeframeKey();
|
betterTodoTimeframe = getTodoTimeframeKey();
|
||||||
if (betterTodoTimeframe === "all") return items;
|
if (betterTodoTimeframe === "all") return items;
|
||||||
@ -2344,6 +2362,7 @@ function applyTodoTimeframe(items, lenientPast) {
|
|||||||
}
|
}
|
||||||
const windowStart = now + (betterTodoTimeframeOffset * days - pastDays) * dayMs;
|
const windowStart = now + (betterTodoTimeframeOffset * days - pastDays) * dayMs;
|
||||||
return items.filter(item => {
|
return items.filter(item => {
|
||||||
|
if (lenientPast !== true && isTodoOverdueItem(item)) return true;
|
||||||
const t = new Date(item.plannable_date).getTime();
|
const t = new Date(item.plannable_date).getTime();
|
||||||
return t > windowStart && t <= cutoff;
|
return t > windowStart && t <= cutoff;
|
||||||
});
|
});
|
||||||
@ -3002,19 +3021,21 @@ function renderProgressRings(container, scopedData) {
|
|||||||
if (mode === "none") { container.innerHTML = ""; return; }
|
if (mode === "none") { container.innerHTML = ""; return; }
|
||||||
|
|
||||||
// Apply the same timeframe window the list pages through so the counts
|
// Apply the same timeframe window the list pages through so the counts
|
||||||
// in the display match what's shown below it. Unlike the Tasks tab —
|
// in the display match what's shown below it. Overdue work always counts
|
||||||
// which keeps recently overdue work — finished work from before the
|
// (the Tasks tab never hides it, see isTodoOverdueItem); finished work
|
||||||
// window is history, not current workload, so it never counts. The
|
// from before the window is history, not current workload, so it never
|
||||||
// window is a strict slice (from the lookback bound through the future
|
// counts. The window is otherwise a strict slice (from the lookback bound
|
||||||
// edge), so the counts always match the Tasks tab exactly.
|
// through the future edge), so the counts always match the Tasks tab
|
||||||
|
// exactly.
|
||||||
const taskItems = scopedData.filter(item => isTodoTaskType(item));
|
const taskItems = scopedData.filter(item => isTodoTaskType(item));
|
||||||
const bounds = getTodoTimeframeBounds();
|
const bounds = getTodoTimeframeBounds();
|
||||||
|
const isDone = (item) => (item.submissions?.submitted || item.planner_override?.marked_complete === true) && !isPinnedIncomplete(item);
|
||||||
let allAssignments;
|
let allAssignments;
|
||||||
if (!bounds) {
|
if (!bounds) {
|
||||||
allAssignments = taskItems;
|
allAssignments = taskItems;
|
||||||
} else {
|
} else {
|
||||||
const isDone = (item) => (item.submissions?.submitted || item.planner_override?.marked_complete === true) && !isPinnedIncomplete(item);
|
|
||||||
allAssignments = taskItems.filter(item => {
|
allAssignments = taskItems.filter(item => {
|
||||||
|
if (!isDone(item) && isTodoOverdueItem(item)) return true;
|
||||||
const t = new Date(item.plannable_date).getTime();
|
const t = new Date(item.plannable_date).getTime();
|
||||||
return t > bounds.start && t <= bounds.end;
|
return t > bounds.start && t <= bounds.end;
|
||||||
});
|
});
|
||||||
@ -3799,9 +3820,10 @@ async function createTodoSections(location) {
|
|||||||
// date, Announcements by posted date, Completed by due date. The
|
// date, Announcements by posted date, Completed by due date. The
|
||||||
// Tasks tab bounds the past (1 week of history back), while
|
// Tasks tab bounds the past (1 week of history back), while
|
||||||
// Announcements/Completed keep their older history on the current
|
// Announcements/Completed keep their older history on the current
|
||||||
// window and only narrow when paged forward.
|
// window and only narrow when paged forward. Overdue items bypass
|
||||||
// Pinned items ("sent back" submissions) bypass the window filter so
|
// the window filter entirely (isTodoOverdueItem) so overdue backlog
|
||||||
// an old pinned item still shows up under Tasks.
|
// always stays visible, and pinned items ("sent back" submissions)
|
||||||
|
// bypass it too so an old pinned item still shows up under Tasks.
|
||||||
const pinnedItems = assignmentsDue.filter(item => isPinnedIncomplete(item));
|
const pinnedItems = assignmentsDue.filter(item => isPinnedIncomplete(item));
|
||||||
assignmentsDue = applyTodoTimeframe(assignmentsDue.filter(item => !isPinnedIncomplete(item)), false).concat(pinnedItems);
|
assignmentsDue = applyTodoTimeframe(assignmentsDue.filter(item => !isPinnedIncomplete(item)), false).concat(pinnedItems);
|
||||||
announcements = applyTodoTimeframe(announcements, true);
|
announcements = applyTodoTimeframe(announcements, true);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user