boardsList.js 10 KB

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