From dc7286a0ef8111c0855129911492588ba8a384df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Manelli?= Date: Mon, 25 Feb 2019 22:48:25 +0100 Subject: Fix list view issues. Allow creation of boards from templates --- models/boards.js | 36 ++++++++++++++++++++++++++++++++++++ models/cardComments.js | 2 +- models/cards.js | 2 +- models/lists.js | 6 +++++- models/swimlanes.js | 19 ++++++++++++------- 5 files changed, 55 insertions(+), 10 deletions(-) (limited to 'models') diff --git a/models/boards.js b/models/boards.js index 0d3213bc..0db2e48e 100644 --- a/models/boards.js +++ b/models/boards.js @@ -315,6 +315,21 @@ Boards.attachSchema(new SimpleSchema({ Boards.helpers({ + copy() { + const oldId = this._id; + delete this._id; + const _id = Boards.insert(this); + + // Copy all swimlanes in board + Swimlanes.find({ + boardId: oldId, + archived: false, + }).forEach((swimlane) => { + swimlane.type = 'swimlane'; + swimlane.boardId = _id; + swimlane.copy(oldId); + }); + }, /** * Is supplied user authorized to view this board? */ @@ -463,6 +478,27 @@ Boards.helpers({ return _id; }, + searchBoards(term) { + check(term, Match.OneOf(String, null, undefined)); + + const query = { boardId: this._id }; + query.type = 'cardType-linkedBoard'; + query.archived = false; + + const projection = { limit: 10, sort: { createdAt: -1 } }; + + if (term) { + const regex = new RegExp(term, 'i'); + + query.$or = [ + { title: regex }, + { description: regex }, + ]; + } + + return Cards.find(query, projection); + }, + searchSwimlanes(term) { check(term, Match.OneOf(String, null, undefined)); diff --git a/models/cardComments.js b/models/cardComments.js index f29366a5..fcb97104 100644 --- a/models/cardComments.js +++ b/models/cardComments.js @@ -69,7 +69,7 @@ CardComments.allow({ CardComments.helpers({ copy(newCardId) { this.cardId = newCardId; - this._id = null; + delete this._id; CardComments.insert(this); }, diff --git a/models/cards.js b/models/cards.js index e91f0af5..c733c7f8 100644 --- a/models/cards.js +++ b/models/cards.js @@ -274,7 +274,7 @@ Cards.allow({ Cards.helpers({ copy() { const oldId = this._id; - this._id = null; + delete this._id; const _id = Cards.insert(this); // copy checklists diff --git a/models/lists.js b/models/lists.js index bf2430ee..d76c961c 100644 --- a/models/lists.js +++ b/models/lists.js @@ -139,20 +139,24 @@ Lists.allow({ Lists.helpers({ copy(swimlaneId) { const oldId = this._id; + const oldSwimlaneId = this.swimlaneId || null; let _id = null; existingListWithSameName = Lists.findOne({ boardId: this.boardId, title: this.title, + archived: false, }); if (existingListWithSameName) { _id = existingListWithSameName._id; } else { - this._id = null; + delete this._id; + delete this.swimlaneId; _id = Lists.insert(this); } // Copy all cards in list Cards.find({ + swimlaneId: oldSwimlaneId, listId: oldId, archived: false, }).forEach((card) => { diff --git a/models/swimlanes.js b/models/swimlanes.js index d3548329..a3427fc6 100644 --- a/models/swimlanes.js +++ b/models/swimlanes.js @@ -101,18 +101,23 @@ Swimlanes.allow({ }); Swimlanes.helpers({ - copy() { + copy(oldBoardId) { const oldId = this._id; - this._id = null; + delete this._id; const _id = Swimlanes.insert(this); - // Copy all lists in swimlane - Lists.find({ - swimlaneId: oldId, + const query = { + swimlaneId: {$in: [oldId, '']}, archived: false, - }).forEach((list) => { + }; + if (oldBoardId) { + query.boardId = oldBoardId; + } + + // Copy all lists in swimlane + Lists.find(query).forEach((list) => { list.type = 'list'; - list.swimlaneId = ''; + list.swimlaneId = oldId; list.boardId = this.boardId; list.copy(_id); }); -- cgit v1.2.3-1-g7c22