boardBody.js 2.3 KB

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