boardsList.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. //if (FlowRouter.getRouteName() === 'template-container') {
  10. // return 'template-container';
  11. //} else {
  12. return FlowRouter.getRouteName() === 'home' ? 'my-boards' : 'public';
  13. //}
  14. },
  15. templatesBoardId() {
  16. return Meteor.user() && Meteor.user().getTemplatesBoardId();
  17. },
  18. templatesBoardSlug() {
  19. return Meteor.user() && Meteor.user().getTemplatesBoardSlug();
  20. },
  21. });
  22. BlazeComponent.extendComponent({
  23. onCreated() {
  24. Meteor.subscribe('setting');
  25. Meteor.subscribe('tableVisibilityModeSettings');
  26. let currUser = Meteor.user();
  27. let userLanguage;
  28. if(currUser && currUser.profile){
  29. userLanguage = currUser.profile.language
  30. }
  31. if (userLanguage) {
  32. TAPi18n.setLanguage(userLanguage);
  33. T9n.setLanguage(userLanguage);
  34. }
  35. },
  36. onRendered() {
  37. const itemsSelector = '.js-board:not(.placeholder)';
  38. const $boards = this.$('.js-boards');
  39. $boards.sortable({
  40. connectWith: '.js-boards',
  41. tolerance: 'pointer',
  42. appendTo: '.board-list',
  43. helper: 'clone',
  44. distance: 7,
  45. items: itemsSelector,
  46. placeholder: 'board-wrapper placeholder',
  47. start(evt, ui) {
  48. ui.helper.css('z-index', 1000);
  49. ui.placeholder.height(ui.helper.height());
  50. EscapeActions.executeUpTo('popup-close');
  51. },
  52. stop(evt, ui) {
  53. // To attribute the new index number, we need to get the DOM element
  54. // of the previous and the following card -- if any.
  55. const prevBoardDom = ui.item.prev('.js-board').get(0);
  56. const nextBoardBom = ui.item.next('.js-board').get(0);
  57. const sortIndex = Utils.calculateIndex(prevBoardDom, nextBoardBom, 1);
  58. const boardDomElement = ui.item.get(0);
  59. const board = Blaze.getData(boardDomElement);
  60. // Normally the jquery-ui sortable library moves the dragged DOM element
  61. // to its new position, which disrupts Blaze reactive updates mechanism
  62. // (especially when we move the last card of a list, or when multiple
  63. // users move some cards at the same time). To prevent these UX glitches
  64. // we ask sortable to gracefully cancel the move, and to put back the
  65. // DOM in its initial state. The card move is then handled reactively by
  66. // Blaze with the below query.
  67. $boards.sortable('cancel');
  68. board.move(sortIndex.base);
  69. },
  70. });
  71. // Disable drag-dropping if the current user is not a board member or is comment only
  72. this.autorun(() => {
  73. if (Utils.isMiniScreenOrShowDesktopDragHandles()) {
  74. $boards.sortable({
  75. handle: '.board-handle',
  76. });
  77. }
  78. });
  79. },
  80. userHasTeams(){
  81. if(Meteor.user() != null && Meteor.user().teams && Meteor.user().teams.length > 0)
  82. return true;
  83. else
  84. return false;
  85. },
  86. teamsDatas() {
  87. if(Meteor.user().teams)
  88. return Meteor.user().teams.sort((a, b) => a.teamDisplayName.localeCompare(b.teamDisplayName));
  89. else
  90. return [];
  91. },
  92. userHasOrgs(){
  93. if(Meteor.user() != null && Meteor.user().orgs && Meteor.user().orgs.length > 0)
  94. return true;
  95. else
  96. return false;
  97. },
  98. /*
  99. userHasTemplates(){
  100. if(Meteor.user() != null && Meteor.user().orgs && Meteor.user().orgs.length > 0)
  101. return true;
  102. else
  103. return false;
  104. },
  105. */
  106. orgsDatas() {
  107. if(Meteor.user().orgs)
  108. return Meteor.user().orgs.sort((a, b) => a.orgDisplayName.localeCompare(b.orgDisplayName));
  109. else
  110. return [];
  111. },
  112. userHasOrgsOrTeams(){
  113. let boolUserHasOrgs;
  114. if(Meteor.user() != null && Meteor.user().orgs && Meteor.user().orgs.length > 0)
  115. boolUserHasOrgs = true;
  116. else
  117. boolUserHasOrgs = false;
  118. let boolUserHasTeams;
  119. if(Meteor.user() != null && Meteor.user().teams && Meteor.user().teams.length > 0)
  120. boolUserHasTeams = true;
  121. else
  122. boolUserHasTeams = false;
  123. return (boolUserHasOrgs || boolUserHasTeams);
  124. },
  125. boards() {
  126. let query = {
  127. // { type: 'board' },
  128. // { type: { $in: ['board','template-container'] } },
  129. $and: [
  130. { archived: false },
  131. { type: { $in: ['board','template-container'] } },
  132. { $or:[] }
  133. ]
  134. };
  135. let allowPrivateVisibilityOnly = TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly');
  136. if (FlowRouter.getRouteName() === 'home'){
  137. query.$and[2].$or.push({'members.userId': Meteor.userId()});
  138. if(allowPrivateVisibilityOnly !== undefined && allowPrivateVisibilityOnly.booleanValue){
  139. query.$and.push({'permission': 'private'});
  140. }
  141. const currUser = Users.findOne(Meteor.userId());
  142. // const currUser = Users.findOne(Meteor.userId(), {
  143. // fields: {
  144. // orgs: 1,
  145. // teams: 1,
  146. // },
  147. // });
  148. let orgIdsUserBelongs = currUser !== undefined && currUser.teams !== 'undefined' ? currUser.orgIdsUserBelongs() : '';
  149. if(orgIdsUserBelongs && orgIdsUserBelongs != ''){
  150. let orgsIds = orgIdsUserBelongs.split(',');
  151. // for(let i = 0; i < orgsIds.length; i++){
  152. // query.$and[2].$or.push({'orgs.orgId': orgsIds[i]});
  153. // }
  154. //query.$and[2].$or.push({'orgs': {$elemMatch : {orgId: orgsIds[0]}}});
  155. query.$and[2].$or.push({'orgs.orgId': {$in : orgsIds}});
  156. }
  157. let teamIdsUserBelongs = currUser !== undefined && currUser.teams !== 'undefined' ? currUser.teamIdsUserBelongs() : '';
  158. if(teamIdsUserBelongs && teamIdsUserBelongs != ''){
  159. let teamsIds = teamIdsUserBelongs.split(',');
  160. // for(let i = 0; i < teamsIds.length; i++){
  161. // query.$or[2].$or.push({'teams.teamId': teamsIds[i]});
  162. // }
  163. //query.$and[2].$or.push({'teams': { $elemMatch : {teamId: teamsIds[0]}}});
  164. query.$and[2].$or.push({'teams.teamId': {$in : teamsIds}});
  165. }
  166. }
  167. else if(allowPrivateVisibilityOnly !== undefined && !allowPrivateVisibilityOnly.booleanValue){
  168. query = {
  169. archived: false,
  170. //type: { $in: ['board','template-container'] },
  171. type: 'board',
  172. permission: 'public',
  173. };
  174. }
  175. return Boards.find(query, {
  176. sort: { sort: 1 /* boards default sorting */ },
  177. });
  178. },
  179. isStarred() {
  180. const user = Meteor.user();
  181. return user && user.hasStarred(this.currentData()._id);
  182. },
  183. isAdministrable() {
  184. const user = Meteor.user();
  185. return user && user.isBoardAdmin(this.currentData()._id);
  186. },
  187. hasOvertimeCards() {
  188. subManager.subscribe('board', this.currentData()._id, false);
  189. return this.currentData().hasOvertimeCards();
  190. },
  191. hasSpentTimeCards() {
  192. subManager.subscribe('board', this.currentData()._id, false);
  193. return this.currentData().hasSpentTimeCards();
  194. },
  195. isInvited() {
  196. const user = Meteor.user();
  197. return user && user.isInvitedTo(this.currentData()._id);
  198. },
  199. events() {
  200. return [
  201. {
  202. 'click .js-add-board': Popup.open('createBoard'),
  203. 'click .js-star-board'(evt) {
  204. const boardId = this.currentData()._id;
  205. Meteor.user().toggleBoardStar(boardId);
  206. evt.preventDefault();
  207. },
  208. 'click .js-clone-board'(evt) {
  209. let title = getSlug(Boards.findOne(this.currentData()._id).title) || 'cloned-board';
  210. Meteor.call(
  211. 'copyBoard',
  212. this.currentData()._id,
  213. {
  214. sort: Boards.find({ archived: false }).count(),
  215. type: 'board',
  216. title: Boards.findOne(this.currentData()._id).title,
  217. },
  218. (err, res) => {
  219. if (err) {
  220. this.setError(err.error);
  221. } else {
  222. Session.set('fromBoard', null);
  223. subManager.subscribe('board', res, false);
  224. FlowRouter.go('board', {
  225. id: res,
  226. slug: title,
  227. });
  228. //Utils.goBoardId(res);
  229. }
  230. },
  231. );
  232. evt.preventDefault();
  233. },
  234. 'click .js-archive-board'(evt) {
  235. const boardId = this.currentData()._id;
  236. Meteor.call('archiveBoard', boardId);
  237. evt.preventDefault();
  238. },
  239. 'click .js-accept-invite'() {
  240. const boardId = this.currentData()._id;
  241. Meteor.call('acceptInvite', boardId);
  242. },
  243. 'click .js-decline-invite'() {
  244. const boardId = this.currentData()._id;
  245. Meteor.call('quitBoard', boardId, (err, ret) => {
  246. if (!err && ret) {
  247. Meteor.call('acceptInvite', boardId);
  248. FlowRouter.go('home');
  249. }
  250. });
  251. },
  252. 'click #resetBtn'(event){
  253. let allBoards = document.getElementsByClassName("js-board");
  254. let currBoard;
  255. for(let i=0; i < allBoards.length; i++){
  256. currBoard = allBoards[i];
  257. currBoard.style.display = "block";
  258. }
  259. },
  260. 'click #filterBtn'(event) {
  261. event.preventDefault();
  262. let selectedTeams = document.querySelectorAll('#jsAllBoardTeams option:checked');
  263. let selectedTeamsValues = Array.from(selectedTeams).map(function(elt){return elt.value});
  264. let index = selectedTeamsValues.indexOf("-1");
  265. if (index > -1) {
  266. selectedTeamsValues.splice(index, 1);
  267. }
  268. let selectedOrgs = document.querySelectorAll('#jsAllBoardOrgs option:checked');
  269. let selectedOrgsValues = Array.from(selectedOrgs).map(function(elt){return elt.value});
  270. index = selectedOrgsValues.indexOf("-1");
  271. if (index > -1) {
  272. selectedOrgsValues.splice(index, 1);
  273. }
  274. if(selectedTeamsValues.length > 0 || selectedOrgsValues.length > 0){
  275. const query = {
  276. $and: [
  277. { archived: false },
  278. { type: 'board' },
  279. { $or:[] }
  280. ]
  281. };
  282. if(selectedTeamsValues.length > 0)
  283. {
  284. query.$and[2].$or.push({'teams.teamId': {$in : selectedTeamsValues}});
  285. }
  286. if(selectedOrgsValues.length > 0)
  287. {
  288. query.$and[2].$or.push({'orgs.orgId': {$in : selectedOrgsValues}});
  289. }
  290. let filteredBoards = Boards.find(query, {}).fetch();
  291. let allBoards = document.getElementsByClassName("js-board");
  292. let currBoard;
  293. if(filteredBoards.length > 0){
  294. let currBoardId;
  295. let found;
  296. for(let i=0; i < allBoards.length; i++){
  297. currBoard = allBoards[i];
  298. currBoardId = currBoard.classList[0];
  299. found = filteredBoards.find(function(board){
  300. return board._id == currBoardId;
  301. });
  302. if(found !== undefined)
  303. currBoard.style.display = "block";
  304. else
  305. currBoard.style.display = "none";
  306. }
  307. }
  308. else{
  309. for(let i=0; i < allBoards.length; i++){
  310. currBoard = allBoards[i];
  311. currBoard.style.display = "none";
  312. }
  313. }
  314. }
  315. },
  316. },
  317. ];
  318. },
  319. }).register('boardList');