diff options
author | Lauri Ojansivu <x@xet7.org> | 2019-02-28 00:54:29 +0200 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2019-02-28 00:54:29 +0200 |
commit | eeb8d4b3de39658f1ed9927cc85a968a9b9fe8c4 (patch) | |
tree | f46123f64a068ee1d6ed6c2f05ac990abdc7a1a5 /models | |
parent | 82a728df7111413e4a1b106f4cd18265da5f397b (diff) | |
parent | ad75c541cff2c27c441a0fb67d52c57180020594 (diff) | |
download | wekan-eeb8d4b3de39658f1ed9927cc85a968a9b9fe8c4.tar.gz wekan-eeb8d4b3de39658f1ed9927cc85a968a9b9fe8c4.tar.bz2 wekan-eeb8d4b3de39658f1ed9927cc85a968a9b9fe8c4.zip |
Merge branch 'edge' into meteor-1.8
Diffstat (limited to 'models')
-rw-r--r-- | models/boards.js | 3 | ||||
-rw-r--r-- | models/cards.js | 32 | ||||
-rw-r--r-- | models/lists.js | 13 | ||||
-rw-r--r-- | models/swimlanes.js | 8 |
4 files changed, 43 insertions, 13 deletions
diff --git a/models/boards.js b/models/boards.js index 0db2e48e..9a71ede8 100644 --- a/models/boards.js +++ b/models/boards.js @@ -326,8 +326,7 @@ Boards.helpers({ archived: false, }).forEach((swimlane) => { swimlane.type = 'swimlane'; - swimlane.boardId = _id; - swimlane.copy(oldId); + swimlane.copy(_id); }); }, /** diff --git a/models/cards.js b/models/cards.js index c733c7f8..cf64cd9b 100644 --- a/models/cards.js +++ b/models/cards.js @@ -272,13 +272,41 @@ 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; + const oldCard = Cards.findOne(oldId); + delete this._id; + delete this.labelIds; + this.labelIds= newCardLabels; + this.boardId = boardId; + this.swimlaneId = swimlaneId; + 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 ch.copy(_id); }); @@ -286,11 +314,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); }); diff --git a/models/lists.js b/models/lists.js index d76c961c..a8e597ee 100644 --- a/models/lists.js +++ b/models/lists.js @@ -137,12 +137,15 @@ Lists.allow({ }); Lists.helpers({ - copy(swimlaneId) { + copy(boardId, swimlaneId) { const oldId = this._id; const oldSwimlaneId = this.swimlaneId || null; + this.boardId = boardId; + this.swimlaneId = swimlaneId; + let _id = null; existingListWithSameName = Lists.findOne({ - boardId: this.boardId, + boardId, title: this.title, archived: false, }); @@ -160,11 +163,7 @@ Lists.helpers({ listId: oldId, archived: false, }).forEach((card) => { - card.type = 'cardType-card'; - card.listId = _id; - card.boardId = this.boardId; - card.swimlaneId = swimlaneId; - card.copy(); + card.copy(boardId, swimlaneId, _id); }); }, diff --git a/models/swimlanes.js b/models/swimlanes.js index a3427fc6..1b18ba5d 100644 --- a/models/swimlanes.js +++ b/models/swimlanes.js @@ -101,8 +101,10 @@ Swimlanes.allow({ }); Swimlanes.helpers({ - copy(oldBoardId) { + copy(boardId) { const oldId = this._id; + const oldBoardId = this.boardId; + this.boardId = boardId; delete this._id; const _id = Swimlanes.insert(this); @@ -118,8 +120,8 @@ Swimlanes.helpers({ Lists.find(query).forEach((list) => { list.type = 'list'; list.swimlaneId = oldId; - list.boardId = this.boardId; - list.copy(_id); + list.boardId = boardId; + list.copy(boardId, _id); }); }, |