From da21a2a410c9b905de89d66236748e0c8f5357ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Manelli?= Date: Wed, 27 Feb 2019 20:45:58 +0100 Subject: Standarize copy functions. Match labels by name --- models/cards.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'models/cards.js') diff --git a/models/cards.js b/models/cards.js index c733c7f8..9dda6dae 100644 --- a/models/cards.js +++ b/models/cards.js @@ -272,13 +272,32 @@ Cards.allow({ }); Cards.helpers({ - copy() { + copy(boardId, swimlaneId, listId) { + const oldBoard = Boards.findOne(this.boardId); + const oldBoardLabels = oldBoard.labels; + // Get old label names + const oldCardLabels = _.pluck(_.filter(oldBoardLabels, (label) => { + return _.contains(this.labelIds, label._id); + }), 'name'); + + const newBoard = Boards.findOne(boardId); + const newBoardLabels = newBoard.labels; + const newCardLabels = _.pluck(_.filter(newBoardLabels, (label) => { + return _.contains(oldCardLabels, label.name); + }), '_id'); + const oldId = this._id; delete this._id; + delete this.labelIds; + this.labelIds= newCardLabels; + this.boardId = boardId; + this.swimlaneId = swimlaneId; + this.listId = listId; const _id = Cards.insert(this); // copy checklists Checklists.find({cardId: oldId}).forEach((ch) => { + // REMOVE verify copy with arguments ch.copy(_id); }); @@ -286,11 +305,13 @@ Cards.helpers({ Cards.find({parentId: oldId}).forEach((subtask) => { subtask.parentId = _id; subtask._id = null; + // REMOVE verify copy with arguments instead of insert? Cards.insert(subtask); }); // copy card comments CardComments.find({cardId: oldId}).forEach((cmt) => { + // REMOVE verify copy with arguments cmt.copy(_id); }); -- cgit v1.2.3-1-g7c22 From abb71083215462d91b084c4de13af0b130638e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Manelli?= Date: Wed, 27 Feb 2019 21:07:13 +0100 Subject: Copy template attachments --- models/cards.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'models/cards.js') diff --git a/models/cards.js b/models/cards.js index 9dda6dae..cf64cd9b 100644 --- a/models/cards.js +++ b/models/cards.js @@ -287,6 +287,8 @@ Cards.helpers({ }), '_id'); const oldId = this._id; + const oldCard = Cards.findOne(oldId); + delete this._id; delete this.labelIds; this.labelIds= newCardLabels; @@ -295,6 +297,13 @@ Cards.helpers({ this.listId = listId; const _id = Cards.insert(this); + // Copy attachments + oldCard.attachments().forEach((att) => { + att.cardId = _id; + delete att._id; + return Attachments.insert(att); + }); + // copy checklists Checklists.find({cardId: oldId}).forEach((ch) => { // REMOVE verify copy with arguments -- cgit v1.2.3-1-g7c22