Use a Meteor call to copy a board

The current method was to copy a board on the client side.  But
not all data was available for copying rules.  Moving the copy
function to the server side solves this problem.
This commit is contained in:
John R. Supplee 2021-01-22 12:49:48 +02:00
parent 1c7a9e4de8
commit ff8a36653a
3 changed files with 30 additions and 6 deletions

View file

@ -675,12 +675,19 @@ BlazeComponent.extendComponent({
element.type = 'swimlane'; element.type = 'swimlane';
_id = element.copy(this.boardId); _id = element.copy(this.boardId);
} else if (this.isBoardTemplateSearch) { } else if (this.isBoardTemplateSearch) {
board = Boards.findOne(element.linkedId); Meteor.call(
board.sort = Boards.find({ archived: false }).count(); 'copyBoard',
board.type = 'board'; element.linkedId,
board.title = element.title; {
delete board.slug; sort: Boards.find({ archived: false }).count(),
_id = board.copy(); type: 'board',
title: element.title,
},
(err, data) => {
_id = data;
},
);
// _id = board.copy();
} }
Popup.close(); Popup.close();
}, },

View file

@ -508,6 +508,7 @@ Boards.helpers({
copy() { copy() {
const oldId = this._id; const oldId = this._id;
delete this._id; delete this._id;
delete this.slug;
const _id = Boards.insert(this); const _id = Boards.insert(this);
// Copy all swimlanes in board // Copy all swimlanes in board

View file

@ -209,3 +209,19 @@ Meteor.publishRelations('board', function(boardId, isArchived) {
return this.ready(); return this.ready();
}); });
Meteor.methods({
copyBoard(boardId, properties) {
check(boardId, String);
check(properties, Object);
const board = Boards.findOne(boardId);
if (board) {
for (const key in properties) {
board[key] = properties[key];
}
return board.copy();
}
return null;
},
});