From 0fec7115451ba3b49442965c8160df4911157601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Manelli?= Date: Sat, 23 Feb 2019 16:36:29 +0100 Subject: Prepare to create card from template --- models/boards.js | 2 ++ models/cardComments.js | 6 ++++++ models/cards.js | 25 +++++++++++++++++++++++++ models/checklists.js | 13 +++++++++++++ 4 files changed, 46 insertions(+) (limited to 'models') diff --git a/models/boards.js b/models/boards.js index c17c7351..25cf5e37 100644 --- a/models/boards.js +++ b/models/boards.js @@ -473,6 +473,8 @@ Boards.helpers({ if (this.isTemplatesBoard()) { query.type = 'template-card'; query.archived = false; + } else { + query.type = {$nin: ['template-card']}; } const projection = { limit: 10, sort: { createdAt: -1 } }; diff --git a/models/cardComments.js b/models/cardComments.js index 974c5ec9..f29366a5 100644 --- a/models/cardComments.js +++ b/models/cardComments.js @@ -67,6 +67,12 @@ CardComments.allow({ }); CardComments.helpers({ + copy(newCardId) { + this.cardId = newCardId; + this._id = null; + CardComments.insert(this); + }, + user() { return Users.findOne(this.userId); }, diff --git a/models/cards.js b/models/cards.js index e9fc453e..c7b4a366 100644 --- a/models/cards.js +++ b/models/cards.js @@ -272,6 +272,31 @@ Cards.allow({ }); Cards.helpers({ + copy() { + const oldId = this._id; + this._id = null; + const _id = Cards.insert(this); + + // copy checklists + Checklists.find({cardId: oldId}).forEach((ch) => { + ch.copy(_id); + }); + + // copy subtasks + Cards.find({parentId: oldId}).forEach((subtask) => { + subtask.parentId = _id; + subtask._id = null; + Cards.insert(subtask); + }); + + // copy card comments + CardComments.find({cardId: oldId}).forEach((cmt) => { + cmt.copy(_id); + }); + + return _id; + }, + list() { return Lists.findOne(this.listId); }, diff --git a/models/checklists.js b/models/checklists.js index a372fafa..99e9f25e 100644 --- a/models/checklists.js +++ b/models/checklists.js @@ -48,6 +48,19 @@ Checklists.attachSchema(new SimpleSchema({ })); Checklists.helpers({ + copy(newCardId) { + const oldChecklistId = this._id; + this._id = null; + this.cardId = newCardId; + const newChecklistId = Checklists.insert(this); + ChecklistItems.find({checklistId: oldChecklistId}).forEach((item) => { + item._id = null; + item.checklistId = newChecklistId; + item.cardId = newCardId; + ChecklistItems.insert(item); + }); + }, + itemCount() { return ChecklistItems.find({ checklistId: this._id }).count(); }, -- cgit v1.2.3-1-g7c22