mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Board-level search now matches text inside card comments, consistent with global search (#5910); the (title OR description OR comment) rule is extracted to the unit-tested helper server/lib/cardMatch.js. Search-result cards can be dragged directly onto board lists, reusing card.move() (#6034, MVP: drops append to end of the target list). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
/**
|
|
* Pure, dependency-free card text-matching helper.
|
|
*
|
|
* Single source of truth for "does this card match a free-text query",
|
|
* shared by board-level and global search so both behave consistently.
|
|
*
|
|
* #5910: board-level search must also match text inside card comments,
|
|
* exactly like global search does. The query is matched (case-insensitively)
|
|
* against the card title, description, AND every comment text.
|
|
*
|
|
* This module intentionally has NO Meteor / collection imports so it can be
|
|
* imported directly by unit tests (mocha + chai) without a running app.
|
|
*
|
|
* @param {Object} card
|
|
* @param {string} [card.title]
|
|
* @param {string} [card.description]
|
|
* @param {string[]} [card.commentTexts] - texts of the card's comments
|
|
* @param {string} query - free-text query
|
|
* @returns {boolean} true if the query matches title, description or any comment
|
|
*/
|
|
export function cardMatchesQuery(card, query) {
|
|
const c = card || {};
|
|
const q = (query == null ? '' : String(query)).toLowerCase();
|
|
|
|
// Empty query matches everything (mirrors existing search.logic behaviour).
|
|
if (q === '') {
|
|
return true;
|
|
}
|
|
|
|
const haystacks = [];
|
|
|
|
if (c.title) {
|
|
haystacks.push(String(c.title));
|
|
}
|
|
if (c.description) {
|
|
haystacks.push(String(c.description));
|
|
}
|
|
if (Array.isArray(c.commentTexts)) {
|
|
for (const t of c.commentTexts) {
|
|
if (t) {
|
|
haystacks.push(String(t));
|
|
}
|
|
}
|
|
}
|
|
|
|
return haystacks.some(h => h.toLowerCase().includes(q));
|
|
}
|