summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/components/rules/rulesMain.js2
-rw-r--r--client/components/rules/triggers/boardTriggers.js2
-rw-r--r--models/actions.js8
-rw-r--r--models/activities.js10
-rw-r--r--models/lists.js2
-rw-r--r--models/rules.js5
-rw-r--r--models/triggers.js6
-rw-r--r--server/rulesHelper.js41
-rw-r--r--server/triggersDef.js39
9 files changed, 100 insertions, 15 deletions
diff --git a/client/components/rules/rulesMain.js b/client/components/rules/rulesMain.js
index c7e10512..5a4b612a 100644
--- a/client/components/rules/rulesMain.js
+++ b/client/components/rules/rulesMain.js
@@ -29,6 +29,8 @@ BlazeComponent.extendComponent({
return [{'click .js-delete-rule'(event) {
const rule = this.currentData();
Rules.remove(rule._id);
+ Actions.remove(rule.actionId);
+ Triggers.remove(rule.triggerId);
},
'click .js-goto-trigger'(event) {
diff --git a/client/components/rules/triggers/boardTriggers.js b/client/components/rules/triggers/boardTriggers.js
index 4c8594d3..08274777 100644
--- a/client/components/rules/triggers/boardTriggers.js
+++ b/client/components/rules/triggers/boardTriggers.js
@@ -11,7 +11,7 @@ BlazeComponent.extendComponent({
const actionSelected = this.find('#action').value;
const boardId = Session.get('currentBoard')
if(actionSelected == "created"){
- Triggers.insert({activityType: "createCard","boardId":boardId},function(error,id){
+ Triggers.insert({activityType: "createCard","boardId":boardId,"listId":"*"},function(error,id){
datas.triggerIdVar.set(id);
});
}
diff --git a/models/actions.js b/models/actions.js
index 0961abbb..93d45928 100644
--- a/models/actions.js
+++ b/models/actions.js
@@ -43,14 +43,6 @@ Actions.helpers({
-if (Meteor.isServer) {
- Meteor.startup(() => {
- const rules = Triggers.findOne({});
- if(!rules){
- Actions.insert({actionType: "moveCardToTop"});
- }
- });
-}
diff --git a/models/activities.js b/models/activities.js
index beb741bc..fe24c9c4 100644
--- a/models/activities.js
+++ b/models/activities.js
@@ -60,13 +60,13 @@ Activities.before.insert((userId, doc) => {
Activities.after.insert((userId, doc) => {
const activity = Activities._transform(doc);
- const matchedTriggers = Triggers.find(activity);
- if(matchedTriggers.count() > 0){
- const card = activity.card();
- Cards.direct.update({_id: card._id},{$set: {title: "ciaooo"}});
- }
+ RulesHelper.executeRules(activity);
+
});
+
+
+
if (Meteor.isServer) {
// For efficiency create indexes on the date of creation, and on the date of
// creation in conjunction with the card or board id, as corresponding views
diff --git a/models/lists.js b/models/lists.js
index 6f6996cb..ceda9ad1 100644
--- a/models/lists.js
+++ b/models/lists.js
@@ -82,7 +82,7 @@ Lists.helpers({
};
if (swimlaneId)
selector.swimlaneId = swimlaneId;
- return Cards.find(Filter.mongoSelector(selector),
+ return Cards.find(selector,
{ sort: ['sort'] });
},
diff --git a/models/rules.js b/models/rules.js
index 778622c4..271e6b52 100644
--- a/models/rules.js
+++ b/models/rules.js
@@ -21,6 +21,11 @@ Rules.mutations({
},
});
+Rules.helpers({
+ getAction(){
+ return Actions.findOne({_id:this.actionId});
+ },
+});
diff --git a/models/triggers.js b/models/triggers.js
index 660d8b94..e4e5ac46 100644
--- a/models/triggers.js
+++ b/models/triggers.js
@@ -21,6 +21,12 @@ Triggers.allow({
Triggers.helpers({
+
+
+ getRule(){
+ return Rules.findOne({triggerId:this._id});
+ },
+
fromList() {
return Lists.findOne(this.fromId);
},
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
diff --git a/server/triggersDef.js b/server/triggersDef.js
new file mode 100644
index 00000000..5625122e
--- /dev/null
+++ b/server/triggersDef.js
@@ -0,0 +1,39 @@
+TriggersDef = {
+ createCard:{
+ matchingFields: ["boardId","listId"]
+ },
+ moveCard:{
+ matchingFields: ["boardId","listId","oldListId"]
+ },
+ archivedCard:{
+ matchingFields: ["boardId"]
+ }
+}
+
+
+ // if(activityType == "createCard"){
+
+ // }
+ // if(activityType == "moveCard"){
+
+ // }
+ // if(activityType == "archivedCard"){
+
+ // }
+ // if(activityType == "restoredCard"){
+
+ // }
+ // if(activityType == "joinMember"){
+
+ // }
+ // if(activityType == "unJoinMember"){
+
+ // }
+ // if(activityType == "addChecklist"){
+
+ // }
+ // if(activityType == "addChecklistItem"){
+
+ // }
+
+