mirror of
https://github.com/wekan/wekan.git
synced 2025-09-22 01:50:48 +02:00
Main flow implemented
This commit is contained in:
parent
9b0eb0a9f1
commit
6828ccd7f1
9 changed files with 100 additions and 15 deletions
41
server/rulesHelper.js
Normal file
41
server/rulesHelper.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue