Pārlūkot izejas kodu

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 gadi atpakaļ
vecāks
revīzija
5c6a725712
2 mainītis faili ar 47 papildinājumiem un 0 dzēšanām
  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;
     // 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;

+ 16 - 0
models/boards.js

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