router.js 5.7 KB

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