boardsList.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. import { TAPi18n } from '/imports/i18n';
  2. const subManager = new SubsManager();
  3. Template.boardListHeaderBar.events({
  4. 'click .js-open-archived-board'() {
  5. Modal.open('archivedBoards');
  6. },
  7. });
  8. Template.boardListHeaderBar.helpers({
  9. title() {
  10. //if (FlowRouter.getRouteName() === 'template-container') {
  11. // return 'template-container';
  12. //} else {
  13. return FlowRouter.getRouteName() === 'home' ? 'my-boards' : 'public';
  14. //}
  15. },
  16. templatesBoardId() {
  17. return Meteor.user() && Meteor.user().getTemplatesBoardId();
  18. },
  19. templatesBoardSlug() {
  20. return Meteor.user() && Meteor.user().getTemplatesBoardSlug();
  21. },
  22. });
  23. BlazeComponent.extendComponent({
  24. onCreated() {
  25. Meteor.subscribe('setting');
  26. Meteor.subscribe('tableVisibilityModeSettings');
  27. let currUser = Meteor.user();
  28. let userLanguage;
  29. if(currUser && currUser.profile){
  30. userLanguage = currUser.profile.language
  31. }
  32. if (userLanguage) {
  33. TAPi18n.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. Meteor.call(
  210. 'copyBoard',
  211. this.currentData()._id,
  212. {
  213. sort: Boards.find({ archived: false }).count(),
  214. type: 'board',
  215. title: Boards.findOne(this.currentData()._id).title,
  216. },
  217. (err, res) => {
  218. if (err) {
  219. this.setError(err.error);
  220. } else {
  221. Session.set('fromBoard', null);
  222. subManager.subscribe('board', res, false);
  223. Utils.goBoardId(res);
  224. }
  225. },
  226. );
  227. evt.preventDefault();
  228. },
  229. 'click .js-archive-board'(evt) {
  230. const boardId = this.currentData()._id;
  231. Meteor.call('archiveBoard', boardId);
  232. evt.preventDefault();
  233. },
  234. 'click .js-accept-invite'() {
  235. const boardId = this.currentData()._id;
  236. Meteor.call('acceptInvite', boardId);
  237. },
  238. 'click .js-decline-invite'() {
  239. const boardId = this.currentData()._id;
  240. Meteor.call('quitBoard', boardId, (err, ret) => {
  241. if (!err && ret) {
  242. Meteor.call('acceptInvite', boardId);
  243. FlowRouter.go('home');
  244. }
  245. });
  246. },
  247. 'click #resetBtn'(event){
  248. let allBoards = document.getElementsByClassName("js-board");
  249. let currBoard;
  250. for(let i=0; i < allBoards.length; i++){
  251. currBoard = allBoards[i];
  252. currBoard.style.display = "block";
  253. }
  254. },
  255. 'click #filterBtn'(event) {
  256. event.preventDefault();
  257. let selectedTeams = document.querySelectorAll('#jsAllBoardTeams option:checked');
  258. let selectedTeamsValues = Array.from(selectedTeams).map(function(elt){return elt.value});
  259. let index = selectedTeamsValues.indexOf("-1");
  260. if (index > -1) {
  261. selectedTeamsValues.splice(index, 1);
  262. }
  263. let selectedOrgs = document.querySelectorAll('#jsAllBoardOrgs option:checked');
  264. let selectedOrgsValues = Array.from(selectedOrgs).map(function(elt){return elt.value});
  265. index = selectedOrgsValues.indexOf("-1");
  266. if (index > -1) {
  267. selectedOrgsValues.splice(index, 1);
  268. }
  269. if(selectedTeamsValues.length > 0 || selectedOrgsValues.length > 0){
  270. const query = {
  271. $and: [
  272. { archived: false },
  273. { type: 'board' },
  274. { $or:[] }
  275. ]
  276. };
  277. if(selectedTeamsValues.length > 0)
  278. {
  279. query.$and[2].$or.push({'teams.teamId': {$in : selectedTeamsValues}});
  280. }
  281. if(selectedOrgsValues.length > 0)
  282. {
  283. query.$and[2].$or.push({'orgs.orgId': {$in : selectedOrgsValues}});
  284. }
  285. let filteredBoards = Boards.find(query, {}).fetch();
  286. let allBoards = document.getElementsByClassName("js-board");
  287. let currBoard;
  288. if(filteredBoards.length > 0){
  289. let currBoardId;
  290. let found;
  291. for(let i=0; i < allBoards.length; i++){
  292. currBoard = allBoards[i];
  293. currBoardId = currBoard.classList[0];
  294. found = filteredBoards.find(function(board){
  295. return board._id == currBoardId;
  296. });
  297. if(found !== undefined)
  298. currBoard.style.display = "block";
  299. else
  300. currBoard.style.display = "none";
  301. }
  302. }
  303. else{
  304. for(let i=0; i < allBoards.length; i++){
  305. currBoard = allBoards[i];
  306. currBoard.style.display = "none";
  307. }
  308. }
  309. }
  310. },
  311. },
  312. ];
  313. },
  314. }).register('boardList');