From 04745f0c2fe83f044032713e1864c5ac00d38ac9 Mon Sep 17 00:00:00 2001 From: Nicu Tofan Date: Mon, 25 Jun 2018 22:01:02 +0300 Subject: implement getDefaultSwimline for boards --- client/components/cards/subtasks.js | 2 +- client/components/lists/listBody.js | 2 +- models/boards.js | 12 ++++++++++++ server/migrations.js | 10 +--------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/client/components/cards/subtasks.js b/client/components/cards/subtasks.js index 087824f7..335eba36 100644 --- a/client/components/cards/subtasks.js +++ b/client/components/cards/subtasks.js @@ -16,7 +16,7 @@ BlazeComponent.extendComponent({ const crtBoard = Boards.findOne(card.boardId); const targetBoard = crtBoard.getDefaultSubtasksBoard(); const listId = targetBoard.getDefaultSubtasksListId(); - const swimlaneId = Swimlanes.findOne({boardId: targetBoard._id})._id; + const swimlaneId = targetBoard.getDefaultSwimline()._id; if (title) { const _id = Cards.insert({ diff --git a/client/components/lists/listBody.js b/client/components/lists/listBody.js index 4bf7b369..34aeb8a8 100644 --- a/client/components/lists/listBody.js +++ b/client/components/lists/listBody.js @@ -46,7 +46,7 @@ BlazeComponent.extendComponent({ if (boardView === 'board-view-swimlanes') swimlaneId = this.parentComponent().parentComponent().data()._id; else if (boardView === 'board-view-lists') - swimlaneId = Swimlanes.findOne({boardId})._id; + swimlaneId = this.data().board().getDefaultSwimline()._id; if (title) { const _id = Cards.insert({ diff --git a/models/boards.js b/models/boards.js index 6f0f7293..a8b7191e 100644 --- a/models/boards.js +++ b/models/boards.js @@ -337,6 +337,18 @@ Boards.helpers({ getDefaultSubtasksList() { return Lists.findOne(this.getDefaultSubtasksListId()); }, + + getDefaultSwimline() { + let result = Swimlanes.findOne({boardId: this._id}); + if (result === undefined) { + Swimlanes.insert({ + title: TAPi18n.__('default'), + boardId: this._id, + }); + result = Swimlanes.findOne({boardId: this._id}); + } + return result; + }, }); diff --git a/server/migrations.js b/server/migrations.js index c49581f5..af866d13 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -154,15 +154,7 @@ Migrations.add('add-sort-checklists', () => { Migrations.add('add-swimlanes', () => { Boards.find().forEach((board) => { - const swimlane = Swimlanes.findOne({ boardId: board._id }); - let swimlaneId = ''; - if (swimlane) - swimlaneId = swimlane._id; - else - swimlaneId = Swimlanes.direct.insert({ - boardId: board._id, - title: 'Default', - }); + const swimlaneId = board.getDefaultSwimline()._id; Cards.find({ boardId: board._id }).forEach((card) => { if (!card.hasOwnProperty('swimlaneId')) { -- cgit v1.2.3-1-g7c22