diff options
author | Lauri Ojansivu <x@xet7.org> | 2018-09-16 03:33:45 +0300 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2018-09-16 03:33:45 +0300 |
commit | b23cbbf9259ac535129cbf431cefe18fa774dd7f (patch) | |
tree | 9e4cccadff9a228f6525fd5722da3a3f290d1ff7 /models/checklistItems.js | |
parent | 053757f135b54241b4899a83cd3bb749b1e81bc9 (diff) | |
parent | 4f299b72f731ffb836871cd19361a6359e3bdfed (diff) | |
download | wekan-b23cbbf9259ac535129cbf431cefe18fa774dd7f.tar.gz wekan-b23cbbf9259ac535129cbf431cefe18fa774dd7f.tar.bz2 wekan-b23cbbf9259ac535129cbf431cefe18fa774dd7f.zip |
Merge branch 'Angtrim-feature-rules' into devel
Diffstat (limited to 'models/checklistItems.js')
-rw-r--r-- | models/checklistItems.js | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/models/checklistItems.js b/models/checklistItems.js index e075eda2..8380bda7 100644 --- a/models/checklistItems.js +++ b/models/checklistItems.js @@ -44,6 +44,12 @@ ChecklistItems.mutations({ setTitle(title) { return { $set: { title } }; }, + check(){ + return { $set: { isFinished: true } }; + }, + uncheck(){ + return { $set: { isFinished: false } }; + }, toggleItem() { return { $set: { isFinished: !this.isFinished } }; }, @@ -70,21 +76,100 @@ function itemCreation(userId, doc) { boardId, checklistId: doc.checklistId, checklistItemId: doc._id, + checklistItemName:doc.title, }); } function itemRemover(userId, doc) { + const card = Cards.findOne(doc.cardId); + const boardId = card.boardId; + Activities.insert({ + userId, + activityType: 'removedChecklistItem', + cardId: doc.cardId, + boardId, + checklistId: doc.checklistId, + checklistItemId: doc._id, + checklistItemName:doc.title, + }); Activities.remove({ checklistItemId: doc._id, }); } +function publishCheckActivity(userId, doc){ + const card = Cards.findOne(doc.cardId); + const boardId = card.boardId; + let activityType; + if(doc.isFinished){ + activityType = 'checkedItem'; + }else{ + activityType = 'uncheckedItem'; + } + const act = { + userId, + activityType, + cardId: doc.cardId, + boardId, + checklistId: doc.checklistId, + checklistItemId: doc._id, + checklistItemName:doc.title, + }; + Activities.insert(act); +} + +function publishChekListCompleted(userId, doc, fieldNames, modifier){ + const card = Cards.findOne(doc.cardId); + const boardId = card.boardId; + const checklistId = doc.checklistId; + const checkList = Checklists.findOne({_id:checklistId}); + if(checkList.isFinished()){ + const act = { + userId, + activityType: 'checklistCompleted', + cardId: doc.cardId, + boardId, + checklistId: doc.checklistId, + checklistName:doc.title, + }; + Activities.insert(act); + } +} + +function publishChekListUncompleted(userId, doc, fieldNames, modifier){ + const card = Cards.findOne(doc.cardId); + const boardId = card.boardId; + const checklistId = doc.checklistId; + const checkList = Checklists.findOne({_id:checklistId}); + if(checkList.isFinished()){ + const act = { + userId, + activityType: 'checklistUncompleted', + cardId: doc.cardId, + boardId, + checklistId: doc.checklistId, + checklistName:doc.title, + }; + Activities.insert(act); + } +} + // Activities if (Meteor.isServer) { Meteor.startup(() => { ChecklistItems._collection._ensureIndex({ checklistId: 1 }); }); + ChecklistItems.after.update((userId, doc, fieldNames, modifier) => { + publishCheckActivity(userId, doc); + publishChekListCompleted(userId, doc, fieldNames, modifier); + }); + + ChecklistItems.before.update((userId, doc, fieldNames, modifier) => { + publishChekListUncompleted(userId, doc, fieldNames, modifier); + }); + + ChecklistItems.after.insert((userId, doc) => { itemCreation(userId, doc); }); |