boardsList.js 12 KB

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