router.js 5.4 KB

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