mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
A sortList rule re-sorts the cards of the rule card's list, or a named list on the same board, and gives each card its index as its sort; the hook records one position History row per changed card and there is no activity. It now has a saved command: the order is decided once, by the same sort keys the ordinary action uses (moved to the pure models/lib/ruleSortList.js so the two cannot drift), and each changed card is a unit written conditionally on its saved sort with its planned position row. Replays change nothing more. Thanks to xet7 !
25 lines
981 B
JavaScript
25 lines
981 B
JavaScript
'use strict';
|
|
|
|
// The order a sortList rule action puts a list's cards in (server/rulesHelper.js
|
|
// performAction, and its durable command server/lib/syncRuleSortListCommand.js):
|
|
// by name, creation, modification or due date (the default), each card then
|
|
// taking its index as its sort. Pure, so both paths sort the same way.
|
|
function sortKey(card, sortField) {
|
|
switch (sortField) {
|
|
case 'name': return (card.title || '').toLowerCase();
|
|
case 'created': return card.createdAt ? new Date(card.createdAt).getTime() : 0;
|
|
case 'modified': return card.modifiedAt ? new Date(card.modifiedAt).getTime() : 0;
|
|
case 'due':
|
|
default: return card.dueAt ? new Date(card.dueAt).getTime() : Number.MAX_SAFE_INTEGER;
|
|
}
|
|
}
|
|
|
|
function sortListOrder(cards, sortField) {
|
|
return [...(cards || [])].sort((a, b) => {
|
|
const ka = sortKey(a, sortField), kb = sortKey(b, sortField);
|
|
return ka > kb ? 1 : ka < kb ? -1 : 0;
|
|
});
|
|
}
|
|
|
|
module.exports = { sortKey, sortListOrder };
|