diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/actions.js | 62 | ||||
-rw-r--r-- | models/activities.js | 11 | ||||
-rw-r--r-- | models/rules.js | 12 | ||||
-rw-r--r-- | models/triggers.js | 29 |
4 files changed, 74 insertions, 40 deletions
diff --git a/models/actions.js b/models/actions.js new file mode 100644 index 00000000..0961abbb --- /dev/null +++ b/models/actions.js @@ -0,0 +1,62 @@ +Actions = new Mongo.Collection('actions'); + + + +Actions.mutations({ + rename(description) { + return { $set: { description } }; + }, +}); + +Actions.allow({ + update: function () { + // add custom authentication code here + return true; + }, + insert: function () { + // add custom authentication code here + return true; + } +}); + + +Actions.helpers({ + fromList() { + return Lists.findOne(this.fromId); + }, + + toList() { + return Lists.findOne(this.toId); + }, + + findList(title) { + return Lists.findOne({title:title}); + }, + + labels() { + const boardLabels = this.board().labels; + const cardLabels = _.filter(boardLabels, (label) => { + return _.contains(this.labelIds, label._id); + }); + return cardLabels; + }}); + + + +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 5b54759c..beb741bc 100644 --- a/models/activities.js +++ b/models/activities.js @@ -56,6 +56,17 @@ Activities.before.insert((userId, doc) => { doc.createdAt = new Date(); }); + + +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"}}); + } +}); + 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/rules.js b/models/rules.js index df0cccea..778622c4 100644 --- a/models/rules.js +++ b/models/rules.js @@ -39,15 +39,3 @@ Rules.allow({ }, }); - - - -if (Meteor.isServer) { - Meteor.startup(() => { - const rules = Rules.findOne({}); - if(!rules){ - Rules.insert({title: "regola1", description: "bella"}); - Rules.insert({title: "regola2", description: "bella2"}); - } - }); -} diff --git a/models/triggers.js b/models/triggers.js index f8dbb50d..660d8b94 100644 --- a/models/triggers.js +++ b/models/triggers.js @@ -39,34 +39,7 @@ Triggers.helpers({ return _.contains(this.labelIds, label._id); }); return cardLabels; - }}); - - - -if (Meteor.isServer) { - Meteor.startup(() => { - const rules = Triggers.findOne({}); - if(!rules){ - Triggers.insert({group: "cards", activityType: "moveCard","fromId":-1,"toId":-1 }); - } - }); -} - - - - Activities.after.insert((userId, doc) => { - const activity = Activities._transform(doc); - const matchedTriggers = Triggers.find({activityType: activity.activityType,fromId:activity.oldListId,toId:activity.listId}) - if(matchedTriggers.count() > 0){ - const card = activity.card(); - const oldTitle = card.title; - const fromListTitle = activity.oldList().title; - Cards.direct.update({_id: card._id, listId: card.listId, boardId: card.boardId, archived: false}, - {$set: {title: "[From "+fromListTitle +"] "+ oldTitle}}); - } - }); - - +}}); |