summaryrefslogtreecommitdiffstats
path: root/models/cards.js
diff options
context:
space:
mode:
authorAndrés Manelli <andresmanelli@gmail.com>2019-02-27 20:45:58 +0100
committerAndrés Manelli <andresmanelli@gmail.com>2019-02-27 21:50:08 +0100
commitda21a2a410c9b905de89d66236748e0c8f5357ea (patch)
tree631efc1954e7be787576284ea55321dd7c424d97 /models/cards.js
parent904b5bf0f5f6e36131bf2d081a5d08fef408ac81 (diff)
downloadwekan-da21a2a410c9b905de89d66236748e0c8f5357ea.tar.gz
wekan-da21a2a410c9b905de89d66236748e0c8f5357ea.tar.bz2
wekan-da21a2a410c9b905de89d66236748e0c8f5357ea.zip
Standarize copy functions. Match labels by name
Diffstat (limited to 'models/cards.js')
-rw-r--r--models/cards.js23
1 files changed, 22 insertions, 1 deletions
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);
});