Make sure Swimlanes and Lists have a populated sort field

When moving around the swimlanes or the lists, if one element has a sort
with a null value, the computation of the new sort value is aborted,
meaning that there are glitches in the UI.

This happens on the first swimlane created with the new board, or when
a swimlane or a list gets added through the API.
This commit is contained in:
Benjamin Tissoires 2019-01-25 10:47:36 +01:00
parent 03efeaeb1a
commit 5c6a725712
2 changed files with 47 additions and 0 deletions

View file

@ -35,6 +35,37 @@ BlazeComponent.extendComponent({
this._isDragging = false;
// Used to set the overlay
this.mouseHasEnterCardDetails = false;
// fix swimlanes sort field if there are null values
const currentBoardData = Boards.findOne(Session.get('currentBoard'));
const nullSortSwimlanes = currentBoardData.nullSortSwimlanes();
if (nullSortSwimlanes.count() > 0) {
const swimlanes = currentBoardData.swimlanes();
let count = 0;
swimlanes.forEach((s) => {
Swimlanes.update(s._id, {
$set: {
sort: count,
},
});
count += 1;
});
}
// fix lists sort field if there are null values
const nullSortLists = currentBoardData.nullSortLists();
if (nullSortLists.count() > 0) {
const lists = currentBoardData.lists();
let count = 0;
lists.forEach((l) => {
Lists.update(l._id, {
$set: {
sort: count,
},
});
count += 1;
});
}
},
onRendered() {
const boardComponent = this;

View file

@ -347,6 +347,14 @@ Boards.helpers({
return Lists.find({ boardId: this._id, archived: false }, { sort: { sort: 1 } });
},
nullSortLists() {
return Lists.find({
boardId: this._id,
archived: false,
sort: { $eq: null },
});
},
swimlanes() {
return Swimlanes.find({ boardId: this._id, archived: false }, { sort: { sort: 1 } });
},
@ -362,6 +370,14 @@ Boards.helpers({
});
},
nullSortSwimlanes() {
return Swimlanes.find({
boardId: this._id,
archived: false,
sort: { $eq: null },
});
},
hasOvertimeCards(){
const card = Cards.findOne({isOvertime: true, boardId: this._id, archived: false} );
return card !== undefined;