2
0

utils.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. Utils = {
  2. // XXX We should remove these two methods
  3. goBoardId(_id) {
  4. const board = Boards.findOne(_id);
  5. return board && FlowRouter.go('board', {
  6. id: board._id,
  7. slug: board.slug,
  8. });
  9. },
  10. goCardId(_id) {
  11. const card = Cards.findOne(_id);
  12. const board = Boards.findOne(card.boardId);
  13. return board && FlowRouter.go('card', {
  14. cardId: card._id,
  15. boardId: board._id,
  16. slug: board.slug,
  17. });
  18. },
  19. capitalize(string) {
  20. return string.charAt(0).toUpperCase() + string.slice(1);
  21. },
  22. // Determine the new sort index
  23. calculateIndex(prevCardDomElement, nextCardDomElement, nCards = 1) {
  24. let base, increment;
  25. // If we drop the card to an empty column
  26. if (!prevCardDomElement && !nextCardDomElement) {
  27. base = 0;
  28. increment = 1;
  29. // If we drop the card in the first position
  30. } else if (!prevCardDomElement) {
  31. base = Blaze.getData(nextCardDomElement).sort - 1;
  32. increment = -1;
  33. // If we drop the card in the last position
  34. } else if (!nextCardDomElement) {
  35. base = Blaze.getData(prevCardDomElement).sort + 1;
  36. increment = 1;
  37. }
  38. // In the general case take the average of the previous and next element
  39. // sort indexes.
  40. else {
  41. const prevSortIndex = Blaze.getData(prevCardDomElement).sort;
  42. const nextSortIndex = Blaze.getData(nextCardDomElement).sort;
  43. increment = (nextSortIndex - prevSortIndex) / (nCards + 1);
  44. base = prevSortIndex + increment;
  45. }
  46. // XXX Return a generator that yield values instead of a base with a
  47. // increment number.
  48. return {
  49. base,
  50. increment,
  51. };
  52. },
  53. };