diff options
author | Angelo Gallarello <angelo.gallarell@gmail.com> | 2018-08-16 00:32:31 +0200 |
---|---|---|
committer | Angelo Gallarello <angelo.gallarell@gmail.com> | 2018-08-16 00:32:31 +0200 |
commit | 6828ccd7f17d14f178e6742d78bdd14428ec6e07 (patch) | |
tree | bca97277f80b29bf224e92b73e5fa6ec630f53c9 /server/rulesHelper.js | |
parent | 9b0eb0a9f1973e05df7199cf2bff7518f2fa98dc (diff) | |
download | wekan-6828ccd7f17d14f178e6742d78bdd14428ec6e07.tar.gz wekan-6828ccd7f17d14f178e6742d78bdd14428ec6e07.tar.bz2 wekan-6828ccd7f17d14f178e6742d78bdd14428ec6e07.zip |
Main flow implemented
Diffstat (limited to 'server/rulesHelper.js')
-rw-r--r-- | server/rulesHelper.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/server/rulesHelper.js b/server/rulesHelper.js new file mode 100644 index 00000000..4af6c08c --- /dev/null +++ b/server/rulesHelper.js @@ -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; + } + +}
\ No newline at end of file |