mirror of
https://github.com/wekan/wekan.git
synced 2026-03-07 14:20:15 +01:00
Standarize copy functions. Match labels by name
This commit is contained in:
parent
904b5bf0f5
commit
da21a2a410
4 changed files with 36 additions and 20 deletions
|
|
@ -272,13 +272,32 @@ Cards.allow({
|
|||
});
|
||||
|
||||
Cards.helpers({
|
||||
copy() {
|
||||
copy(boardId, swimlaneId, listId) {
|
||||
const oldBoard = Boards.findOne(this.boardId);
|
||||
const oldBoardLabels = oldBoard.labels;
|
||||
// Get old label names
|
||||
const oldCardLabels = _.pluck(_.filter(oldBoardLabels, (label) => {
|
||||
return _.contains(this.labelIds, label._id);
|
||||
}), 'name');
|
||||
|
||||
const newBoard = Boards.findOne(boardId);
|
||||
const newBoardLabels = newBoard.labels;
|
||||
const newCardLabels = _.pluck(_.filter(newBoardLabels, (label) => {
|
||||
return _.contains(oldCardLabels, label.name);
|
||||
}), '_id');
|
||||
|
||||
const oldId = this._id;
|
||||
delete this._id;
|
||||
delete this.labelIds;
|
||||
this.labelIds= newCardLabels;
|
||||
this.boardId = boardId;
|
||||
this.swimlaneId = swimlaneId;
|
||||
this.listId = listId;
|
||||
const _id = Cards.insert(this);
|
||||
|
||||
// copy checklists
|
||||
Checklists.find({cardId: oldId}).forEach((ch) => {
|
||||
// REMOVE verify copy with arguments
|
||||
ch.copy(_id);
|
||||
});
|
||||
|
||||
|
|
@ -286,11 +305,13 @@ Cards.helpers({
|
|||
Cards.find({parentId: oldId}).forEach((subtask) => {
|
||||
subtask.parentId = _id;
|
||||
subtask._id = null;
|
||||
// REMOVE verify copy with arguments instead of insert?
|
||||
Cards.insert(subtask);
|
||||
});
|
||||
|
||||
// copy card comments
|
||||
CardComments.find({cardId: oldId}).forEach((cmt) => {
|
||||
// REMOVE verify copy with arguments
|
||||
cmt.copy(_id);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -137,12 +137,15 @@ Lists.allow({
|
|||
});
|
||||
|
||||
Lists.helpers({
|
||||
copy(swimlaneId) {
|
||||
copy(boardId, swimlaneId) {
|
||||
const oldId = this._id;
|
||||
const oldSwimlaneId = this.swimlaneId || null;
|
||||
this.boardId = boardId;
|
||||
this.swimlaneId = swimlaneId;
|
||||
|
||||
let _id = null;
|
||||
existingListWithSameName = Lists.findOne({
|
||||
boardId: this.boardId,
|
||||
boardId,
|
||||
title: this.title,
|
||||
archived: false,
|
||||
});
|
||||
|
|
@ -160,11 +163,7 @@ Lists.helpers({
|
|||
listId: oldId,
|
||||
archived: false,
|
||||
}).forEach((card) => {
|
||||
card.type = 'cardType-card';
|
||||
card.listId = _id;
|
||||
card.boardId = this.boardId;
|
||||
card.swimlaneId = swimlaneId;
|
||||
card.copy();
|
||||
card.copy(boardId, swimlaneId, _id);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -101,8 +101,10 @@ Swimlanes.allow({
|
|||
});
|
||||
|
||||
Swimlanes.helpers({
|
||||
copy(oldBoardId) {
|
||||
copy(boardId) {
|
||||
const oldId = this._id;
|
||||
const oldBoardId = this.boardId;
|
||||
this.boardId = boardId;
|
||||
delete this._id;
|
||||
const _id = Swimlanes.insert(this);
|
||||
|
||||
|
|
@ -118,8 +120,8 @@ Swimlanes.helpers({
|
|||
Lists.find(query).forEach((list) => {
|
||||
list.type = 'list';
|
||||
list.swimlaneId = oldId;
|
||||
list.boardId = this.boardId;
|
||||
list.copy(_id);
|
||||
list.boardId = boardId;
|
||||
list.copy(boardId, _id);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue