Commit Graph
1 Commits
Author SHA1 Message Date
Lauri Ojansivu fd935f7242 Add an optional "Sort by votes" mode that floats highly-voted cards up.
#3050: cards within a list are always rendered in the manual drag `sort`
order, with no way to bring the highest-voted cards to the top without
reordering them by hand.

The existing board-wide "Sort" popup (`cardsSortPopup`, already offering
due date / title / created date) gets a new "Sort by votes" entry -
extending it is the natural, minimal fit since it is already the one
alternate-sort mechanism WeKan has for cards, rather than building a
separate per-list toggle or a new multi-criteria picker.

Vote score (positive votes minus negative votes) is not a real Mongo
field, so it cannot be expressed as a Mongo sort spec the way due date/
title/created date are. `{ votes: -1 }` is used as a marker only:
`cardsWithLimit()` (client/components/lists/listBody.js) recognizes it,
fetches the window in the underlying manual `sort` order, and re-sorts
the resulting array in JS by vote score - a pure DISPLAY-order change.
The manual `sort` field on each card is never touched, so switching the
mode back off (or the plain "Sort" reset) restores the exact manual
drag order.

models/lib/voteSortCards.js extracts the comparator as a plain,
Meteor-free module (mirrors models/lib/boardSortReorder.js and
models/lib/sortCardsByTitle.js) so the scoring and ordering rules are
unit-testable: highest vote score first, a card with no votes scores 0
and sorts last, and ties (including two zero-vote cards) keep their
relative manual-sort order via a stable sort - proven in
tests/voteSortCards.test.cjs.

Thanks to xet7 !

Closes #3050,
2026-09-10 20:37:09 +03:00