2
0

boardsList.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. { title: { $not: { $regex: /^\^.*\^$/ } } }
  145. ]
  146. };
  147. let allowPrivateVisibilityOnly = TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly');
  148. if (FlowRouter.getRouteName() === 'home') {
  149. query.$and[2].$or.push({ 'members.userId': Meteor.userId() });
  150. if (allowPrivateVisibilityOnly !== undefined && allowPrivateVisibilityOnly.booleanValue) {
  151. query.$and.push({ 'permission': 'private' });
  152. }
  153. const currUser = Users.findOne(Meteor.userId());
  154. // const currUser = Users.findOne(Meteor.userId(), {
  155. // fields: {
  156. // orgs: 1,
  157. // teams: 1,
  158. // },
  159. // });
  160. let orgIdsUserBelongs = currUser !== undefined && currUser.teams !== 'undefined' ? currUser.orgIdsUserBelongs() : '';
  161. if (orgIdsUserBelongs && orgIdsUserBelongs != '') {
  162. let orgsIds = orgIdsUserBelongs.split(',');
  163. // for(let i = 0; i < orgsIds.length; i++){
  164. // query.$and[2].$or.push({'orgs.orgId': orgsIds[i]});
  165. // }
  166. //query.$and[2].$or.push({'orgs': {$elemMatch : {orgId: orgsIds[0]}}});
  167. query.$and[2].$or.push({ 'orgs.orgId': { $in: orgsIds } });
  168. }
  169. let teamIdsUserBelongs = currUser !== undefined && currUser.teams !== 'undefined' ? currUser.teamIdsUserBelongs() : '';
  170. if (teamIdsUserBelongs && teamIdsUserBelongs != '') {
  171. let teamsIds = teamIdsUserBelongs.split(',');
  172. // for(let i = 0; i < teamsIds.length; i++){
  173. // query.$or[2].$or.push({'teams.teamId': teamsIds[i]});
  174. // }
  175. //query.$and[2].$or.push({'teams': { $elemMatch : {teamId: teamsIds[0]}}});
  176. query.$and[2].$or.push({ 'teams.teamId': { $in: teamsIds } });
  177. }
  178. }
  179. else if (allowPrivateVisibilityOnly !== undefined && !allowPrivateVisibilityOnly.booleanValue) {
  180. query = {
  181. archived: false,
  182. //type: { $in: ['board','template-container'] },
  183. type: 'board',
  184. permission: 'public',
  185. };
  186. }
  187. return Boards.find(query, {
  188. sort: { sort: 1 /* boards default sorting */ },
  189. });
  190. },
  191. boardLists(boardId) {
  192. let boardLists = [];
  193. const lists = Lists.find({ 'boardId': boardId, 'archived': false },{sort: ['sort','asc']});
  194. lists.forEach(list => {
  195. let cardCount = Cards.find({ 'boardId': boardId, 'listId': list._id }).count()
  196. boardLists.push(`${list.title}: ${cardCount}`);
  197. });
  198. return boardLists
  199. },
  200. boardMembers(boardId) {
  201. let boardMembers = [];
  202. const lists = Boards.findOne({ '_id': boardId })
  203. let members = lists.members
  204. members.forEach(member => {
  205. boardMembers.push(member.userId);
  206. });
  207. return boardMembers
  208. },
  209. isStarred() {
  210. const user = Meteor.user();
  211. return user && user.hasStarred(this.currentData()._id);
  212. },
  213. isAdministrable() {
  214. const user = Meteor.user();
  215. return user && user.isBoardAdmin(this.currentData()._id);
  216. },
  217. hasOvertimeCards() {
  218. subManager.subscribe('board', this.currentData()._id, false);
  219. return this.currentData().hasOvertimeCards();
  220. },
  221. hasSpentTimeCards() {
  222. subManager.subscribe('board', this.currentData()._id, false);
  223. return this.currentData().hasSpentTimeCards();
  224. },
  225. isInvited() {
  226. const user = Meteor.user();
  227. return user && user.isInvitedTo(this.currentData()._id);
  228. },
  229. events() {
  230. return [
  231. {
  232. 'click .js-add-board': Popup.open('createBoard'),
  233. 'click .js-star-board'(evt) {
  234. const boardId = this.currentData()._id;
  235. Meteor.user().toggleBoardStar(boardId);
  236. evt.preventDefault();
  237. },
  238. 'click .js-clone-board'(evt) {
  239. let title = getSlug(Boards.findOne(this.currentData()._id).title) || 'cloned-board';
  240. Meteor.call(
  241. 'copyBoard',
  242. this.currentData()._id,
  243. {
  244. sort: Boards.find({ archived: false }).count(),
  245. type: 'board',
  246. title: Boards.findOne(this.currentData()._id).title,
  247. },
  248. (err, res) => {
  249. if (err) {
  250. console.error(err);
  251. } else {
  252. Session.set('fromBoard', null);
  253. subManager.subscribe('board', res, false);
  254. FlowRouter.go('board', {
  255. id: res,
  256. slug: title,
  257. });
  258. }
  259. },
  260. );
  261. evt.preventDefault();
  262. },
  263. 'click .js-archive-board'(evt) {
  264. const boardId = this.currentData()._id;
  265. Meteor.call('archiveBoard', boardId);
  266. evt.preventDefault();
  267. },
  268. 'click .js-accept-invite'() {
  269. const boardId = this.currentData()._id;
  270. Meteor.call('acceptInvite', boardId);
  271. },
  272. 'click .js-decline-invite'() {
  273. const boardId = this.currentData()._id;
  274. Meteor.call('quitBoard', boardId, (err, ret) => {
  275. if (!err && ret) {
  276. Meteor.call('acceptInvite', boardId);
  277. FlowRouter.go('home');
  278. }
  279. });
  280. },
  281. 'click #resetBtn'(event) {
  282. let allBoards = document.getElementsByClassName("js-board");
  283. let currBoard;
  284. for (let i = 0; i < allBoards.length; i++) {
  285. currBoard = allBoards[i];
  286. currBoard.style.display = "block";
  287. }
  288. },
  289. 'click #filterBtn'(event) {
  290. event.preventDefault();
  291. let selectedTeams = document.querySelectorAll('#jsAllBoardTeams option:checked');
  292. let selectedTeamsValues = Array.from(selectedTeams).map(function (elt) { return elt.value });
  293. let index = selectedTeamsValues.indexOf("-1");
  294. if (index > -1) {
  295. selectedTeamsValues.splice(index, 1);
  296. }
  297. let selectedOrgs = document.querySelectorAll('#jsAllBoardOrgs option:checked');
  298. let selectedOrgsValues = Array.from(selectedOrgs).map(function (elt) { return elt.value });
  299. index = selectedOrgsValues.indexOf("-1");
  300. if (index > -1) {
  301. selectedOrgsValues.splice(index, 1);
  302. }
  303. if (selectedTeamsValues.length > 0 || selectedOrgsValues.length > 0) {
  304. const query = {
  305. $and: [
  306. { archived: false },
  307. { type: 'board' },
  308. { $or: [] }
  309. ]
  310. };
  311. if (selectedTeamsValues.length > 0) {
  312. query.$and[2].$or.push({ 'teams.teamId': { $in: selectedTeamsValues } });
  313. }
  314. if (selectedOrgsValues.length > 0) {
  315. query.$and[2].$or.push({ 'orgs.orgId': { $in: selectedOrgsValues } });
  316. }
  317. let filteredBoards = Boards.find(query, {}).fetch();
  318. let allBoards = document.getElementsByClassName("js-board");
  319. let currBoard;
  320. if (filteredBoards.length > 0) {
  321. let currBoardId;
  322. let found;
  323. for (let i = 0; i < allBoards.length; i++) {
  324. currBoard = allBoards[i];
  325. currBoardId = currBoard.classList[0];
  326. found = filteredBoards.find(function (board) {
  327. return board._id == currBoardId;
  328. });
  329. if (found !== undefined)
  330. currBoard.style.display = "block";
  331. else
  332. currBoard.style.display = "none";
  333. }
  334. }
  335. else {
  336. for (let i = 0; i < allBoards.length; i++) {
  337. currBoard = allBoards[i];
  338. currBoard.style.display = "none";
  339. }
  340. }
  341. }
  342. },
  343. },
  344. ];
  345. },
  346. }).register('boardList');