Ver Fonte

List add always at the end of all lists

- if a sort number is higher than the count of lists, the list wasn't
  added at the end
Martin Filser há 3 anos atrás
pai
commit
0fb6b6e519
2 ficheiros alterados com 12 adições e 1 exclusões
  1. 3 1
      client/components/swimlanes/swimlanes.js
  2. 9 0
      models/boards.js

+ 3 - 1
client/components/swimlanes/swimlanes.js

@@ -237,13 +237,15 @@ BlazeComponent.extendComponent({
       {
         submit(evt) {
           evt.preventDefault();
+          const lastList = this.currentBoard.getLastList();
+          const sortIndex = Utils.calculateIndexData(lastList, null).base;
           const titleInput = this.find('.list-name-input');
           const title = titleInput.value.trim();
           if (title) {
             Lists.insert({
               title,
               boardId: Session.get('currentBoard'),
-              sort: $('.js-list').length,
+              sort: sortIndex,
               type: this.isListTemplatesSwimlane ? 'template-list' : 'list',
               swimlaneId: this.currentBoard.isTemplatesBoard()
                 ? this.currentSwimlane._id

+ 9 - 0
models/boards.js

@@ -693,10 +693,19 @@ Boards.helpers({
       { sort: sortKey },
     );
   },
+
   draggableLists() {
     return Lists.find({ boardId: this._id }, { sort: { sort: 1 } });
   },
 
+  /** returns the last list
+   * @returns Document the last list
+   */
+  getLastList() {
+    const ret = Lists.findOne({ boardId: this._id }, { sort: { sort: 'desc' } });
+    return ret;
+  },
+
   nullSortLists() {
     return Lists.find({
       boardId: this._id,