router.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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. FlowRouter.route('/broken-cards', {
  206. name: 'broken-cards',
  207. action() {
  208. const brokenCardsTemplate = 'brokenCards';
  209. Filter.reset();
  210. Session.set('sortBy', '');
  211. // EscapeActions.executeAll();
  212. EscapeActions.executeUpTo('popup-close');
  213. Utils.manageCustomUI();
  214. Utils.manageMatomo();
  215. BlazeLayout.render('defaultLayout', {
  216. headerBar: 'brokenCardsHeaderBar',
  217. content: brokenCardsTemplate,
  218. });
  219. },
  220. });
  221. FlowRouter.route('/import/:source', {
  222. name: 'import',
  223. triggersEnter: [AccountsTemplates.ensureSignedIn],
  224. action(params) {
  225. if (Session.get('currentBoard')) {
  226. Session.set('fromBoard', Session.get('currentBoard'));
  227. }
  228. Session.set('currentBoard', null);
  229. Session.set('currentList', null);
  230. Session.set('currentCard', null);
  231. Session.set('popupCardId', null);
  232. Session.set('popupCardBoardId', null);
  233. Session.set('importSource', params.source);
  234. Filter.reset();
  235. Session.set('sortBy', '');
  236. EscapeActions.executeAll();
  237. BlazeLayout.render('defaultLayout', {
  238. headerBar: 'importHeaderBar',
  239. content: 'import',
  240. });
  241. },
  242. });
  243. FlowRouter.route('/setting', {
  244. name: 'setting',
  245. triggersEnter: [
  246. AccountsTemplates.ensureSignedIn,
  247. () => {
  248. Session.set('currentBoard', null);
  249. Session.set('currentList', null);
  250. Session.set('currentCard', null);
  251. Session.set('popupCardId', null);
  252. Session.set('popupCardBoardId', null);
  253. Filter.reset();
  254. Session.set('sortBy', '');
  255. EscapeActions.executeAll();
  256. },
  257. ],
  258. action() {
  259. Utils.manageCustomUI();
  260. BlazeLayout.render('defaultLayout', {
  261. headerBar: 'settingHeaderBar',
  262. content: 'setting',
  263. });
  264. },
  265. });
  266. FlowRouter.route('/information', {
  267. name: 'information',
  268. triggersEnter: [
  269. AccountsTemplates.ensureSignedIn,
  270. () => {
  271. Session.set('currentBoard', null);
  272. Session.set('currentList', null);
  273. Session.set('currentCard', null);
  274. Session.set('popupCardId', null);
  275. Session.set('popupCardBoardId', null);
  276. Filter.reset();
  277. Session.set('sortBy', '');
  278. EscapeActions.executeAll();
  279. },
  280. ],
  281. action() {
  282. BlazeLayout.render('defaultLayout', {
  283. headerBar: 'settingHeaderBar',
  284. content: 'information',
  285. });
  286. },
  287. });
  288. FlowRouter.route('/people', {
  289. name: 'people',
  290. triggersEnter: [
  291. AccountsTemplates.ensureSignedIn,
  292. () => {
  293. Session.set('currentBoard', null);
  294. Session.set('currentList', null);
  295. Session.set('currentCard', null);
  296. Session.set('popupCardId', null);
  297. Session.set('popupCardBoardId', null);
  298. Filter.reset();
  299. Session.set('sortBy', '');
  300. EscapeActions.executeAll();
  301. },
  302. ],
  303. action() {
  304. BlazeLayout.render('defaultLayout', {
  305. headerBar: 'settingHeaderBar',
  306. content: 'people',
  307. });
  308. },
  309. });
  310. FlowRouter.route('/admin-reports', {
  311. name: 'admin-reports',
  312. triggersEnter: [
  313. AccountsTemplates.ensureSignedIn,
  314. () => {
  315. Session.set('currentBoard', null);
  316. Session.set('currentList', null);
  317. Session.set('currentCard', null);
  318. Session.set('popupCardId', null);
  319. Session.set('popupCardBoardId', null);
  320. Filter.reset();
  321. Session.set('sortBy', '');
  322. EscapeActions.executeAll();
  323. },
  324. ],
  325. action() {
  326. BlazeLayout.render('defaultLayout', {
  327. headerBar: 'settingHeaderBar',
  328. content: 'adminReports',
  329. });
  330. },
  331. });
  332. FlowRouter.route('/attachments', {
  333. name: 'attachments',
  334. triggersEnter: [
  335. AccountsTemplates.ensureSignedIn,
  336. () => {
  337. Session.set('currentBoard', null);
  338. Session.set('currentList', null);
  339. Session.set('currentCard', null);
  340. Session.set('popupCardId', null);
  341. Session.set('popupCardBoardId', null);
  342. Filter.reset();
  343. Session.set('sortBy', '');
  344. EscapeActions.executeAll();
  345. },
  346. ],
  347. action() {
  348. BlazeLayout.render('defaultLayout', {
  349. headerBar: 'settingHeaderBar',
  350. content: 'attachments',
  351. });
  352. },
  353. });
  354. FlowRouter.route('/translation', {
  355. name: 'translation',
  356. triggersEnter: [
  357. AccountsTemplates.ensureSignedIn,
  358. () => {
  359. Session.set('currentBoard', null);
  360. Session.set('currentList', null);
  361. Session.set('currentCard', null);
  362. Session.set('popupCardId', null);
  363. Session.set('popupCardBoardId', null);
  364. Filter.reset();
  365. Session.set('sortBy', '');
  366. EscapeActions.executeAll();
  367. },
  368. ],
  369. action() {
  370. BlazeLayout.render('defaultLayout', {
  371. headerBar: 'settingHeaderBar',
  372. content: 'translation',
  373. });
  374. },
  375. });
  376. FlowRouter.notFound = {
  377. action() {
  378. BlazeLayout.render('defaultLayout', { content: 'notFound' });
  379. },
  380. };
  381. // We maintain a list of redirections to ensure that we don't break old URLs
  382. // when we change our routing scheme.
  383. const redirections = {
  384. '/boards': '/',
  385. '/boards/:id/:slug': '/b/:id/:slug',
  386. '/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId',
  387. '/import': '/import/trello',
  388. };
  389. _.each(redirections, (newPath, oldPath) => {
  390. FlowRouter.route(oldPath, {
  391. triggersEnter: [
  392. (context, redirect) => {
  393. redirect(FlowRouter.path(newPath, context.params));
  394. },
  395. ],
  396. });
  397. });
  398. // As it is not possible to use template helpers in the page <head> we create a
  399. // reactive function whose role is to set any page-specific tag in the <head>
  400. // using the `kadira:dochead` package. Currently we only use it to display the
  401. // board title if we are in a board page (see #364) but we may want to support
  402. // some <meta> tags in the future.
  403. //const appTitle = Utils.manageCustomUI();
  404. // XXX The `Meteor.startup` should not be necessary -- we don't need to wait for
  405. // the complete DOM to be ready to call `DocHead.setTitle`. But the problem is
  406. // that the global variable `Boards` is undefined when this file loads so we
  407. // wait a bit until hopefully all files are loaded. This will be fixed in a
  408. // clean way once Meteor will support ES6 modules -- hopefully in Meteor 1.3.
  409. //Meteor.isClient && Meteor.startup(() => {
  410. // Tracker.autorun(() => {
  411. // const currentBoard = Utils.getCurrentBoard();
  412. // const titleStack = [appTitle];
  413. // if (currentBoard) {
  414. // titleStack.push(currentBoard.title);
  415. // }
  416. // DocHead.setTitle(titleStack.reverse().join(' - '));
  417. // });
  418. //});