mirror of
https://github.com/wekan/wekan.git
synced 2025-12-30 22:28:49 +01:00
Create unique board names when importing
This commit is contained in:
parent
5adaaa7f22
commit
ad6da9bf37
4 changed files with 22 additions and 17 deletions
|
|
@ -510,6 +510,7 @@ Boards.helpers({
|
|||
const oldId = this._id;
|
||||
delete this._id;
|
||||
delete this.slug;
|
||||
this.title = this.copyTitle();
|
||||
const _id = Boards.insert(this);
|
||||
|
||||
// Copy all swimlanes in board
|
||||
|
|
@ -569,20 +570,7 @@ Boards.helpers({
|
|||
* @returns {string|null}
|
||||
*/
|
||||
copyTitle() {
|
||||
const m = this.title.match(/^(?<title>.*?)\s*(\[(?<num>\d+)]\s*$|\s*$)/);
|
||||
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}]`;
|
||||
return Boards.uniqueTitle(this.title);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -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 = (
|
||||
userId,
|
||||
selector = {},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue