mirror of
https://github.com/wekan/wekan.git
synced 2026-01-01 23:28:49 +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
|
|
@ -621,15 +621,12 @@ BlazeComponent.extendComponent({
|
||||||
if (!this.isTemplateSearch || this.isCardTemplateSearch) {
|
if (!this.isTemplateSearch || this.isCardTemplateSearch) {
|
||||||
// Card insertion
|
// Card insertion
|
||||||
// 1. Common
|
// 1. Common
|
||||||
element.boardId = this.boardId;
|
|
||||||
element.listId = this.listId;
|
|
||||||
element.swimlaneId = this.swimlaneId;
|
|
||||||
element.sort = Lists.findOne(this.listId).cards().count();
|
element.sort = Lists.findOne(this.listId).cards().count();
|
||||||
// 1.A From template
|
// 1.A From template
|
||||||
if (this.isTemplateSearch) {
|
if (this.isTemplateSearch) {
|
||||||
element.type = 'cardType-card';
|
element.type = 'cardType-card';
|
||||||
element.linkedId = '';
|
element.linkedId = '';
|
||||||
_id = element.copy();
|
_id = element.copy(this.boardId, this.swimlaneId, this.listId);
|
||||||
// 1.B Linked card
|
// 1.B Linked card
|
||||||
} else {
|
} else {
|
||||||
delete element._id;
|
delete element._id;
|
||||||
|
|
@ -640,21 +637,18 @@ BlazeComponent.extendComponent({
|
||||||
Filter.addException(_id);
|
Filter.addException(_id);
|
||||||
// List insertion
|
// List insertion
|
||||||
} else if (this.isListTemplateSearch) {
|
} else if (this.isListTemplateSearch) {
|
||||||
element.boardId = this.boardId;
|
|
||||||
element.sort = Swimlanes.findOne(this.swimlaneId).lists().count();
|
element.sort = Swimlanes.findOne(this.swimlaneId).lists().count();
|
||||||
element.type = 'list';
|
element.type = 'list';
|
||||||
_id = element.copy(this.swimlaneId);
|
_id = element.copy(this.boardId, this.swimlaneId);
|
||||||
} else if (this.isSwimlaneTemplateSearch) {
|
} else if (this.isSwimlaneTemplateSearch) {
|
||||||
element.boardId = this.boardId;
|
|
||||||
element.sort = Boards.findOne(this.boardId).swimlanes().count();
|
element.sort = Boards.findOne(this.boardId).swimlanes().count();
|
||||||
element.type = 'swimlalne';
|
element.type = 'swimlalne';
|
||||||
_id = element.copy();
|
_id = element.copy(this.boardId);
|
||||||
} else if (this.isBoardTemplateSearch) {
|
} else if (this.isBoardTemplateSearch) {
|
||||||
board = Boards.findOne(element.linkedId);
|
board = Boards.findOne(element.linkedId);
|
||||||
board.sort = Boards.find({archived: false}).count();
|
board.sort = Boards.find({archived: false}).count();
|
||||||
board.type = 'board';
|
board.type = 'board';
|
||||||
delete board.slug;
|
delete board.slug;
|
||||||
delete board.members;
|
|
||||||
_id = board.copy();
|
_id = board.copy();
|
||||||
}
|
}
|
||||||
Popup.close();
|
Popup.close();
|
||||||
|
|
|
||||||
|
|
@ -272,13 +272,32 @@ Cards.allow({
|
||||||
});
|
});
|
||||||
|
|
||||||
Cards.helpers({
|
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;
|
const oldId = this._id;
|
||||||
delete 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);
|
const _id = Cards.insert(this);
|
||||||
|
|
||||||
// copy checklists
|
// copy checklists
|
||||||
Checklists.find({cardId: oldId}).forEach((ch) => {
|
Checklists.find({cardId: oldId}).forEach((ch) => {
|
||||||
|
// REMOVE verify copy with arguments
|
||||||
ch.copy(_id);
|
ch.copy(_id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -286,11 +305,13 @@ Cards.helpers({
|
||||||
Cards.find({parentId: oldId}).forEach((subtask) => {
|
Cards.find({parentId: oldId}).forEach((subtask) => {
|
||||||
subtask.parentId = _id;
|
subtask.parentId = _id;
|
||||||
subtask._id = null;
|
subtask._id = null;
|
||||||
|
// REMOVE verify copy with arguments instead of insert?
|
||||||
Cards.insert(subtask);
|
Cards.insert(subtask);
|
||||||
});
|
});
|
||||||
|
|
||||||
// copy card comments
|
// copy card comments
|
||||||
CardComments.find({cardId: oldId}).forEach((cmt) => {
|
CardComments.find({cardId: oldId}).forEach((cmt) => {
|
||||||
|
// REMOVE verify copy with arguments
|
||||||
cmt.copy(_id);
|
cmt.copy(_id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,12 +137,15 @@ Lists.allow({
|
||||||
});
|
});
|
||||||
|
|
||||||
Lists.helpers({
|
Lists.helpers({
|
||||||
copy(swimlaneId) {
|
copy(boardId, swimlaneId) {
|
||||||
const oldId = this._id;
|
const oldId = this._id;
|
||||||
const oldSwimlaneId = this.swimlaneId || null;
|
const oldSwimlaneId = this.swimlaneId || null;
|
||||||
|
this.boardId = boardId;
|
||||||
|
this.swimlaneId = swimlaneId;
|
||||||
|
|
||||||
let _id = null;
|
let _id = null;
|
||||||
existingListWithSameName = Lists.findOne({
|
existingListWithSameName = Lists.findOne({
|
||||||
boardId: this.boardId,
|
boardId,
|
||||||
title: this.title,
|
title: this.title,
|
||||||
archived: false,
|
archived: false,
|
||||||
});
|
});
|
||||||
|
|
@ -160,11 +163,7 @@ Lists.helpers({
|
||||||
listId: oldId,
|
listId: oldId,
|
||||||
archived: false,
|
archived: false,
|
||||||
}).forEach((card) => {
|
}).forEach((card) => {
|
||||||
card.type = 'cardType-card';
|
card.copy(boardId, swimlaneId, _id);
|
||||||
card.listId = _id;
|
|
||||||
card.boardId = this.boardId;
|
|
||||||
card.swimlaneId = swimlaneId;
|
|
||||||
card.copy();
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,8 +101,10 @@ Swimlanes.allow({
|
||||||
});
|
});
|
||||||
|
|
||||||
Swimlanes.helpers({
|
Swimlanes.helpers({
|
||||||
copy(oldBoardId) {
|
copy(boardId) {
|
||||||
const oldId = this._id;
|
const oldId = this._id;
|
||||||
|
const oldBoardId = this.boardId;
|
||||||
|
this.boardId = boardId;
|
||||||
delete this._id;
|
delete this._id;
|
||||||
const _id = Swimlanes.insert(this);
|
const _id = Swimlanes.insert(this);
|
||||||
|
|
||||||
|
|
@ -118,8 +120,8 @@ Swimlanes.helpers({
|
||||||
Lists.find(query).forEach((list) => {
|
Lists.find(query).forEach((list) => {
|
||||||
list.type = 'list';
|
list.type = 'list';
|
||||||
list.swimlaneId = oldId;
|
list.swimlaneId = oldId;
|
||||||
list.boardId = this.boardId;
|
list.boardId = boardId;
|
||||||
list.copy(_id);
|
list.copy(boardId, _id);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue