From 153960742cac53c52f176f1bc645d850f25ac966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Manelli?= Date: Mon, 19 Mar 2018 15:03:44 -0300 Subject: Fix migration. Replace old checklist-item sort algorithm. --- client/lib/utils.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'client/lib/utils.js') diff --git a/client/lib/utils.js b/client/lib/utils.js index 9a9ff654..1f44c60d 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -33,6 +33,37 @@ Utils = { return $(window).width() <= 800; }, + calculateIndexData(prevData, nextData, nItems = 1) { + let base, increment; + // If we drop the card to an empty column + if (!prevData && !nextData) { + base = 0; + increment = 1; + // If we drop the card in the first position + } else if (!prevData) { + base = nextData.sort - 1; + increment = -1; + // If we drop the card in the last position + } else if (!nextData) { + base = prevData.sort + 1; + increment = 1; + } + // In the general case take the average of the previous and next element + // sort indexes. + else { + const prevSortIndex = prevData.sort; + const nextSortIndex = nextData.sort; + increment = (nextSortIndex - prevSortIndex) / (nItems + 1); + base = prevSortIndex + increment; + } + // XXX Return a generator that yield values instead of a base with a + // increment number. + return { + base, + increment, + }; + }, + // Determine the new sort index calculateIndex(prevCardDomElement, nextCardDomElement, nCards = 1) { let base, increment; -- cgit v1.2.3-1-g7c22