router.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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('/b/:id/:slug', {
  25. name: 'board',
  26. action(params) {
  27. const currentBoard = params.id;
  28. const previousBoard = Session.get('currentBoard');
  29. Session.set('currentBoard', currentBoard);
  30. Session.set('currentCard', null);
  31. // If we close a card, we'll execute again this route action but we don't
  32. // want to excape every current actions (filters, etc.)
  33. if (previousBoard !== currentBoard) {
  34. Filter.reset();
  35. EscapeActions.executeAll();
  36. } else {
  37. EscapeActions.executeUpTo('popup-close');
  38. }
  39. Utils.manageCustomUI();
  40. Utils.manageMatomo();
  41. BlazeLayout.render('defaultLayout', {
  42. headerBar: 'boardHeaderBar',
  43. content: 'board',
  44. });
  45. },
  46. });
  47. FlowRouter.route('/b/:boardId/:slug/:cardId', {
  48. name: 'card',
  49. action(params) {
  50. EscapeActions.executeUpTo('inlinedForm');
  51. Session.set('currentBoard', params.boardId);
  52. Session.set('currentCard', params.cardId);
  53. Utils.manageCustomUI();
  54. Utils.manageMatomo();
  55. BlazeLayout.render('defaultLayout', {
  56. headerBar: 'boardHeaderBar',
  57. content: 'board',
  58. });
  59. },
  60. });
  61. FlowRouter.route('/shortcuts', {
  62. name: 'shortcuts',
  63. action() {
  64. const shortcutsTemplate = 'keyboardShortcuts';
  65. EscapeActions.executeUpTo('popup-close');
  66. if (previousPath) {
  67. Modal.open(shortcutsTemplate, {
  68. header: 'shortcutsModalTitle',
  69. onCloseGoTo: previousPath,
  70. });
  71. } else {
  72. BlazeLayout.render('defaultLayout', {
  73. headerBar: 'shortcutsHeaderBar',
  74. content: shortcutsTemplate,
  75. });
  76. }
  77. },
  78. });
  79. FlowRouter.route('/import/:source', {
  80. name: 'import',
  81. triggersEnter: [AccountsTemplates.ensureSignedIn],
  82. action(params) {
  83. if (Session.get('currentBoard')) {
  84. Session.set('fromBoard', Session.get('currentBoard'));
  85. }
  86. Session.set('currentBoard', null);
  87. Session.set('currentList', null);
  88. Session.set('currentCard', null);
  89. Session.set('importSource', params.source);
  90. Filter.reset();
  91. EscapeActions.executeAll();
  92. BlazeLayout.render('defaultLayout', {
  93. headerBar: 'importHeaderBar',
  94. content: 'import',
  95. });
  96. },
  97. });
  98. FlowRouter.route('/setting', {
  99. name: 'setting',
  100. triggersEnter: [
  101. AccountsTemplates.ensureSignedIn,
  102. () => {
  103. Session.set('currentBoard', null);
  104. Session.set('currentList', null);
  105. Session.set('currentCard', null);
  106. Filter.reset();
  107. EscapeActions.executeAll();
  108. },
  109. ],
  110. action() {
  111. Utils.manageCustomUI();
  112. BlazeLayout.render('defaultLayout', {
  113. headerBar: 'settingHeaderBar',
  114. content: 'setting',
  115. });
  116. },
  117. });
  118. FlowRouter.route('/information', {
  119. name: 'information',
  120. triggersEnter: [
  121. AccountsTemplates.ensureSignedIn,
  122. () => {
  123. Session.set('currentBoard', null);
  124. Session.set('currentList', null);
  125. Session.set('currentCard', null);
  126. Filter.reset();
  127. EscapeActions.executeAll();
  128. },
  129. ],
  130. action() {
  131. BlazeLayout.render('defaultLayout', {
  132. headerBar: 'settingHeaderBar',
  133. content: 'information',
  134. });
  135. },
  136. });
  137. FlowRouter.route('/people', {
  138. name: 'people',
  139. triggersEnter: [
  140. AccountsTemplates.ensureSignedIn,
  141. () => {
  142. Session.set('currentBoard', null);
  143. Session.set('currentList', null);
  144. Session.set('currentCard', null);
  145. Filter.reset();
  146. EscapeActions.executeAll();
  147. },
  148. ],
  149. action() {
  150. BlazeLayout.render('defaultLayout', {
  151. headerBar: 'settingHeaderBar',
  152. content: 'people',
  153. });
  154. },
  155. });
  156. FlowRouter.notFound = {
  157. action() {
  158. BlazeLayout.render('defaultLayout', { content: 'notFound' });
  159. },
  160. };
  161. // We maintain a list of redirections to ensure that we don't break old URLs
  162. // when we change our routing scheme.
  163. const redirections = {
  164. '/boards': '/',
  165. '/boards/:id/:slug': '/b/:id/:slug',
  166. '/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId',
  167. '/import': '/import/trello',
  168. };
  169. _.each(redirections, (newPath, oldPath) => {
  170. FlowRouter.route(oldPath, {
  171. triggersEnter: [
  172. (context, redirect) => {
  173. redirect(FlowRouter.path(newPath, context.params));
  174. },
  175. ],
  176. });
  177. });
  178. // As it is not possible to use template helpers in the page <head> we create a
  179. // reactive function whose role is to set any page-specific tag in the <head>
  180. // using the `kadira:dochead` package. Currently we only use it to display the
  181. // board title if we are in a board page (see #364) but we may want to support
  182. // some <meta> tags in the future.
  183. //const appTitle = Utils.manageCustomUI();
  184. // XXX The `Meteor.startup` should not be necessary -- we don't need to wait for
  185. // the complete DOM to be ready to call `DocHead.setTitle`. But the problem is
  186. // that the global variable `Boards` is undefined when this file loads so we
  187. // wait a bit until hopefully all files are loaded. This will be fixed in a
  188. // clean way once Meteor will support ES6 modules -- hopefully in Meteor 1.3.
  189. //Meteor.isClient && Meteor.startup(() => {
  190. // Tracker.autorun(() => {
  191. // const currentBoard = Boards.findOne(Session.get('currentBoard'));
  192. // const titleStack = [appTitle];
  193. // if (currentBoard) {
  194. // titleStack.push(currentBoard.title);
  195. // }
  196. // DocHead.setTitle(titleStack.reverse().join(' - '));
  197. // });
  198. //});