Files
wekan/models/lib/calendarFilter.js
T
Lauri Ojansivu 8d1fae4f7d Convert client-reachable models/lib helpers from CommonJS to ES modules (1/2).
The rspack client build treats a `module.exports` file imported into the
client bundle as an ES module and throws
"ES Modules may not assign module.exports" at evaluation time, aborting
the whole client module chain (No such template: swimlane / notifications
/ boardButtons, blank board, missing top bar). This is not an rspack
version regression (the lockfile has pinned ~1.7.x since v8.40); it is
that WeKan added CommonJS helpers to the client bundle.

Convert the 42 client-reachable pure-logic models/lib helpers from
`module.exports = { ... }` to `export { ... }`, and calendarFilter's
internal require('./swimlaneFilter') to an import with a .js extension
(node ESM needs it; rspack/reify tolerate it). Server-only helpers that
use node built-ins (fs/path/child_process) stay CommonJS. The plain-Node
.cjs unit tests for these helpers now use `await import(...js)` (wrapped
in an async IIFE); a source-guard in importVirtualMembers was updated
from module.exports to export. Verified: the full tests/*.test.cjs suite
has the SAME 7 pre-existing failures as before this change and no new
ones.
2026-07-23 18:55:30 +03:00

54 lines
2.0 KiB
JavaScript

'use strict';
// Pure, Meteor-free helpers for building the card selectors the Calendar view
// (client/components/boards/boardBody.js) queries. Extracted so the selectors
// are unit-testable in plain Node (mirrors models/lib/swimlaneFilter.js).
//
// #5656 ("Filter not working for Calendar"): the board Filter sidebar (member /
// assignee / due-date / label / custom-field) scopes the Board / Lists /
// Swimlanes views, but the Calendar view used to query cards with only a
// board+date selector and ignore the active Filter entirely, so it showed every
// card in the interval regardless of the filter. These builders combine the
// date-interval base selector with the Filter's selector via combineWithFilter,
// so the Filter is ALWAYS ANDed in (never overwritten by — nor colliding with —
// the top-level `$or` that cardsInIntervalSelector uses) and the Calendar honors
// the same filter as the other views. `filterSelector` is the object produced by
// Filter._getMongoSelector() on the client; pass a falsy/empty value when no
// filter is active (or on the server) and the base selector is returned
// unchanged.
import { combineWithFilter } from './swimlaneFilter.js';
// Cards whose due date falls within [start, end].
function cardsDueInBetweenSelector(boardId, start, end, filterSelector) {
return combineWithFilter(
{
boardId,
dueAt: { $gte: start, $lte: end },
},
filterSelector,
);
}
// Cards whose [startAt, endAt] interval overlaps [start, end] in any way:
// starts before and still runs at `start`, starts before and still runs at
// `end`, or is fully contained within [start, end].
function cardsInIntervalSelector(boardId, start, end, filterSelector) {
return combineWithFilter(
{
boardId,
$or: [
{ startAt: { $lte: start }, endAt: { $gte: start } },
{ startAt: { $lte: end }, endAt: { $gte: end } },
{ startAt: { $gte: start }, endAt: { $lte: end } },
],
},
filterSelector,
);
}
export {
cardsDueInBetweenSelector,
cardsInIntervalSelector,
};