mirror of https://github.com/wekan/wekan
The Open Source kanban (built with Meteor). Keep variable/table/field names camelCase. For translations, only add Pull Request changes to wekan/i18n/en.i18n.json , other translations are done at https://transifex.com/wekan/wekan only.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.3 KiB
41 lines
1.3 KiB
|
7 years ago
|
RulesHelper = {
|
||
|
|
|
||
|
|
|
||
|
|
executeRules(activity){
|
||
|
|
const matchingRules = this.findMatchingRules(activity);
|
||
|
|
for(let i = 0;i< matchingRules.length;i++){
|
||
|
|
const actionType = matchingRules[i].getAction().actionType;
|
||
|
|
this.performAction(activity,actionType);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
performAction(activity,actionType){
|
||
|
|
if(actionType == "moveCardToTop"){
|
||
|
|
const card = Cards.findOne({_id:activity.cardId});
|
||
|
|
const minOrder = _.min(card.list().cards(card.swimlaneId).map((c) => c.sort));
|
||
|
|
card.move(card.swimlaneId, card.listId, minOrder - 1);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
findMatchingRules(activity){
|
||
|
|
const activityType = activity.activityType;
|
||
|
|
const matchingFields = TriggersDef[activityType].matchingFields;
|
||
|
|
const matchingMap = this.buildMatchingFieldsMap(activity,matchingFields);
|
||
|
|
let matchingTriggers = Triggers.find(matchingMap);
|
||
|
|
let matchingRules = [];
|
||
|
|
matchingTriggers.forEach(function(trigger){
|
||
|
|
matchingRules.push(trigger.getRule());
|
||
|
|
});
|
||
|
|
return matchingRules;
|
||
|
|
},
|
||
|
|
buildMatchingFieldsMap(activity, matchingFields){
|
||
|
|
let matchingMap = {};
|
||
|
|
for(let i = 0;i< matchingFields.length;i++){
|
||
|
|
// Creating a matching map with the actual field of the activity
|
||
|
|
// and with the wildcard (for example: trigger when a card is added
|
||
|
|
// in any [*] board
|
||
|
|
matchingMap[matchingFields[i]] = { $in: [activity[matchingFields[i]],"*"]};
|
||
|
|
}
|
||
|
|
return matchingMap;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|