summaryrefslogtreecommitdiffstats
path: root/client/lib
diff options
context:
space:
mode:
authorAndrés Manelli <andresmanelli@gmail.com>2018-03-19 15:03:44 -0300
committerAndrés Manelli <andresmanelli@gmail.com>2018-03-19 15:03:44 -0300
commit153960742cac53c52f176f1bc645d850f25ac966 (patch)
treee965ea478a8e3025e6497e7deb6f40eb50a2bd37 /client/lib
parentbf7de463f1f71f1758b62187667bf3a7e55585ff (diff)
downloadwekan-153960742cac53c52f176f1bc645d850f25ac966.tar.gz
wekan-153960742cac53c52f176f1bc645d850f25ac966.tar.bz2
wekan-153960742cac53c52f176f1bc645d850f25ac966.zip
Fix migration. Replace old checklist-item sort algorithm.
Diffstat (limited to 'client/lib')
-rw-r--r--client/lib/utils.js31
1 files changed, 31 insertions, 0 deletions
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;