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:
Lauri Ojansivu 2021-08-03 16:12:28 +03:00 committed by GitHub
commit f01b440fb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View file

@ -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) {

View file

@ -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);