mirror of
https://github.com/wekan/wekan.git
synced 2025-12-18 00:10:13 +01:00
Merge pull request #3154 from marc1006/issue_2970
Copy the labels only if the target board is different
This commit is contained in:
commit
39a8524354
1 changed files with 60 additions and 51 deletions
111
models/cards.js
111
models/cards.js
|
|
@ -368,30 +368,36 @@ Cards.allow({
|
||||||
|
|
||||||
Cards.helpers({
|
Cards.helpers({
|
||||||
copy(boardId, swimlaneId, listId) {
|
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;
|
||||||
const oldCard = Cards.findOne(oldId);
|
const oldCard = Cards.findOne(oldId);
|
||||||
|
|
||||||
// Copy Custom Fields
|
// we must only copy the labels and custom fields if the target board
|
||||||
if (oldBoard._id !== boardId) {
|
// differs from the source board
|
||||||
|
if (this.boardId !== boardId) {
|
||||||
|
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',
|
||||||
|
);
|
||||||
|
// now set the new label ids
|
||||||
|
delete this.labelIds;
|
||||||
|
this.labelIds = newCardLabels;
|
||||||
|
|
||||||
|
// Copy Custom Fields
|
||||||
CustomFields.find({
|
CustomFields.find({
|
||||||
_id: {
|
_id: {
|
||||||
$in: oldCard.customFields.map(cf => {
|
$in: oldCard.customFields.map(cf => {
|
||||||
|
|
@ -404,8 +410,6 @@ Cards.helpers({
|
||||||
}
|
}
|
||||||
|
|
||||||
delete this._id;
|
delete this._id;
|
||||||
delete this.labelIds;
|
|
||||||
this.labelIds = newCardLabels;
|
|
||||||
this.boardId = boardId;
|
this.boardId = boardId;
|
||||||
this.swimlaneId = swimlaneId;
|
this.swimlaneId = swimlaneId;
|
||||||
this.listId = listId;
|
this.listId = listId;
|
||||||
|
|
@ -1298,8 +1302,40 @@ Cards.mutations({
|
||||||
},
|
},
|
||||||
|
|
||||||
move(boardId, swimlaneId, listId, sort) {
|
move(boardId, swimlaneId, listId, sort) {
|
||||||
// Copy Custom Fields
|
const mutatedFields = {
|
||||||
|
boardId,
|
||||||
|
swimlaneId,
|
||||||
|
listId,
|
||||||
|
sort,
|
||||||
|
};
|
||||||
|
|
||||||
|
// we must only copy the labels and custom fields if the target board
|
||||||
|
// differs from the source board
|
||||||
if (this.boardId !== boardId) {
|
if (this.boardId !== boardId) {
|
||||||
|
// Get label names
|
||||||
|
const oldBoard = Boards.findOne(this.boardId);
|
||||||
|
const oldBoardLabels = oldBoard.labels;
|
||||||
|
const oldCardLabels = _.pluck(
|
||||||
|
_.filter(oldBoardLabels, label => {
|
||||||
|
return _.contains(this.labelIds, label._id);
|
||||||
|
}),
|
||||||
|
'name',
|
||||||
|
);
|
||||||
|
|
||||||
|
const newBoard = Boards.findOne(boardId);
|
||||||
|
const newBoardLabels = newBoard.labels;
|
||||||
|
const newCardLabelIds = _.pluck(
|
||||||
|
_.filter(newBoardLabels, label => {
|
||||||
|
return label.name && _.contains(oldCardLabels, label.name);
|
||||||
|
}),
|
||||||
|
'_id',
|
||||||
|
);
|
||||||
|
|
||||||
|
Object.assign(mutatedFields, {
|
||||||
|
labelIds: newCardLabelIds,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Copy custom fields
|
||||||
CustomFields.find({
|
CustomFields.find({
|
||||||
_id: {
|
_id: {
|
||||||
$in: this.customFields.map(cf => {
|
$in: this.customFields.map(cf => {
|
||||||
|
|
@ -1311,33 +1347,6 @@ Cards.mutations({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get label names
|
|
||||||
const oldBoard = Boards.findOne(this.boardId);
|
|
||||||
const oldBoardLabels = oldBoard.labels;
|
|
||||||
const oldCardLabels = _.pluck(
|
|
||||||
_.filter(oldBoardLabels, label => {
|
|
||||||
return _.contains(this.labelIds, label._id);
|
|
||||||
}),
|
|
||||||
'name',
|
|
||||||
);
|
|
||||||
|
|
||||||
const newBoard = Boards.findOne(boardId);
|
|
||||||
const newBoardLabels = newBoard.labels;
|
|
||||||
const newCardLabelIds = _.pluck(
|
|
||||||
_.filter(newBoardLabels, label => {
|
|
||||||
return label.name && _.contains(oldCardLabels, label.name);
|
|
||||||
}),
|
|
||||||
'_id',
|
|
||||||
);
|
|
||||||
|
|
||||||
const mutatedFields = {
|
|
||||||
boardId,
|
|
||||||
swimlaneId,
|
|
||||||
listId,
|
|
||||||
sort,
|
|
||||||
labelIds: newCardLabelIds,
|
|
||||||
};
|
|
||||||
|
|
||||||
Cards.update(this._id, {
|
Cards.update(this._id, {
|
||||||
$set: mutatedFields,
|
$set: mutatedFields,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue