boardsList.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. const subManager = new SubsManager();
  2. Template.boardListHeaderBar.events({
  3. 'click .js-open-archived-board'() {
  4. Modal.open('archivedBoards');
  5. },
  6. });
  7. Template.boardListHeaderBar.helpers({
  8. title() {
  9. return FlowRouter.getRouteName() === 'home' ? 'my-boards' : 'public';
  10. },
  11. templatesBoardId() {
  12. return Meteor.user() && Meteor.user().getTemplatesBoardId();
  13. },
  14. templatesBoardSlug() {
  15. return Meteor.user() && Meteor.user().getTemplatesBoardSlug();
  16. },
  17. });
  18. BlazeComponent.extendComponent({
  19. onCreated() {
  20. Meteor.subscribe('setting');
  21. Meteor.subscribe('tableVisibilityModeSettings');
  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 = Utils.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. // Disable drag-dropping if the current user is not a board member or is comment only
  68. this.autorun(() => {
  69. if (Utils.isMiniScreenOrShowDesktopDragHandles()) {
  70. $boards.sortable({
  71. handle: '.board-handle',
  72. });
  73. }
  74. });
  75. },
  76. userHasTeams(){
  77. if(Meteor.user() != null && Meteor.user().teams && Meteor.user().teams.length > 0)
  78. return true;
  79. else
  80. return false;
  81. },
  82. teamsDatas() {
  83. if(Meteor.user().teams)
  84. return Meteor.user().teams.sort((a, b) => a.teamDisplayName.localeCompare(b.teamDisplayName));
  85. else
  86. return [];
  87. },
  88. userHasOrgs(){
  89. if(Meteor.user() != null && Meteor.user().orgs && Meteor.user().orgs.length > 0)
  90. return true;
  91. else
  92. return false;
  93. },
  94. orgsDatas() {
  95. if(Meteor.user().orgs)
  96. return Meteor.user().orgs.sort((a, b) => a.orgDisplayName.localeCompare(b.orgDisplayName));
  97. else
  98. return [];
  99. },
  100. userHasOrgsOrTeams(){
  101. let boolUserHasOrgs;
  102. if(Meteor.user() != null && Meteor.user().orgs && Meteor.user().orgs.length > 0)
  103. boolUserHasOrgs = true;
  104. else
  105. boolUserHasOrgs = false;
  106. let boolUserHasTeams;
  107. if(Meteor.user() != null && Meteor.user().teams && Meteor.user().teams.length > 0)
  108. boolUserHasTeams = true;
  109. else
  110. boolUserHasTeams = false;
  111. return (boolUserHasOrgs || boolUserHasTeams);
  112. },
  113. boards() {
  114. let query = {
  115. //archived: false,
  116. ////type: { $in: ['board','template-container'] },
  117. //type: 'board',
  118. $and: [
  119. { archived: false },
  120. { type: 'board' },
  121. { $or:[] }
  122. ]
  123. };
  124. let allowPrivateVisibilityOnly = TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly');
  125. if (FlowRouter.getRouteName() === 'home'){
  126. query.$and[2].$or.push({'members.userId': Meteor.userId()});
  127. if(allowPrivateVisibilityOnly !== undefined && allowPrivateVisibilityOnly.booleanValue){
  128. query.$and.push({'permission': 'private'});
  129. }
  130. const currUser = Users.findOne(Meteor.userId());
  131. // const currUser = Users.findOne(Meteor.userId(), {
  132. // fields: {
  133. // orgs: 1,
  134. // teams: 1,
  135. // },
  136. // });
  137. let orgIdsUserBelongs = currUser !== undefined && currUser.teams !== 'undefined' ? currUser.orgIdsUserBelongs() : '';
  138. if(orgIdsUserBelongs && orgIdsUserBelongs != ''){
  139. let orgsIds = orgIdsUserBelongs.split(',');
  140. // for(let i = 0; i < orgsIds.length; i++){
  141. // query.$and[2].$or.push({'orgs.orgId': orgsIds[i]});
  142. // }
  143. //query.$and[2].$or.push({'orgs': {$elemMatch : {orgId: orgsIds[0]}}});
  144. query.$and[2].$or.push({'orgs.orgId': {$in : orgsIds}});
  145. }
  146. let teamIdsUserBelongs = currUser !== undefined && currUser.teams !== 'undefined' ? currUser.teamIdsUserBelongs() : '';
  147. if(teamIdsUserBelongs && teamIdsUserBelongs != ''){
  148. let teamsIds = teamIdsUserBelongs.split(',');
  149. // for(let i = 0; i < teamsIds.length; i++){
  150. // query.$or[2].$or.push({'teams.teamId': teamsIds[i]});
  151. // }
  152. //query.$and[2].$or.push({'teams': { $elemMatch : {teamId: teamsIds[0]}}});
  153. query.$and[2].$or.push({'teams.teamId': {$in : teamsIds}});
  154. }
  155. }
  156. else if(allowPrivateVisibilityOnly !== undefined && !allowPrivateVisibilityOnly.booleanValue){
  157. query = {
  158. archived: false,
  159. //type: { $in: ['board','template-container'] },
  160. type: 'board',
  161. permission: 'public',
  162. };
  163. }
  164. return Boards.find(query, {
  165. sort: { sort: 1 /* boards default sorting */ },
  166. });
  167. },
  168. isStarred() {
  169. const user = Meteor.user();
  170. return user && user.hasStarred(this.currentData()._id);
  171. },
  172. isAdministrable() {
  173. const user = Meteor.user();
  174. return user && user.isBoardAdmin(this.currentData()._id);
  175. },
  176. hasOvertimeCards() {
  177. subManager.subscribe('board', this.currentData()._id, false);
  178. return this.currentData().hasOvertimeCards();
  179. },
  180. hasSpentTimeCards() {
  181. subManager.subscribe('board', this.currentData()._id, false);
  182. return this.currentData().hasSpentTimeCards();
  183. },
  184. isInvited() {
  185. const user = Meteor.user();
  186. return user && user.isInvitedTo(this.currentData()._id);
  187. },
  188. events() {
  189. return [
  190. {
  191. 'click .js-add-board': Popup.open('createBoard'),
  192. 'click .js-star-board'(evt) {
  193. const boardId = this.currentData()._id;
  194. Meteor.user().toggleBoardStar(boardId);
  195. evt.preventDefault();
  196. },
  197. 'click .js-clone-board'(evt) {
  198. Meteor.call(
  199. 'copyBoard',
  200. this.currentData()._id,
  201. {
  202. sort: Boards.find({ archived: false }).count(),
  203. type: 'board',
  204. title: Boards.findOne(this.currentData()._id).title,
  205. },
  206. (err, res) => {
  207. if (err) {
  208. this.setError(err.error);
  209. } else {
  210. Session.set('fromBoard', null);
  211. Utils.goBoardId(res);
  212. }
  213. },
  214. );
  215. evt.preventDefault();
  216. },
  217. 'click .js-archive-board'(evt) {
  218. const boardId = this.currentData()._id;
  219. Meteor.call('archiveBoard', boardId);
  220. evt.preventDefault();
  221. },
  222. 'click .js-accept-invite'() {
  223. const boardId = this.currentData()._id;
  224. Meteor.call('acceptInvite', boardId);
  225. },
  226. 'click .js-decline-invite'() {
  227. const boardId = this.currentData()._id;
  228. Meteor.call('quitBoard', boardId, (err, ret) => {
  229. if (!err && ret) {
  230. Meteor.call('acceptInvite', boardId);
  231. FlowRouter.go('home');
  232. }
  233. });
  234. },
  235. 'click #resetBtn'(event){
  236. let allBoards = document.getElementsByClassName("js-board");
  237. let currBoard;
  238. for(let i=0; i < allBoards.length; i++){
  239. currBoard = allBoards[i];
  240. currBoard.style.display = "block";
  241. }
  242. },
  243. 'click #filterBtn'(event) {
  244. event.preventDefault();
  245. let selectedTeams = document.querySelectorAll('#jsAllBoardTeams option:checked');
  246. let selectedTeamsValues = Array.from(selectedTeams).map(function(elt){return elt.value});
  247. let index = selectedTeamsValues.indexOf("-1");
  248. if (index > -1) {
  249. selectedTeamsValues.splice(index, 1);
  250. }
  251. let selectedOrgs = document.querySelectorAll('#jsAllBoardOrgs option:checked');
  252. let selectedOrgsValues = Array.from(selectedOrgs).map(function(elt){return elt.value});
  253. index = selectedOrgsValues.indexOf("-1");
  254. if (index > -1) {
  255. selectedOrgsValues.splice(index, 1);
  256. }
  257. if(selectedTeamsValues.length > 0 || selectedOrgsValues.length > 0){
  258. const query = {
  259. $and: [
  260. { archived: false },
  261. { type: 'board' },
  262. { $or:[] }
  263. ]
  264. };
  265. if(selectedTeamsValues.length > 0)
  266. {
  267. query.$and[2].$or.push({'teams.teamId': {$in : selectedTeamsValues}});
  268. }
  269. if(selectedOrgsValues.length > 0)
  270. {
  271. query.$and[2].$or.push({'orgs.orgId': {$in : selectedOrgsValues}});
  272. }
  273. let filteredBoards = Boards.find(query, {}).fetch();
  274. let allBoards = document.getElementsByClassName("js-board");
  275. let currBoard;
  276. if(filteredBoards.length > 0){
  277. let currBoardId;
  278. let found;
  279. for(let i=0; i < allBoards.length; i++){
  280. currBoard = allBoards[i];
  281. currBoardId = currBoard.classList[0];
  282. found = filteredBoards.find(function(board){
  283. return board._id == currBoardId;
  284. });
  285. if(found !== undefined)
  286. currBoard.style.display = "block";
  287. else
  288. currBoard.style.display = "none";
  289. }
  290. }
  291. else{
  292. for(let i=0; i < allBoards.length; i++){
  293. currBoard = allBoards[i];
  294. currBoard.style.display = "none";
  295. }
  296. }
  297. }
  298. },
  299. },
  300. ];
  301. },
  302. }).register('boardList');