mirror of
https://github.com/wekan/wekan.git
synced 2025-12-17 16:00:13 +01:00
Utils#calculateIndex re-uses the logic of Utils#calculateIndexData
- nearly the same implementation, so use common code base
This commit is contained in:
parent
1a71abbc1d
commit
c10f7b6134
1 changed files with 8 additions and 26 deletions
|
|
@ -356,34 +356,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