diff options
Diffstat (limited to 'models/cards.js')
-rw-r--r-- | models/cards.js | 83 |
1 files changed, 75 insertions, 8 deletions
diff --git a/models/cards.js b/models/cards.js index 84fbb6c2..922fbecd 100644 --- a/models/cards.js +++ b/models/cards.js @@ -56,6 +56,14 @@ Cards.attachSchema(new SimpleSchema({ type: [String], optional: true, }, + startAt: { + type: Date, + optional: true, + }, + dueAt: { + type: Date, + optional: true, + }, // XXX Should probably be called `authorId`. Is it even needed since we have // the `members` field? userId: { @@ -133,6 +141,36 @@ Cards.helpers({ return cover && cover.url() && cover; }, + checklists() { + return Checklists.find({ cardId: this._id }, { sort: { createdAt: 1 }}); + }, + + checklistItemCount() { + const checklists = this.checklists().fetch(); + return checklists.map((checklist) => { + return checklist.itemCount(); + }).reduce((prev, next) => { + return prev + next; + }, 0); + }, + + checklistFinishedCount() { + const checklists = this.checklists().fetch(); + return checklists.map((checklist) => { + return checklist.finishedCount(); + }).reduce((prev, next) => { + return prev + next; + }, 0); + }, + + checklistFinished() { + return this.hasChecklist() && this.checklistItemCount() === this.checklistFinishedCount(); + }, + + hasChecklist() { + return this.checklistItemCount() !== 0; + }, + absoluteUrl() { const board = this.board(); return FlowRouter.url('card', { @@ -207,13 +245,29 @@ Cards.mutations({ unsetCover() { return { $unset: { coverId: '' }}; }, + + setStart(startAt) { + return { $set: { startAt }}; + }, + + unsetStart() { + return { $unset: { startAt: '' }}; + }, + + setDue(dueAt) { + return { $set: { dueAt }}; + }, + + unsetDue() { + return { $unset: { dueAt: '' }}; + }, }); if (Meteor.isServer) { // Cards are often fetched within a board, so we create an index to make these // queries more efficient. Meteor.startup(() => { - Cards._collection._ensureIndex({ boardId: 1 }); + Cards._collection._ensureIndex({ boardId: 1, createdAt: -1 }); }); Cards.after.insert((userId, doc) => { @@ -286,20 +340,33 @@ if (Meteor.isServer) { // Say goodbye to the former member if (modifier.$pull && modifier.$pull.members) { memberId = modifier.$pull.members; - Activities.insert({ - userId, - memberId, - activityType: 'unjoinMember', - boardId: doc.boardId, - cardId: doc._id, - }); + // Check that the former member is member of the card + if (_.contains(doc.members, memberId)) { + Activities.insert({ + userId, + memberId, + activityType: 'unjoinMember', + boardId: doc.boardId, + cardId: doc._id, + }); + } } }); // Remove all activities associated with a card if we remove the card + // Remove also card_comments / checklists / attachments Cards.after.remove((userId, doc) => { Activities.remove({ cardId: doc._id, }); + Checklists.remove({ + cardId: doc._id, + }); + CardComments.remove({ + cardId: doc._id, + }); + Attachments.remove({ + cardId: doc._id, + }); }); } |