router.js 12 KB

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