mirror of
https://github.com/wekan/wekan.git
synced 2025-04-22 04:57:07 -04:00
Merge pull request #3936 from syndimann/feature/boardwise-card-numbers
Fix: Consecutive Card numbering when a card is moved to another board or copied
This commit is contained in:
commit
f01b440fb7
2 changed files with 22 additions and 2 deletions
|
@ -1065,8 +1065,23 @@ Boards.helpers({
|
|||
},
|
||||
|
||||
getNextCardNumber() {
|
||||
const boardCards = Cards.find({ boardId: this._id }).fetch();
|
||||
return boardCards.length + 1;
|
||||
const boardCards = Cards.find(
|
||||
{
|
||||
boardId: this._id
|
||||
},
|
||||
{
|
||||
sort: { cardNumber: -1 },
|
||||
limit: 1
|
||||
}
|
||||
).fetch();
|
||||
|
||||
// If no card is assigned to the board, return 1
|
||||
if (!boardCards || boardCards.length === 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const maxCardNr = !!boardCards[0].cardNumber ? boardCards[0].cardNumber : 0;
|
||||
return maxCardNr + 1;
|
||||
},
|
||||
|
||||
cardsDueInBetween(start, end) {
|
||||
|
|
|
@ -577,6 +577,7 @@ Cards.helpers({
|
|||
|
||||
delete this._id;
|
||||
this.boardId = boardId;
|
||||
this.cardNumber = Boards.findOne(boardId).getNextCardNumber();
|
||||
this.swimlaneId = swimlaneId;
|
||||
this.listId = listId;
|
||||
const _id = Cards.insert(this);
|
||||
|
@ -1989,8 +1990,12 @@ Cards.mutations({
|
|||
'_id',
|
||||
);
|
||||
|
||||
// assign the new card number from the target board
|
||||
const newCardNumber = newBoard.getNextCardNumber();
|
||||
|
||||
Object.assign(mutatedFields, {
|
||||
labelIds: newCardLabelIds,
|
||||
cardNumber: newCardNumber
|
||||
});
|
||||
|
||||
mutatedFields.customFields = this.mapCustomFieldsToBoard(newBoard._id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue