router.js 7.8 KB

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