router.js 4.9 KB

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