mirror of
https://github.com/wekan/wekan.git
synced 2025-04-23 13:37:09 -04:00
Main flow implemented
This commit is contained in:
parent
9b0eb0a9f1
commit
6828ccd7f1
9 changed files with 100 additions and 15 deletions
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -43,14 +43,6 @@ Actions.helpers({
|
|||
|
||||
|
||||
|
||||
if (Meteor.isServer) {
|
||||
Meteor.startup(() => {
|
||||
const rules = Triggers.findOne({});
|
||||
if(!rules){
|
||||
Actions.insert({actionType: "moveCardToTop"});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -82,7 +82,7 @@ Lists.helpers({
|
|||
};
|
||||
if (swimlaneId)
|
||||
selector.swimlaneId = swimlaneId;
|
||||
return Cards.find(Filter.mongoSelector(selector),
|
||||
return Cards.find(selector,
|
||||
{ sort: ['sort'] });
|
||||
},
|
||||
|
||||
|
|
|
@ -21,6 +21,11 @@ Rules.mutations({
|
|||
},
|
||||
});
|
||||
|
||||
Rules.helpers({
|
||||
getAction(){
|
||||
return Actions.findOne({_id:this.actionId});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -21,6 +21,12 @@ Triggers.allow({
|
|||
|
||||
|
||||
Triggers.helpers({
|
||||
|
||||
|
||||
getRule(){
|
||||
return Rules.findOne({triggerId:this._id});
|
||||
},
|
||||
|
||||
fromList() {
|
||||
return Lists.findOne(this.fromId);
|
||||
},
|
||||
|
|
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;
|
||||
}
|
||||
|
||||
}
|
39
server/triggersDef.js
Normal file
39
server/triggersDef.js
Normal file
|
@ -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"){
|
||||
|
||||
// }
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue