boardsList.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. const subManager = new SubsManager();
  2. const { calculateIndex, enableClickOnTouch } = Utils;
  3. Template.boardListHeaderBar.events({
  4. 'click .js-open-archived-board'() {
  5. Modal.open('archivedBoards');
  6. },
  7. });
  8. Template.boardListHeaderBar.helpers({
  9. title() {
  10. return FlowRouter.getRouteName() === 'home' ? 'my-boards' : 'public';
  11. },
  12. templatesBoardId() {
  13. return Meteor.user() && Meteor.user().getTemplatesBoardId();
  14. },
  15. templatesBoardSlug() {
  16. return Meteor.user() && Meteor.user().getTemplatesBoardSlug();
  17. },
  18. });
  19. BlazeComponent.extendComponent({
  20. onCreated() {
  21. Meteor.subscribe('setting');
  22. let currUser = Meteor.user();
  23. let userLanguage;
  24. if(currUser && currUser.profile){
  25. userLanguage = currUser.profile.language
  26. }
  27. if (userLanguage) {
  28. TAPi18n.setLanguage(userLanguage);
  29. T9n.setLanguage(userLanguage);
  30. }
  31. },
  32. onRendered() {
  33. const itemsSelector = '.js-board:not(.placeholder)';
  34. const $boards = this.$('.js-boards');
  35. $boards.sortable({
  36. connectWith: '.js-boards',
  37. tolerance: 'pointer',
  38. appendTo: '.board-list',
  39. helper: 'clone',
  40. distance: 7,
  41. items: itemsSelector,
  42. placeholder: 'board-wrapper placeholder',
  43. start(evt, ui) {
  44. ui.helper.css('z-index', 1000);
  45. ui.placeholder.height(ui.helper.height());
  46. EscapeActions.executeUpTo('popup-close');
  47. },
  48. stop(evt, ui) {
  49. // To attribute the new index number, we need to get the DOM element
  50. // of the previous and the following card -- if any.
  51. const prevBoardDom = ui.item.prev('.js-board').get(0);
  52. const nextBoardBom = ui.item.next('.js-board').get(0);
  53. const sortIndex = calculateIndex(prevBoardDom, nextBoardBom, 1);
  54. const boardDomElement = ui.item.get(0);
  55. const board = Blaze.getData(boardDomElement);
  56. // Normally the jquery-ui sortable library moves the dragged DOM element
  57. // to its new position, which disrupts Blaze reactive updates mechanism
  58. // (especially when we move the last card of a list, or when multiple
  59. // users move some cards at the same time). To prevent these UX glitches
  60. // we ask sortable to gracefully cancel the move, and to put back the
  61. // DOM in its initial state. The card move is then handled reactively by
  62. // Blaze with the below query.
  63. $boards.sortable('cancel');
  64. board.move(sortIndex.base);
  65. },
  66. });
  67. // ugly touch event hotfix
  68. enableClickOnTouch(itemsSelector);
  69. // Disable drag-dropping if the current user is not a board member or is comment only
  70. this.autorun(() => {
  71. if (Utils.isMiniScreen()) {
  72. $boards.sortable({
  73. handle: '.board-handle',
  74. });
  75. }
  76. });
  77. },
  78. boards() {
  79. const query = {
  80. //archived: false,
  81. ////type: { $in: ['board','template-container'] },
  82. //type: 'board',
  83. $and: [
  84. { archived: false },
  85. { type: 'board' },
  86. { $or:[] }
  87. ]
  88. };
  89. if (FlowRouter.getRouteName() === 'home'){
  90. query.$and[2].$or.push({'members.userId': Meteor.userId()});
  91. const currUser = Users.findOne(Meteor.userId());
  92. // const currUser = Users.findOne(Meteor.userId(), {
  93. // fields: {
  94. // orgs: 1,
  95. // teams: 1,
  96. // },
  97. // });
  98. let orgIdsUserBelongs = currUser.teams !== 'undefined' ? currUser.orgIdsUserBelongs() : '';
  99. if(orgIdsUserBelongs && orgIdsUserBelongs != ''){
  100. let orgsIds = orgIdsUserBelongs.split(',');
  101. // for(let i = 0; i < orgsIds.length; i++){
  102. // query.$and[2].$or.push({'orgs.orgId': orgsIds[i]});
  103. // }
  104. //query.$and[2].$or.push({'orgs': {$elemMatch : {orgId: orgsIds[0]}}});
  105. query.$and[2].$or.push({'orgs.orgId': {$in : orgsIds}});
  106. }
  107. let teamIdsUserBelongs = currUser.teams !== 'undefined' ? currUser.teamIdsUserBelongs() : '';
  108. if(teamIdsUserBelongs && teamIdsUserBelongs != ''){
  109. let teamsIds = teamIdsUserBelongs.split(',');
  110. // for(let i = 0; i < teamsIds.length; i++){
  111. // query.$or[2].$or.push({'teams.teamId': teamsIds[i]});
  112. // }
  113. //query.$and[2].$or.push({'teams': { $elemMatch : {teamId: teamsIds[0]}}});
  114. query.$and[2].$or.push({'teams.teamId': {$in : teamsIds}});
  115. }
  116. }
  117. else query.permission = 'public';
  118. return Boards.find(query, {
  119. //sort: { sort: 1 /* boards default sorting */ },
  120. });
  121. },
  122. isStarred() {
  123. const user = Meteor.user();
  124. return user && user.hasStarred(this.currentData()._id);
  125. },
  126. isAdministrable() {
  127. const user = Meteor.user();
  128. return user && user.isBoardAdmin(this.currentData()._id);
  129. },
  130. hasOvertimeCards() {
  131. subManager.subscribe('board', this.currentData()._id, false);
  132. return this.currentData().hasOvertimeCards();
  133. },
  134. hasSpentTimeCards() {
  135. subManager.subscribe('board', this.currentData()._id, false);
  136. return this.currentData().hasSpentTimeCards();
  137. },
  138. isInvited() {
  139. const user = Meteor.user();
  140. return user && user.isInvitedTo(this.currentData()._id);
  141. },
  142. events() {
  143. return [
  144. {
  145. 'click .js-add-board': Popup.open('createBoard'),
  146. 'click .js-star-board'(evt) {
  147. const boardId = this.currentData()._id;
  148. Meteor.user().toggleBoardStar(boardId);
  149. evt.preventDefault();
  150. },
  151. 'click .js-clone-board'(evt) {
  152. Meteor.call(
  153. 'copyBoard',
  154. this.currentData()._id,
  155. {
  156. sort: Boards.find({ archived: false }).count(),
  157. type: 'board',
  158. title: Boards.findOne(this.currentData()._id).title,
  159. },
  160. (err, res) => {
  161. if (err) {
  162. this.setError(err.error);
  163. } else {
  164. Session.set('fromBoard', null);
  165. Utils.goBoardId(res);
  166. }
  167. },
  168. );
  169. evt.preventDefault();
  170. },
  171. 'click .js-archive-board'(evt) {
  172. const boardId = this.currentData()._id;
  173. Meteor.call('archiveBoard', boardId);
  174. evt.preventDefault();
  175. },
  176. 'click .js-accept-invite'() {
  177. const boardId = this.currentData()._id;
  178. Meteor.call('acceptInvite', boardId);
  179. },
  180. 'click .js-decline-invite'() {
  181. const boardId = this.currentData()._id;
  182. Meteor.call('quitBoard', boardId, (err, ret) => {
  183. if (!err && ret) {
  184. Meteor.call('acceptInvite', boardId);
  185. FlowRouter.go('home');
  186. }
  187. });
  188. },
  189. },
  190. ];
  191. },
  192. }).register('boardList');