Files
wekan/models/lib/ruleMoveDirection.js
Lauri Ojansivu eac524380f Add rule triggers for a card moved forward or back.
The reporter puts a card at the bottom of the next list when it moves on and
at the top when it moves back. With only "moved to" and "moved from" a list
triggers, that needs a rule for every pair of lists. "A card is moved forward
to a later list" and "moved back to an earlier list" now fire on any move
between two lists of the board, compared by the lists' order rather than by
the screen, so they also work in right-to-left languages. They are matched
on the rule's own board, like the other trigger kinds
(models/lib/ruleMoveDirection.js).

tests/ruleMoveDirection.test.cjs covers the directions and what has none; a
Playwright case moves cards both ways through the REST API. The RepointBleed
guard counts the new matching path. New text is in English, pending
Transifex.

Thanks to rlach and xet7 !

Fixes #2076.
2026-10-08 12:25:29 +03:00

27 lines
1.2 KiB
JavaScript

'use strict';
// #2076: rule triggers "a card is moved forward" and "... back": to a list
// after or before the one it left, in the board's list order. The reporter
// puts a card at the bottom of the next list when it moves on and at the top
// when it moves back; with plain "moved to / moved from" triggers that needs a
// rule for every pair of lists. The order is the lists' sort, not the screen,
// so the same rule works in right-to-left languages, where it is drawn the
// other way.
//
// Pure: tested by tests/ruleMoveDirection.test.cjs.
const MOVE_DIRECTIONS = ['forward', 'back'];
function moveDirection(oldList, newList) {
if (!oldList || !newList || oldList._id === newList._id || oldList.boardId !== newList.boardId) return null;
const from = Number(oldList.sort);
const to = Number(newList.sort);
if (!Number.isFinite(from) || !Number.isFinite(to) || from === to) return null;
return to > from ? 'forward' : 'back';
}
function directionTriggerMatches(trigger, direction) {
return !!trigger && MOVE_DIRECTIONS.includes(trigger.direction) && trigger.direction === direction;
}
module.exports = { MOVE_DIRECTIONS, moveDirection, directionTriggerMatches };