mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
#2194 asked for a text-search rule condition combinable with other triggers. WeKan's rules stay single-trigger/single-condition today - combining several conditions in one rule with AND was already looked at and explicitly deferred by #4294 (see TODO Later) - so this adds ONE new standalone trigger type instead: "when a card's title or description contains {value}", the same scope-down the #3092 advanced-filter trigger used. A new pure module, models/lib/ruleTextContainsMatch.js, does a case-insensitive substring test against a card's title/description; server/rulesHelper.js (already wired to import and call it) evaluates it the same way it already evaluates the advanced-filter trigger, on card creation and the a-changedTitle/a-changedDescription activities. This commit adds the missing pieces to complete that wiring: the pure module itself, the card-triggers Add Rule UI row (cardTriggers.jade/ .js) with its text input, and tests/rulesTextContainsTrigger.test.cjs pinning the match function, the trigger registration, the rulesHelper.js wiring, the UI wiring and the i18n keys. Thanks to sfahrenholz and xet7 ! Closes #2194,
38 lines
1.5 KiB
JavaScript
38 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
// #2194 "Card title/description contains {value}" rule trigger.
|
|
//
|
|
// WeKan's rules are single-trigger/single-condition today (see the #4294
|
|
// investigation noted in CHANGELOG.md's TODO Later - combining several
|
|
// conditions in one rule with AND is explicitly out of scope here and
|
|
// deferred). This module is the pure, testable decision for a SINGLE new
|
|
// trigger type: does a card's title or description contain a
|
|
// case-insensitive substring the user typed when creating the rule?
|
|
//
|
|
// Pure (no Meteor imports) so both server/rulesHelper.js and the unit tests
|
|
// share one implementation, the same discipline models/lib/ruleCardTitleFilter.js
|
|
// and server/lib/advancedFilterMatch.js already follow.
|
|
|
|
// Case-insensitive substring test. Returns false when either side is not a
|
|
// non-empty string - an unset trigger value never matches anything, and a
|
|
// card with no title/description (undefined/null) never matches either.
|
|
function textContainsMatch(text, needle) {
|
|
if (typeof needle !== 'string' || needle.trim() === '') return false;
|
|
if (typeof text !== 'string' || text === '') return false;
|
|
return text.toLowerCase().includes(needle.toLowerCase());
|
|
}
|
|
|
|
// Does the card (title and/or description) contain the trigger's substring?
|
|
function cardTextContainsMatch(card, needle) {
|
|
if (!card) return false;
|
|
return (
|
|
textContainsMatch(card.title, needle) ||
|
|
textContainsMatch(card.description, needle)
|
|
);
|
|
}
|
|
|
|
module.exports = {
|
|
textContainsMatch,
|
|
cardTextContainsMatch,
|
|
};
|