Create unique board names when importing

This commit is contained in:
John R. Supplee 2021-01-28 18:21:56 +02:00
parent 5adaaa7f22
commit ad6da9bf37
4 changed files with 22 additions and 17 deletions

View file

@ -129,7 +129,7 @@ BlazeComponent.extendComponent({
{ {
sort: Boards.find({ archived: false }).count(), sort: Boards.find({ archived: false }).count(),
type: 'board', type: 'board',
title: Boards.findOne(this.currentData()._id).copyTitle(), title: Boards.findOne(this.currentData()._id).title,
}, },
(err, res) => { (err, res) => {
if (err) { if (err) {

View file

@ -510,6 +510,7 @@ Boards.helpers({
const oldId = this._id; const oldId = this._id;
delete this._id; delete this._id;
delete this.slug; delete this.slug;
this.title = this.copyTitle();
const _id = Boards.insert(this); const _id = Boards.insert(this);
// Copy all swimlanes in board // Copy all swimlanes in board
@ -569,20 +570,7 @@ Boards.helpers({
* @returns {string|null} * @returns {string|null}
*/ */
copyTitle() { copyTitle() {
const m = this.title.match(/^(?<title>.*?)\s*(\[(?<num>\d+)]\s*$|\s*$)/); return Boards.uniqueTitle(this.title);
const title = escapeForRegex(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}]`;
}, },
/** /**
@ -1274,6 +1262,23 @@ function boardRemover(userId, doc) {
); );
} }
Boards.uniqueTitle = title => {
const m = title.match(/^(?<title>.*?)\s*(\[(?<num>\d+)]\s*$|\s*$)/);
const base = escapeForRegex(m.groups.title);
let num = 0;
Boards.find({ title: new RegExp(`^${base}\\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 `${base} [${num + 1}]`;
};
Boards.userSearch = ( Boards.userSearch = (
userId, userId,
selector = {}, selector = {},

View file

@ -177,7 +177,7 @@ export class TrelloCreator {
permission: this.getPermission(trelloBoard.prefs.permissionLevel), permission: this.getPermission(trelloBoard.prefs.permissionLevel),
slug: getSlug(trelloBoard.name) || 'board', slug: getSlug(trelloBoard.name) || 'board',
stars: 0, stars: 0,
title: trelloBoard.name, title: Boards.uniqueTitle(trelloBoard.name),
}; };
// now add other members // now add other members
if (trelloBoard.memberships) { if (trelloBoard.memberships) {

View file

@ -253,7 +253,7 @@ export class WekanCreator {
permission: boardToImport.permission, permission: boardToImport.permission,
slug: getSlug(boardToImport.title) || 'board', slug: getSlug(boardToImport.title) || 'board',
stars: 0, stars: 0,
title: boardToImport.title, title: Boards.uniqueTitle(boardToImport.title),
}; };
// now add other members // now add other members
if (boardToImport.members) { if (boardToImport.members) {