router.js 5.5 KB

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