From c10f7b61341c36e093930755275ff735f17b1dea Mon Sep 17 00:00:00 2001 From: Martin Filser Date: Tue, 17 May 2022 00:14:10 +0200 Subject: [PATCH 1/3] Utils#calculateIndex re-uses the logic of Utils#calculateIndexData - nearly the same implementation, so use common code base --- client/lib/utils.js | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/client/lib/utils.js b/client/lib/utils.js index 6444fdef6..7c3a18aaa 100644 --- a/client/lib/utils.js +++ b/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() { From 7e8073d6213ea3970f0e4a46e68179c614c5b126 Mon Sep 17 00:00:00 2001 From: Martin Filser Date: Tue, 17 May 2022 00:15:00 +0200 Subject: [PATCH 2/3] after moving, e.g. the minicard, round the index to the next integer - before: at index -1 and -9 the new index was -5 - now : at index -1 (or -1.1) and -9 the new index is -2 --- client/lib/utils.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/client/lib/utils.js b/client/lib/utils.js index 7c3a18aaa..321ee3090 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -343,8 +343,25 @@ Utils = { else { const prevSortIndex = prevData.sort; const nextSortIndex = nextData.sort; - increment = (nextSortIndex - prevSortIndex) / (nItems + 1); - base = prevSortIndex + increment; + if (nItems == 1 ) { + if (prevSortIndex < 0 ) { + const ceil = Math.ceil(nextSortIndex - 1); + if (ceil < nextSortIndex && ceil > prevSortIndex) { + increment = ceil - prevSortIndex; + } + } else { + const floor = Math.floor(nextSortIndex - 1); + if (floor < nextSortIndex && floor > prevSortIndex) { + increment = floor - prevSortIndex; + } + } + } + if (!increment) { + increment = (nextSortIndex - prevSortIndex) / (nItems + 1); + } + if (!base) { + base = prevSortIndex + increment; + } } // XXX Return a generator that yield values instead of a base with a // increment number. From b869e3efb6a7e90d1e9c441875cb56bb492ea3e7 Mon Sep 17 00:00:00 2001 From: Martin Filser Date: Wed, 27 Jul 2022 21:24:00 +0200 Subject: [PATCH 3/3] after moving, e.g. minicards, to the list start / end the index is rounded to the next index --- client/lib/utils.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/client/lib/utils.js b/client/lib/utils.js index 321ee3090..8cfd30426 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -331,12 +331,26 @@ Utils = { increment = 1; // If we drop the card in the first position } else if (!prevData) { - base = nextData.sort - 1; - increment = -1; + const nextSortIndex = nextData.sort; + const ceil = Math.ceil(nextSortIndex - 1); + if (ceil < nextSortIndex) { + increment = nextSortIndex - ceil; + base = nextSortIndex - increment; + } else { + base = nextData.sort - 1; + increment = -1; + } // If we drop the card in the last position } else if (!nextData) { - base = prevData.sort + 1; - increment = 1; + const prevSortIndex = prevData.sort; + const floor = Math.floor(prevSortIndex + 1); + if (floor > prevSortIndex) { + increment = prevSortIndex - floor; + base = prevSortIndex - increment; + } else { + base = prevData.sort + 1; + increment = 1; + } } // In the general case take the average of the previous and next element // sort indexes.