router.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. let previousPath;
  2. FlowRouter.triggers.exit([
  3. ({ path }) => {
  4. previousPath = path;
  5. },
  6. ]);
  7. FlowRouter.route('/', {
  8. name: 'home',
  9. triggersEnter: [AccountsTemplates.ensureSignedIn],
  10. action() {
  11. Session.set('currentBoard', null);
  12. Session.set('currentList', null);
  13. Session.set('currentCard', null);
  14. Session.set('popupCardId', null);
  15. Session.set('popupCardBoardId', null);
  16. Filter.reset();
  17. Session.set('sortBy', '');
  18. EscapeActions.executeAll();
  19. Utils.manageCustomUI();
  20. Utils.manageMatomo();
  21. BlazeLayout.render('defaultLayout', {
  22. headerBar: 'boardListHeaderBar',
  23. content: 'boardList',
  24. });
  25. },
  26. });
  27. FlowRouter.route('/public', {
  28. name: 'public',
  29. triggersEnter: [AccountsTemplates.ensureSignedIn],
  30. action() {
  31. Session.set('currentBoard', null);
  32. Session.set('currentList', null);
  33. Session.set('currentCard', null);
  34. Session.set('popupCardId', null);
  35. Session.set('popupCardBoardId', null);
  36. Filter.reset();
  37. Session.set('sortBy', '');
  38. EscapeActions.executeAll();
  39. Utils.manageCustomUI();
  40. Utils.manageMatomo();
  41. BlazeLayout.render('defaultLayout', {
  42. headerBar: 'boardListHeaderBar',
  43. content: 'boardList',
  44. });
  45. },
  46. });
  47. FlowRouter.route('/b/:id/:slug', {
  48. name: 'board',
  49. action(params) {
  50. const currentBoard = params.id;
  51. const previousBoard = Session.get('currentBoard');
  52. Session.set('currentBoard', currentBoard);
  53. Session.set('currentCard', null);
  54. Session.set('popupCardId', null);
  55. Session.set('popupCardBoardId', null);
  56. // If we close a card, we'll execute again this route action but we don't
  57. // want to excape every current actions (filters, etc.)
  58. if (previousBoard !== currentBoard) {
  59. Filter.reset();
  60. Session.set('sortBy', '');
  61. EscapeActions.executeAll();
  62. } else {
  63. EscapeActions.executeUpTo('popup-close');
  64. }
  65. Utils.manageCustomUI();
  66. Utils.manageMatomo();
  67. BlazeLayout.render('defaultLayout', {
  68. headerBar: 'boardHeaderBar',
  69. content: 'board',
  70. });
  71. },
  72. });
  73. FlowRouter.route('/b/:boardId/:slug/:cardId', {
  74. name: 'card',
  75. action(params) {
  76. EscapeActions.executeUpTo('inlinedForm');
  77. Session.set('currentBoard', params.boardId);
  78. Session.set('currentCard', params.cardId);
  79. Session.set('popupCardId', null);
  80. Session.set('popupCardBoardId', null);
  81. Utils.manageCustomUI();
  82. Utils.manageMatomo();
  83. BlazeLayout.render('defaultLayout', {
  84. headerBar: 'boardHeaderBar',
  85. content: 'board',
  86. });
  87. },
  88. });
  89. FlowRouter.route('/shortcuts', {
  90. name: 'shortcuts',
  91. action() {
  92. const shortcutsTemplate = 'keyboardShortcuts';
  93. EscapeActions.executeUpTo('popup-close');
  94. if (previousPath) {
  95. Modal.open(shortcutsTemplate, {
  96. header: 'shortcutsModalTitle',
  97. onCloseGoTo: previousPath,
  98. });
  99. } else {
  100. BlazeLayout.render('defaultLayout', {
  101. headerBar: 'shortcutsHeaderBar',
  102. content: shortcutsTemplate,
  103. });
  104. }
  105. },
  106. });
  107. FlowRouter.route('/my-cards', {
  108. name: 'my-cards',
  109. triggersEnter: [AccountsTemplates.ensureSignedIn],
  110. action() {
  111. Filter.reset();
  112. Session.set('sortBy', '');
  113. // EscapeActions.executeAll();
  114. EscapeActions.executeUpTo('popup-close');
  115. Utils.manageCustomUI();
  116. Utils.manageMatomo();
  117. BlazeLayout.render('defaultLayout', {
  118. headerBar: 'myCardsHeaderBar',
  119. content: 'myCards',
  120. });
  121. // }
  122. },
  123. });
  124. FlowRouter.route('/due-cards', {
  125. name: 'due-cards',
  126. triggersEnter: [AccountsTemplates.ensureSignedIn],
  127. action() {
  128. Filter.reset();
  129. Session.set('sortBy', '');
  130. // EscapeActions.executeAll();
  131. EscapeActions.executeUpTo('popup-close');
  132. Utils.manageCustomUI();
  133. Utils.manageMatomo();
  134. BlazeLayout.render('defaultLayout', {
  135. headerBar: 'dueCardsHeaderBar',
  136. content: 'dueCards',
  137. });
  138. // }
  139. },
  140. });
  141. FlowRouter.route('/global-search', {
  142. name: 'global-search',
  143. triggersEnter: [AccountsTemplates.ensureSignedIn],
  144. action() {
  145. Filter.reset();
  146. Session.set('sortBy', '');
  147. // EscapeActions.executeAll();
  148. EscapeActions.executeUpTo('popup-close');
  149. Utils.manageCustomUI();
  150. Utils.manageMatomo();
  151. DocHead.setTitle(TAPi18n.__('globalSearch-title'));
  152. if (FlowRouter.getQueryParam('q')) {
  153. Session.set(
  154. 'globalQuery',
  155. decodeURIComponent(FlowRouter.getQueryParam('q')),
  156. );
  157. }
  158. BlazeLayout.render('defaultLayout', {
  159. headerBar: 'globalSearchHeaderBar',
  160. content: 'globalSearch',
  161. });
  162. },
  163. });
  164. FlowRouter.route('/broken-cards', {
  165. name: 'broken-cards',
  166. action() {
  167. const brokenCardsTemplate = 'brokenCards';
  168. Filter.reset();
  169. Session.set('sortBy', '');
  170. // EscapeActions.executeAll();
  171. EscapeActions.executeUpTo('popup-close');
  172. Utils.manageCustomUI();
  173. Utils.manageMatomo();
  174. BlazeLayout.render('defaultLayout', {
  175. headerBar: 'brokenCardsHeaderBar',
  176. content: brokenCardsTemplate,
  177. });
  178. },
  179. });
  180. FlowRouter.route('/import/:source', {
  181. name: 'import',
  182. triggersEnter: [AccountsTemplates.ensureSignedIn],
  183. action(params) {
  184. if (Session.get('currentBoard')) {
  185. Session.set('fromBoard', Session.get('currentBoard'));
  186. }
  187. Session.set('currentBoard', null);
  188. Session.set('currentList', null);
  189. Session.set('currentCard', null);
  190. Session.set('popupCardId', null);
  191. Session.set('popupCardBoardId', null);
  192. Session.set('importSource', params.source);
  193. Filter.reset();
  194. Session.set('sortBy', '');
  195. EscapeActions.executeAll();
  196. BlazeLayout.render('defaultLayout', {
  197. headerBar: 'importHeaderBar',
  198. content: 'import',
  199. });
  200. },
  201. });
  202. FlowRouter.route('/setting', {
  203. name: 'setting',
  204. triggersEnter: [
  205. AccountsTemplates.ensureSignedIn,
  206. () => {
  207. Session.set('currentBoard', null);
  208. Session.set('currentList', null);
  209. Session.set('currentCard', null);
  210. Session.set('popupCardId', null);
  211. Session.set('popupCardBoardId', null);
  212. Filter.reset();
  213. Session.set('sortBy', '');
  214. EscapeActions.executeAll();
  215. },
  216. ],
  217. action() {
  218. Utils.manageCustomUI();
  219. BlazeLayout.render('defaultLayout', {
  220. headerBar: 'settingHeaderBar',
  221. content: 'setting',
  222. });
  223. },
  224. });
  225. FlowRouter.route('/information', {
  226. name: 'information',
  227. triggersEnter: [
  228. AccountsTemplates.ensureSignedIn,
  229. () => {
  230. Session.set('currentBoard', null);
  231. Session.set('currentList', null);
  232. Session.set('currentCard', null);
  233. Session.set('popupCardId', null);
  234. Session.set('popupCardBoardId', null);
  235. Filter.reset();
  236. Session.set('sortBy', '');
  237. EscapeActions.executeAll();
  238. },
  239. ],
  240. action() {
  241. BlazeLayout.render('defaultLayout', {
  242. headerBar: 'settingHeaderBar',
  243. content: 'information',
  244. });
  245. },
  246. });
  247. FlowRouter.route('/people', {
  248. name: 'people',
  249. triggersEnter: [
  250. AccountsTemplates.ensureSignedIn,
  251. () => {
  252. Session.set('currentBoard', null);
  253. Session.set('currentList', null);
  254. Session.set('currentCard', null);
  255. Session.set('popupCardId', null);
  256. Session.set('popupCardBoardId', null);
  257. Filter.reset();
  258. Session.set('sortBy', '');
  259. EscapeActions.executeAll();
  260. },
  261. ],
  262. action() {
  263. BlazeLayout.render('defaultLayout', {
  264. headerBar: 'settingHeaderBar',
  265. content: 'people',
  266. });
  267. },
  268. });
  269. FlowRouter.route('/admin-reports', {
  270. name: 'admin-reports',
  271. triggersEnter: [
  272. AccountsTemplates.ensureSignedIn,
  273. () => {
  274. Session.set('currentBoard', null);
  275. Session.set('currentList', null);
  276. Session.set('currentCard', null);
  277. Session.set('popupCardId', null);
  278. Session.set('popupCardBoardId', null);
  279. Filter.reset();
  280. Session.set('sortBy', '');
  281. EscapeActions.executeAll();
  282. },
  283. ],
  284. action() {
  285. BlazeLayout.render('defaultLayout', {
  286. headerBar: 'settingHeaderBar',
  287. content: 'adminReports',
  288. });
  289. },
  290. });
  291. FlowRouter.notFound = {
  292. action() {
  293. BlazeLayout.render('defaultLayout', { content: 'notFound' });
  294. },
  295. };
  296. // We maintain a list of redirections to ensure that we don't break old URLs
  297. // when we change our routing scheme.
  298. const redirections = {
  299. '/boards': '/',
  300. '/boards/:id/:slug': '/b/:id/:slug',
  301. '/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId',
  302. '/import': '/import/trello',
  303. };
  304. _.each(redirections, (newPath, oldPath) => {
  305. FlowRouter.route(oldPath, {
  306. triggersEnter: [
  307. (context, redirect) => {
  308. redirect(FlowRouter.path(newPath, context.params));
  309. },
  310. ],
  311. });
  312. });
  313. // As it is not possible to use template helpers in the page <head> we create a
  314. // reactive function whose role is to set any page-specific tag in the <head>
  315. // using the `kadira:dochead` package. Currently we only use it to display the
  316. // board title if we are in a board page (see #364) but we may want to support
  317. // some <meta> tags in the future.
  318. //const appTitle = Utils.manageCustomUI();
  319. // XXX The `Meteor.startup` should not be necessary -- we don't need to wait for
  320. // the complete DOM to be ready to call `DocHead.setTitle`. But the problem is
  321. // that the global variable `Boards` is undefined when this file loads so we
  322. // wait a bit until hopefully all files are loaded. This will be fixed in a
  323. // clean way once Meteor will support ES6 modules -- hopefully in Meteor 1.3.
  324. //Meteor.isClient && Meteor.startup(() => {
  325. // Tracker.autorun(() => {
  326. // const currentBoard = Boards.findOne(Session.get('currentBoard'));
  327. // const titleStack = [appTitle];
  328. // if (currentBoard) {
  329. // titleStack.push(currentBoard.title);
  330. // }
  331. // DocHead.setTitle(titleStack.reverse().join(' - '));
  332. // });
  333. //});