router.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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('/b/templates', {
  108. name: 'template-container',
  109. triggersEnter: [AccountsTemplates.ensureSignedIn],
  110. action() {
  111. Session.set('currentBoard', null);
  112. Session.set('currentList', null);
  113. Session.set('currentCard', null);
  114. Session.set('popupCardId', null);
  115. Session.set('popupCardBoardId', null);
  116. Filter.reset();
  117. Session.set('sortBy', '');
  118. EscapeActions.executeAll();
  119. Utils.manageCustomUI();
  120. Utils.manageMatomo();
  121. BlazeLayout.render('defaultLayout', {
  122. headerBar: 'boardListHeaderBar',
  123. content: 'boardList',
  124. });
  125. },
  126. });
  127. FlowRouter.route('/my-cards', {
  128. name: 'my-cards',
  129. triggersEnter: [AccountsTemplates.ensureSignedIn],
  130. action() {
  131. Filter.reset();
  132. Session.set('sortBy', '');
  133. // EscapeActions.executeAll();
  134. EscapeActions.executeUpTo('popup-close');
  135. Utils.manageCustomUI();
  136. Utils.manageMatomo();
  137. BlazeLayout.render('defaultLayout', {
  138. headerBar: 'myCardsHeaderBar',
  139. content: 'myCards',
  140. });
  141. // }
  142. },
  143. });
  144. FlowRouter.route('/due-cards', {
  145. name: 'due-cards',
  146. triggersEnter: [AccountsTemplates.ensureSignedIn],
  147. action() {
  148. Filter.reset();
  149. Session.set('sortBy', '');
  150. // EscapeActions.executeAll();
  151. EscapeActions.executeUpTo('popup-close');
  152. Utils.manageCustomUI();
  153. Utils.manageMatomo();
  154. BlazeLayout.render('defaultLayout', {
  155. headerBar: 'dueCardsHeaderBar',
  156. content: 'dueCards',
  157. });
  158. // }
  159. },
  160. });
  161. FlowRouter.route('/global-search', {
  162. name: 'global-search',
  163. triggersEnter: [AccountsTemplates.ensureSignedIn],
  164. action() {
  165. Filter.reset();
  166. Session.set('sortBy', '');
  167. // EscapeActions.executeAll();
  168. EscapeActions.executeUpTo('popup-close');
  169. Utils.manageCustomUI();
  170. Utils.manageMatomo();
  171. DocHead.setTitle(TAPi18n.__('globalSearch-title'));
  172. if (FlowRouter.getQueryParam('q')) {
  173. Session.set(
  174. 'globalQuery',
  175. decodeURIComponent(FlowRouter.getQueryParam('q')),
  176. );
  177. }
  178. BlazeLayout.render('defaultLayout', {
  179. headerBar: 'globalSearchHeaderBar',
  180. content: 'globalSearch',
  181. });
  182. },
  183. });
  184. FlowRouter.route('/broken-cards', {
  185. name: 'broken-cards',
  186. action() {
  187. const brokenCardsTemplate = 'brokenCards';
  188. Filter.reset();
  189. Session.set('sortBy', '');
  190. // EscapeActions.executeAll();
  191. EscapeActions.executeUpTo('popup-close');
  192. Utils.manageCustomUI();
  193. Utils.manageMatomo();
  194. BlazeLayout.render('defaultLayout', {
  195. headerBar: 'brokenCardsHeaderBar',
  196. content: brokenCardsTemplate,
  197. });
  198. },
  199. });
  200. FlowRouter.route('/import/:source', {
  201. name: 'import',
  202. triggersEnter: [AccountsTemplates.ensureSignedIn],
  203. action(params) {
  204. if (Session.get('currentBoard')) {
  205. Session.set('fromBoard', Session.get('currentBoard'));
  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. Session.set('importSource', params.source);
  213. Filter.reset();
  214. Session.set('sortBy', '');
  215. EscapeActions.executeAll();
  216. BlazeLayout.render('defaultLayout', {
  217. headerBar: 'importHeaderBar',
  218. content: 'import',
  219. });
  220. },
  221. });
  222. FlowRouter.route('/setting', {
  223. name: 'setting',
  224. triggersEnter: [
  225. AccountsTemplates.ensureSignedIn,
  226. () => {
  227. Session.set('currentBoard', null);
  228. Session.set('currentList', null);
  229. Session.set('currentCard', null);
  230. Session.set('popupCardId', null);
  231. Session.set('popupCardBoardId', null);
  232. Filter.reset();
  233. Session.set('sortBy', '');
  234. EscapeActions.executeAll();
  235. },
  236. ],
  237. action() {
  238. Utils.manageCustomUI();
  239. BlazeLayout.render('defaultLayout', {
  240. headerBar: 'settingHeaderBar',
  241. content: 'setting',
  242. });
  243. },
  244. });
  245. FlowRouter.route('/information', {
  246. name: 'information',
  247. triggersEnter: [
  248. AccountsTemplates.ensureSignedIn,
  249. () => {
  250. Session.set('currentBoard', null);
  251. Session.set('currentList', null);
  252. Session.set('currentCard', null);
  253. Session.set('popupCardId', null);
  254. Session.set('popupCardBoardId', null);
  255. Filter.reset();
  256. Session.set('sortBy', '');
  257. EscapeActions.executeAll();
  258. },
  259. ],
  260. action() {
  261. BlazeLayout.render('defaultLayout', {
  262. headerBar: 'settingHeaderBar',
  263. content: 'information',
  264. });
  265. },
  266. });
  267. FlowRouter.route('/people', {
  268. name: 'people',
  269. triggersEnter: [
  270. AccountsTemplates.ensureSignedIn,
  271. () => {
  272. Session.set('currentBoard', null);
  273. Session.set('currentList', null);
  274. Session.set('currentCard', null);
  275. Session.set('popupCardId', null);
  276. Session.set('popupCardBoardId', null);
  277. Filter.reset();
  278. Session.set('sortBy', '');
  279. EscapeActions.executeAll();
  280. },
  281. ],
  282. action() {
  283. BlazeLayout.render('defaultLayout', {
  284. headerBar: 'settingHeaderBar',
  285. content: 'people',
  286. });
  287. },
  288. });
  289. FlowRouter.route('/admin-reports', {
  290. name: 'admin-reports',
  291. triggersEnter: [
  292. AccountsTemplates.ensureSignedIn,
  293. () => {
  294. Session.set('currentBoard', null);
  295. Session.set('currentList', null);
  296. Session.set('currentCard', null);
  297. Session.set('popupCardId', null);
  298. Session.set('popupCardBoardId', null);
  299. Filter.reset();
  300. Session.set('sortBy', '');
  301. EscapeActions.executeAll();
  302. },
  303. ],
  304. action() {
  305. BlazeLayout.render('defaultLayout', {
  306. headerBar: 'settingHeaderBar',
  307. content: 'adminReports',
  308. });
  309. },
  310. });
  311. FlowRouter.notFound = {
  312. action() {
  313. BlazeLayout.render('defaultLayout', { content: 'notFound' });
  314. },
  315. };
  316. // We maintain a list of redirections to ensure that we don't break old URLs
  317. // when we change our routing scheme.
  318. const redirections = {
  319. '/boards': '/',
  320. '/boards/:id/:slug': '/b/:id/:slug',
  321. '/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId',
  322. '/import': '/import/trello',
  323. };
  324. _.each(redirections, (newPath, oldPath) => {
  325. FlowRouter.route(oldPath, {
  326. triggersEnter: [
  327. (context, redirect) => {
  328. redirect(FlowRouter.path(newPath, context.params));
  329. },
  330. ],
  331. });
  332. });
  333. // As it is not possible to use template helpers in the page <head> we create a
  334. // reactive function whose role is to set any page-specific tag in the <head>
  335. // using the `kadira:dochead` package. Currently we only use it to display the
  336. // board title if we are in a board page (see #364) but we may want to support
  337. // some <meta> tags in the future.
  338. //const appTitle = Utils.manageCustomUI();
  339. // XXX The `Meteor.startup` should not be necessary -- we don't need to wait for
  340. // the complete DOM to be ready to call `DocHead.setTitle`. But the problem is
  341. // that the global variable `Boards` is undefined when this file loads so we
  342. // wait a bit until hopefully all files are loaded. This will be fixed in a
  343. // clean way once Meteor will support ES6 modules -- hopefully in Meteor 1.3.
  344. //Meteor.isClient && Meteor.startup(() => {
  345. // Tracker.autorun(() => {
  346. // const currentBoard = Boards.findOne(Session.get('currentBoard'));
  347. // const titleStack = [appTitle];
  348. // if (currentBoard) {
  349. // titleStack.push(currentBoard.title);
  350. // }
  351. // DocHead.setTitle(titleStack.reverse().join(' - '));
  352. // });
  353. //});