Files
wekan/models/lib/checklistItemSchedule.js
T
Lauri Ojansivu 7ca1489279 Checklist items get a person responsible, and dated items show in the calendar and Gantt.
Each checklist item gets a "who is responsible" button: the board's
active members to pick from, or nobody; the avatar then shows on the
item. A deny rule keeps the responsible person an active member of the
item's board. Checklist items with a due date (#4755) now appear in the
calendar and in the Frappe and dhtmlx Gantt views as "card: item", with
their own `ci:` ids: opening one opens its card, a calendar drag of one is
refused, and moving one in a Gantt moves only the item's own due date -
never the card's dates.

models/lib/checklistItemSchedule.js collects dated items (not of archived
or missing cards) and decides who may be responsible;
tests/checklistItemSchedule.test.cjs covers both and the wiring of the
three views. tests/checklistItemDueDate.test.cjs, which pinned #4755 as
"due dates only", now says the assignee is #1618's own field. The new
strings are English placeholders until the next translation pass.

Thanks to martinbruno90 and xet7 !

Fixes #1618.
2026-10-14 15:24:57 +03:00

51 lines
1.9 KiB
JavaScript

'use strict';
// #1618: a person responsible for each checklist item, and dated checklist
// items in the calendar and the Gantt views. An item's due date (dueAt) shows
// beside the cards, as "card: item", with its own id - `ci:<itemId>` - so the
// views never mistake it for a card: opening it opens its card, and moving it
// moves only the item's own due date. Pure: tests/checklistItemSchedule.test.cjs.
const PREFIX = 'ci:';
function isChecklistItemEventId(id) {
return typeof id === 'string' && id.startsWith(PREFIX);
}
function checklistItemIdOf(id) {
return isChecklistItemEventId(id) ? id.slice(PREFIX.length) : null;
}
// The board's dated, not-archived checklist items, each with its card, in
// [from, to) when a range is given.
function datedChecklistItems(items, cardOf, { from, to } = {}) {
const out = [];
for (const item of Array.isArray(items) ? items : []) {
if (!item || !item.dueAt) continue;
const due = new Date(item.dueAt);
if (Number.isNaN(due.getTime())) continue;
if (from && due < new Date(from)) continue;
if (to && due >= new Date(to)) continue;
const card = cardOf(item.cardId);
if (!card || card.archived) continue;
out.push({
id: PREFIX + item._id,
itemId: item._id,
cardId: card._id,
title: `${card.title || ''}: ${item.title || ''}`,
dueAt: due,
isFinished: !!item.isFinished,
assigneeId: item.assigneeId || null,
});
}
return out.sort((a, b) => a.dueAt - b.dueAt);
}
// Whether `userId` may be made responsible for an item of `board`.
function mayBeAssigned(board, userId) {
if (userId === null || userId === '') return true; // nobody
return typeof userId === 'string' && !!board && (board.members || [])
.some(m => m && m.userId === userId && m.isActive !== false);
}
module.exports = { PREFIX, isChecklistItemEventId, checklistItemIdOf, datedChecklistItems, mayBeAssigned };