diff --git a/models/cards.js b/models/cards.js index 712f18e11..5b006775b 100644 --- a/models/cards.js +++ b/models/cards.js @@ -1527,14 +1527,17 @@ Cards.mutations({ return this.move(boardId, swimlaneId, listId, sort); }, - move(boardId, swimlaneId, listId, sort) { + move(boardId, swimlaneId, listId, sort=null) { const mutatedFields = { boardId, swimlaneId, listId, - sort, }; + if (sort !== null) { + mutatedFields.sort = sort; + } + // we must only copy the labels and custom fields if the target board // differs from the source board if (this.boardId !== boardId) { diff --git a/models/lists.js b/models/lists.js index 141804492..c783746d4 100644 --- a/models/lists.js +++ b/models/lists.js @@ -297,6 +297,36 @@ Lists.mutations({ return { $set: { starred: !!enable } }; }, + move(boardId, swimlaneId, sort=null) { + const mutatedFields = { + boardId, + swimlaneId, + sort, + }; + + if (this.boardId !== boardId) { + mutatedFields.boardId = boardId; + } + + if (this.swimlaneId !== swimlaneId) { + mutatedFields.swimlaneId = swimlaneId; + } + + if (sort !== null && sort !== this.sort) { + mutatedFields.sort = sort; + } + + if (Object.keys(mutatedFields).length) { + this.cards().forEach(card => { + card.move(boardId, swimlaneId, this._id); + }); + + Lists.update(this._id, { + $set: mutatedFields, + }); + } + }, + archive() { if (this.isTemplateList()) { this.cards().forEach(card => { diff --git a/models/swimlanes.js b/models/swimlanes.js index 8cb0c8e9c..7ac89b06d 100644 --- a/models/swimlanes.js +++ b/models/swimlanes.js @@ -269,6 +269,29 @@ Swimlanes.mutations({ return { $set: { archived: true, archivedAt: new Date() } }; }, + move(boardId, sort=null) { + const mutatedFields = {}; + + if (this.boardId !== boardId) { + mutatedFields.boardId = boardId; + } + + if (sort !== null && sort !== this.sort) { + mutatedFields.sort = sort; + } + + if (Object.keys(mutatedFields).length) { + this.lists().forEach(list => { + list.move(boardId, this._id); + }); + + Swimlanes.update(this._id, { + $set: mutatedFields, + }); + } + + }, + restore() { if (this.isTemplateSwimlane()) { this.myLists().forEach(list => {