mirror of
https://github.com/wekan/wekan.git
synced 2026-03-12 00:22:34 +01:00
Merge pull request #4975 from mfilser/rounding_sort_number_to_next_integer
Rounding sort number to next integer
This commit is contained in:
commit
e90791fdbc
1 changed files with 45 additions and 32 deletions
|
|
@ -331,20 +331,51 @@ Utils = {
|
||||||
increment = 1;
|
increment = 1;
|
||||||
// If we drop the card in the first position
|
// If we drop the card in the first position
|
||||||
} else if (!prevData) {
|
} else if (!prevData) {
|
||||||
base = nextData.sort - 1;
|
const nextSortIndex = nextData.sort;
|
||||||
increment = -1;
|
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
|
// If we drop the card in the last position
|
||||||
} else if (!nextData) {
|
} else if (!nextData) {
|
||||||
base = prevData.sort + 1;
|
const prevSortIndex = prevData.sort;
|
||||||
increment = 1;
|
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
|
// In the general case take the average of the previous and next element
|
||||||
// sort indexes.
|
// sort indexes.
|
||||||
else {
|
else {
|
||||||
const prevSortIndex = prevData.sort;
|
const prevSortIndex = prevData.sort;
|
||||||
const nextSortIndex = nextData.sort;
|
const nextSortIndex = nextData.sort;
|
||||||
increment = (nextSortIndex - prevSortIndex) / (nItems + 1);
|
if (nItems == 1 ) {
|
||||||
base = prevSortIndex + increment;
|
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
|
// XXX Return a generator that yield values instead of a base with a
|
||||||
// increment number.
|
// increment number.
|
||||||
|
|
@ -356,34 +387,16 @@ Utils = {
|
||||||
|
|
||||||
// Determine the new sort index
|
// Determine the new sort index
|
||||||
calculateIndex(prevCardDomElement, nextCardDomElement, nCards = 1) {
|
calculateIndex(prevCardDomElement, nextCardDomElement, nCards = 1) {
|
||||||
let base, increment;
|
let prevData = null;
|
||||||
// If we drop the card to an empty column
|
let nextData = null;
|
||||||
if (!prevCardDomElement && !nextCardDomElement) {
|
if (prevCardDomElement) {
|
||||||
base = 0;
|
prevData = Blaze.getData(prevCardDomElement)
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
// In the general case take the average of the previous and next element
|
if (nextCardDomElement) {
|
||||||
// sort indexes.
|
nextData = Blaze.getData(nextCardDomElement);
|
||||||
else {
|
|
||||||
const prevSortIndex = Blaze.getData(prevCardDomElement).sort;
|
|
||||||
const nextSortIndex = Blaze.getData(nextCardDomElement).sort;
|
|
||||||
increment = (nextSortIndex - prevSortIndex) / (nCards + 1);
|
|
||||||
base = prevSortIndex + increment;
|
|
||||||
}
|
}
|
||||||
// XXX Return a generator that yield values instead of a base with a
|
const ret = Utils.calculateIndexData(prevData, nextData, nCards);
|
||||||
// increment number.
|
return ret;
|
||||||
return {
|
|
||||||
base,
|
|
||||||
increment,
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
|
|
||||||
manageCustomUI() {
|
manageCustomUI() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue