浏览代码

Utils#calculateIndex re-uses the logic of Utils#calculateIndexData

- nearly the same implementation, so use common code base
Martin Filser 3 年之前
父节点
当前提交
c10f7b6134
共有 1 个文件被更改,包括 8 次插入26 次删除
  1. 8 26
      client/lib/utils.js

+ 8 - 26
client/lib/utils.js

@@ -356,34 +356,16 @@ Utils = {
 
   // Determine the new sort index
   calculateIndex(prevCardDomElement, nextCardDomElement, nCards = 1) {
-    let base, increment;
-    // If we drop the card to an empty column
-    if (!prevCardDomElement && !nextCardDomElement) {
-      base = 0;
-      increment = 1;
-      // If we drop the card in the first position
-    } else if (!prevCardDomElement) {
-      base = Blaze.getData(nextCardDomElement).sort - 1;
-      increment = -1;
-      // If we drop the card in the last position
-    } else if (!nextCardDomElement) {
-      base = Blaze.getData(prevCardDomElement).sort + 1;
-      increment = 1;
+    let prevData = null;
+    let nextData = null;
+    if (prevCardDomElement) {
+      prevData = Blaze.getData(prevCardDomElement)
     }
-    // In the general case take the average of the previous and next element
-    // sort indexes.
-    else {
-      const prevSortIndex = Blaze.getData(prevCardDomElement).sort;
-      const nextSortIndex = Blaze.getData(nextCardDomElement).sort;
-      increment = (nextSortIndex - prevSortIndex) / (nCards + 1);
-      base = prevSortIndex + increment;
+    if (nextCardDomElement) {
+      nextData = Blaze.getData(nextCardDomElement);
     }
-    // XXX Return a generator that yield values instead of a base with a
-    // increment number.
-    return {
-      base,
-      increment,
-    };
+    const ret = Utils.calculateIndexData(prevData, nextData, nCards);
+    return ret;
   },
 
   manageCustomUI() {