From f63482b58775a2f52fdd5f932ce7d14f16757133 Mon Sep 17 00:00:00 2001 From: Angelo Gallarello Date: Fri, 3 Aug 2018 19:47:20 +0200 Subject: UI for rules list --- models/.DS_Store | Bin 0 -> 6148 bytes models/cards.js | 1 + models/rules.js | 38 +++++++++++++++++++++++++++ models/triggers.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 models/.DS_Store create mode 100644 models/rules.js create mode 100644 models/triggers.js (limited to 'models') diff --git a/models/.DS_Store b/models/.DS_Store new file mode 100644 index 00000000..5008ddfc Binary files /dev/null and b/models/.DS_Store differ diff --git a/models/cards.js b/models/cards.js index b6a7b4c6..618c191e 100644 --- a/models/cards.js +++ b/models/cards.js @@ -806,3 +806,4 @@ if (Meteor.isServer) { }); } + diff --git a/models/rules.js b/models/rules.js new file mode 100644 index 00000000..2304d2dc --- /dev/null +++ b/models/rules.js @@ -0,0 +1,38 @@ +Rules = new Mongo.Collection('rules'); + +Rules.attachSchema(new SimpleSchema({ + title: { + type: String, + optional: true, + }, + description: { + type: String, + optional: true, + }, +})); + +Rules.mutations({ + rename(description) { + return { $set: { description } }; + }, +}); + +Rules.allow({ + update: function () { + // add custom authentication code here + return true; + }, +}); + + + + +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 new file mode 100644 index 00000000..f8dbb50d --- /dev/null +++ b/models/triggers.js @@ -0,0 +1,74 @@ +Triggers = new Mongo.Collection('triggers'); + + + +Triggers.mutations({ + rename(description) { + return { $set: { description } }; + }, +}); + +Triggers.allow({ + update: function () { + // add custom authentication code here + return true; + }, + insert: function () { + // add custom authentication code here + return true; + } +}); + + +Triggers.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){ + 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}}); + } + }); + + + + + + + -- cgit v1.2.3-1-g7c22