浏览代码

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.
Benjamin Tissoires 6 年之前
父节点
当前提交
5c6a725712
共有 2 个文件被更改,包括 47 次插入0 次删除
  1. 31 0
      client/components/boards/boardBody.js
  2. 16 0
      models/boards.js

+ 31 - 0
client/components/boards/boardBody.js

@@ -35,6 +35,37 @@ BlazeComponent.extendComponent({
     this._isDragging = false;
     this._isDragging = false;
     // Used to set the overlay
     // Used to set the overlay
     this.mouseHasEnterCardDetails = false;
     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() {
   onRendered() {
     const boardComponent = this;
     const boardComponent = this;

+ 16 - 0
models/boards.js

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