瀏覽代碼

insert linked card at top/bottom of list

Martin Filser 2 年之前
父節點
當前提交
29216599e4
共有 1 個文件被更改,包括 12 次插入5 次删除
  1. 12 5
      client/components/lists/listBody.js

+ 12 - 5
client/components/lists/listBody.js

@@ -433,8 +433,8 @@ BlazeComponent.extendComponent({
     subManager.subscribe('board', this.boardId, false);
     subManager.subscribe('board', this.boardId, false);
     this.board = ReactiveCache.getBoard(this.boardId);
     this.board = ReactiveCache.getBoard(this.boardId);
     // List where to insert card
     // List where to insert card
-    const list = $(Popup._getTopStack().openerElement).closest('.js-list');
-    this.listId = Blaze.getData(list[0])._id;
+    this.list = $(Popup._getTopStack().openerElement).closest('.js-list');
+    this.listId = Blaze.getData(this.list[0])._id;
     // Swimlane where to insert card
     // Swimlane where to insert card
     const swimlane = $(Popup._getTopStack().openerElement).closest(
     const swimlane = $(Popup._getTopStack().openerElement).closest(
       '.js-swimlane',
       '.js-swimlane',
@@ -520,14 +520,21 @@ BlazeComponent.extendComponent({
             Popup.back();
             Popup.back();
             return;
             return;
           }
           }
+          const position = this.currentData().position;
+          let sortIndex;
+          if (position === 'top') {
+            const firstCardDom = this.list.find('.js-minicard:first')[0];
+            sortIndex = Utils.calculateIndex(null, firstCardDom).base;
+          } else if (position === 'bottom') {
+            const lastCardDom = this.list.find('.js-minicard:last')[0];
+            sortIndex = Utils.calculateIndex(lastCardDom, null).base;
+          }
           const _id = Cards.insert({
           const _id = Cards.insert({
             title: $('.js-select-cards option:selected').text(), //dummy
             title: $('.js-select-cards option:selected').text(), //dummy
             listId: this.listId,
             listId: this.listId,
             swimlaneId: this.swimlaneId,
             swimlaneId: this.swimlaneId,
             boardId: this.boardId,
             boardId: this.boardId,
-            sort: Lists.findOne(this.listId)
-              .cards()
-              .count(),
+            sort: sortIndex,
             type: 'cardType-linkedCard',
             type: 'cardType-linkedCard',
             linkedId,
             linkedId,
           });
           });