瀏覽代碼

Checklist, adding many items set's now the sorting correctly

Martin Filser 7 月之前
父節點
當前提交
1d7eb8a03b
共有 1 個文件被更改,包括 10 次插入6 次删除
  1. 10 6
      client/components/cards/checklists.js

+ 10 - 6
client/components/cards/checklists.js

@@ -133,19 +133,23 @@ BlazeComponent.extendComponent({
           }
         }
       }
+      let addIndex;
+      let sortIndex;
+      if (this.currentData().position === 'top') {
+        sortIndex = Utils.calculateIndexData(null, checklist.firstItem()).base;
+        addIndex = -1;
+      } else {
+        sortIndex = Utils.calculateIndexData(checklist.lastItem(), null).base;
+        addIndex = 1;
+      }
       for (let checklistItem of checklistItems) {
-        let sortIndex;
-        if (this.currentData().position === 'top') {
-          sortIndex = Utils.calculateIndexData(null, checklist.firstItem()).base;
-        } else {
-          sortIndex = Utils.calculateIndexData(checklist.lastItem(), null).base;
-        }
         ChecklistItems.insert({
           title: checklistItem,
           checklistId: checklist._id,
           cardId: checklist.cardId,
           sort: sortIndex,
         });
+        sortIndex += addIndex;
       }
     }
     // We keep the form opened, empty it.