boardsList.js 10 KB

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