boardsList.js 9.9 KB

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