diff --git a/client/components/boards/boardsList.js b/client/components/boards/boardsList.js index 145f67892..14174938a 100644 --- a/client/components/boards/boardsList.js +++ b/client/components/boards/boardsList.js @@ -124,9 +124,13 @@ BlazeComponent.extendComponent({ }, 'click .js-clone-board'(evt) { Meteor.call( - 'cloneBoard', + 'copyBoard', this.currentData()._id, - Session.get('fromBoard'), + { + sort: Boards.find({ archived: false }).count(), + type: 'board', + title: Boards.findOne(this.currentData()._id).copyTitle(), + }, (err, res) => { if (err) { this.setError(err.error); diff --git a/client/components/lists/listBody.js b/client/components/lists/listBody.js index 45e8e506f..f607219fd 100644 --- a/client/components/lists/listBody.js +++ b/client/components/lists/listBody.js @@ -687,7 +687,6 @@ BlazeComponent.extendComponent({ _id = data; }, ); - // _id = board.copy(); } Popup.close(); }, diff --git a/models/boards.js b/models/boards.js index 4069489fa..cf1e8da08 100644 --- a/models/boards.js +++ b/models/boards.js @@ -562,6 +562,28 @@ Boards.helpers({ Rules.insert(rule); }); }, + /** + * Return a unique title based on the current title + * + * @returns {string|null} + */ + copyTitle() { + const m = this.title.match(/^(?.*?)\s*(\[(?<num>\d+)]\s*$|\s*$)/); + const title = m.groups.title; + let num = 0; + Boards.find({ title: new RegExp(`^${title}\\s*\\[\\d+]\\s*$`) }).forEach( + board => { + const m = board.title.match(/^(?<title>.*?)\s*\[(?<num>\d+)]\s*$/); + if (m) { + const n = parseInt(m.groups.num, 10); + num = num < n ? n : num; + } + }, + ); + + return `${title} [${num + 1}]`; + }, + /** * Is supplied user authorized to view this board? */