boardBody.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const subManager = new SubsManager();
  2. BlazeComponent.extendComponent({
  3. onCreated() {
  4. this.draggingActive = new ReactiveVar(false);
  5. this.showOverlay = new ReactiveVar(false);
  6. this.isBoardReady = new ReactiveVar(false);
  7. // The pattern we use to manually handle data loading is described here:
  8. // https://kadira.io/academy/meteor-routing-guide/content/subscriptions-and-data-management/using-subs-manager
  9. // XXX The boardId should be readed from some sort the component "props",
  10. // unfortunatly, Blaze doesn't have this notion.
  11. this.autorun(() => {
  12. const currentBoardId = Session.get('currentBoard');
  13. if (!currentBoardId)
  14. return;
  15. const handle = subManager.subscribe('board', currentBoardId);
  16. Tracker.nonreactive(() => {
  17. Tracker.autorun(() => {
  18. this.isBoardReady.set(handle.ready());
  19. });
  20. });
  21. });
  22. this._isDragging = false;
  23. this._lastDragPositionX = 0;
  24. // Used to set the overlay
  25. this.mouseHasEnterCardDetails = false;
  26. },
  27. // XXX Flow components allow us to avoid creating these two setter methods by
  28. // exposing a public API to modify the component state. We need to investigate
  29. // best practices here.
  30. setIsDragging(bool) {
  31. this.draggingActive.set(bool);
  32. },
  33. scrollLeft(position = 0) {
  34. const lists = this.$('.js-lists');
  35. lists && lists.animate({
  36. scrollLeft: position,
  37. });
  38. },
  39. onlyShowCurrentCard() {
  40. return Utils.isMiniScreen() && Session.get('currentCard');
  41. },
  42. isViewSwimlanes() {
  43. const currentBoardId = Session.get('currentBoard');
  44. const board = Boards.findOne(currentBoardId);
  45. return (board.view === 'board-view-swimlanes');
  46. },
  47. isViewLists() {
  48. const currentBoardId = Session.get('currentBoard');
  49. const board = Boards.findOne(currentBoardId);
  50. return (board.view === 'board-view-lists');
  51. },
  52. events() {
  53. return [{
  54. // XXX The board-overlay div should probably be moved to the parent
  55. // component.
  56. 'mouseenter .board-overlay'() {
  57. if (this.mouseHasEnterCardDetails) {
  58. this.showOverlay.set(false);
  59. }
  60. },
  61. 'mouseup'() {
  62. if (this._isDragging) {
  63. this._isDragging = false;
  64. }
  65. },
  66. }];
  67. },
  68. }).register('board');