router.js 4.3 KB

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