boardBody.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. const subManager = new SubsManager();
  2. const { calculateIndex } = Utils;
  3. BlazeComponent.extendComponent({
  4. onCreated() {
  5. this.isBoardReady = new ReactiveVar(false);
  6. // The pattern we use to manually handle data loading is described here:
  7. // https://kadira.io/academy/meteor-routing-guide/content/subscriptions-and-data-management/using-subs-manager
  8. // XXX The boardId should be readed from some sort the component "props",
  9. // unfortunatly, Blaze doesn't have this notion.
  10. this.autorun(() => {
  11. const currentBoardId = Session.get('currentBoard');
  12. if (!currentBoardId)
  13. return;
  14. const handle = subManager.subscribe('board', currentBoardId);
  15. Tracker.nonreactive(() => {
  16. Tracker.autorun(() => {
  17. this.isBoardReady.set(handle.ready());
  18. });
  19. });
  20. });
  21. },
  22. onlyShowCurrentCard() {
  23. return Utils.isMiniScreen() && Session.get('currentCard');
  24. },
  25. }).register('board');
  26. BlazeComponent.extendComponent({
  27. onCreated() {
  28. this.showOverlay = new ReactiveVar(false);
  29. this.draggingActive = new ReactiveVar(false);
  30. this._isDragging = false;
  31. // Used to set the overlay
  32. this.mouseHasEnterCardDetails = false;
  33. },
  34. onRendered() {
  35. const boardComponent = this;
  36. const $swimlanesDom = boardComponent.$('.js-swimlanes');
  37. $swimlanesDom.sortable({
  38. tolerance: 'pointer',
  39. appendTo: '.board-canvas',
  40. helper: 'clone',
  41. handle: '.js-swimlane-header',
  42. items: '.js-swimlane:not(.placeholder)',
  43. placeholder: 'swimlane placeholder',
  44. distance: 7,
  45. start(evt, ui) {
  46. ui.placeholder.height(ui.helper.height());
  47. EscapeActions.executeUpTo('popup-close');
  48. boardComponent.setIsDragging(true);
  49. },
  50. stop(evt, ui) {
  51. // To attribute the new index number, we need to get the DOM element
  52. // of the previous and the following card -- if any.
  53. const prevSwimlaneDom = ui.item.prev('.js-swimlane').get(0);
  54. const nextSwimlaneDom = ui.item.next('.js-swimlane').get(0);
  55. const sortIndex = calculateIndex(prevSwimlaneDom, nextSwimlaneDom, 1);
  56. $swimlanesDom.sortable('cancel');
  57. const swimlaneDomElement = ui.item.get(0);
  58. const swimlane = Blaze.getData(swimlaneDomElement);
  59. Swimlanes.update(swimlane._id, {
  60. $set: {
  61. sort: sortIndex.base,
  62. },
  63. });
  64. boardComponent.setIsDragging(false);
  65. },
  66. });
  67. function userIsMember() {
  68. return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly();
  69. }
  70. // If there is no data in the board (ie, no lists) we autofocus the list
  71. // creation form by clicking on the corresponding element.
  72. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  73. if (userIsMember() && currentBoard.lists().count() === 0) {
  74. boardComponent.openNewListForm();
  75. }
  76. },
  77. isViewSwimlanes() {
  78. const currentUser = Meteor.user();
  79. if (!currentUser) return false;
  80. return (currentUser.profile.boardView === 'board-view-swimlanes');
  81. },
  82. isViewLists() {
  83. const currentUser = Meteor.user();
  84. if (!currentUser) return true;
  85. return (currentUser.profile.boardView === 'board-view-lists');
  86. },
  87. isViewCalendar() {
  88. const currentUser = Meteor.user();
  89. if (!currentUser) return true;
  90. return (currentUser.profile.boardView === 'board-view-cal');
  91. },
  92. openNewListForm() {
  93. if (this.isViewSwimlanes()) {
  94. this.childComponents('swimlane')[0]
  95. .childComponents('addListAndSwimlaneForm')[0].open();
  96. } else if (this.isViewLists()) {
  97. this.childComponents('listsGroup')[0]
  98. .childComponents('addListForm')[0].open();
  99. }
  100. },
  101. calendarOptions() {
  102. return {
  103. id: 'calendar-view',
  104. defaultView: 'basicWeek',
  105. header: {
  106. left: 'title',
  107. center: 'agendaDay,listDay,timelineDay agendaWeek,listWeek,timelineWeek month,timelineMonth timelineYear',
  108. right: 'today prev,next',
  109. },
  110. views: {
  111. basic: {
  112. // options apply to basicWeek and basicDay views
  113. },
  114. agenda: {
  115. // options apply to agendaWeek and agendaDay views
  116. },
  117. week: {
  118. // options apply to basicWeek and agendaWeek views
  119. },
  120. day: {
  121. // options apply to basicDay and agendaDay views
  122. },
  123. },
  124. themeSystem: 'jquery-ui',
  125. height: 'parent',
  126. /* TODO: lists as resources: https://fullcalendar.io/docs/vertical-resource-view */
  127. navLinks: true,
  128. nowIndicator: true,
  129. businessHours: {
  130. // days of week. an array of zero-based day of week integers (0=Sunday)
  131. dow: [ 1, 2, 3, 4, 5 ], // Monday - Thursday
  132. start: '8:00',
  133. end: '18:00',
  134. },
  135. locale: TAPi18n.getLanguage(),
  136. events(start, end, timezone, callback) {
  137. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  138. const events = [];
  139. currentBoard.cardsInInterval(start.toDate(), end.toDate()).forEach(function(card){
  140. events.push({
  141. id: card.id,
  142. title: card.title,
  143. start: card.startAt,
  144. end: card.endAt,
  145. url: FlowRouter.url('card', {
  146. boardId: currentBoard._id,
  147. slug: currentBoard.slug,
  148. cardId: card._id,
  149. }),
  150. });
  151. });
  152. callback(events);
  153. },
  154. };
  155. },
  156. events() {
  157. return [{
  158. // XXX The board-overlay div should probably be moved to the parent
  159. // component.
  160. 'mouseenter .board-overlay'() {
  161. if (this.mouseHasEnterCardDetails) {
  162. this.showOverlay.set(false);
  163. }
  164. },
  165. 'mouseup'() {
  166. if (this._isDragging) {
  167. this._isDragging = false;
  168. }
  169. },
  170. }];
  171. },
  172. // XXX Flow components allow us to avoid creating these two setter methods by
  173. // exposing a public API to modify the component state. We need to investigate
  174. // best practices here.
  175. setIsDragging(bool) {
  176. this.draggingActive.set(bool);
  177. },
  178. scrollLeft(position = 0) {
  179. const swimlanes = this.$('.js-swimlanes');
  180. swimlanes && swimlanes.animate({
  181. scrollLeft: position,
  182. });
  183. },
  184. }).register('boardBody');