summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/boards.js4
-rw-r--r--models/cards.js41
2 files changed, 45 insertions, 0 deletions
diff --git a/models/boards.js b/models/boards.js
index 76a8f704..c77c9de2 100644
--- a/models/boards.js
+++ b/models/boards.js
@@ -254,6 +254,10 @@ Boards.helpers({
return _.findWhere(this.labels, { name, color });
},
+ getLabelById(labelId){
+ return _.findWhere(this.labels, { _id: labelId });
+ },
+
labelIndex(labelId) {
return _.pluck(this.labels, '_id').indexOf(labelId);
},
diff --git a/models/cards.js b/models/cards.js
index 618c191e..364f5a39 100644
--- a/models/cards.js
+++ b/models/cards.js
@@ -624,6 +624,41 @@ function cardMembers(userId, doc, fieldNames, modifier) {
}
}
+function cardLabels(userId, doc, fieldNames, modifier) {
+ if (!_.contains(fieldNames, 'labelIds'))
+ return;
+ let labelId;
+ // Say hello to the new label
+ if (modifier.$addToSet && modifier.$addToSet.labelIds) {
+ labelId = modifier.$addToSet.labelIds;
+ if (!_.contains(doc.labelIds, labelId)) {
+ const act = {
+ userId,
+ labelId,
+ activityType: 'addedLabel',
+ boardId: doc.boardId,
+ cardId: doc._id,
+ }
+ Activities.insert(act);
+ }
+ }
+
+ // Say goodbye to the label
+ if (modifier.$pull && modifier.$pull.labelIds) {
+ labelId = modifier.$pull.labelIds;
+ // Check that the former member is member of the card
+ if (_.contains(doc.labelIds, labelId)) {
+ Activities.insert({
+ userId,
+ labelId,
+ activityType: 'removedLabel',
+ boardId: doc.boardId,
+ cardId: doc._id,
+ });
+ }
+ }
+}
+
function cardCreation(userId, doc) {
Activities.insert({
userId,
@@ -680,6 +715,12 @@ if (Meteor.isServer) {
cardMembers(userId, doc, fieldNames, modifier);
});
+ // Add a new activity if we add or remove a label to the card
+ Cards.before.update((userId, doc, fieldNames, modifier) => {
+ cardLabels(userId, doc, fieldNames, modifier);
+ });
+
+
// Remove all activities associated with a card if we remove the card
// Remove also card_comments / checklists / attachments
Cards.after.remove((userId, doc) => {