router.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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', {
  71. name: 'import',
  72. triggersEnter: [
  73. AccountsTemplates.ensureSignedIn,
  74. () => {
  75. Session.set('currentBoard', null);
  76. Session.set('currentCard', null);
  77. Filter.reset();
  78. EscapeActions.executeAll();
  79. },
  80. ],
  81. action() {
  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.notFound = {
  107. action() {
  108. BlazeLayout.render('defaultLayout', { content: 'notFound' });
  109. },
  110. };
  111. // We maintain a list of redirections to ensure that we don't break old URLs
  112. // when we change our routing scheme.
  113. const redirections = {
  114. '/boards': '/',
  115. '/boards/:id/:slug': '/b/:id/:slug',
  116. '/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId',
  117. };
  118. _.each(redirections, (newPath, oldPath) => {
  119. FlowRouter.route(oldPath, {
  120. triggersEnter: [(context, redirect) => {
  121. redirect(FlowRouter.path(newPath, context.params));
  122. }],
  123. });
  124. });
  125. // As it is not possible to use template helpers in the page <head> we create a
  126. // reactive function whose role is to set any page-specific tag in the <head>
  127. // using the `kadira:dochead` package. Currently we only use it to display the
  128. // board title if we are in a board page (see #364) but we may want to support
  129. // some <meta> tags in the future.
  130. const appTitle = 'Wekan';
  131. // XXX The `Meteor.startup` should not be necessary -- we don't need to wait for
  132. // the complete DOM to be ready to call `DocHead.setTitle`. But the problem is
  133. // that the global variable `Boards` is undefined when this file loads so we
  134. // wait a bit until hopefully all files are loaded. This will be fixed in a
  135. // clean way once Meteor will support ES6 modules -- hopefully in Meteor 1.3.
  136. Meteor.isClient && Meteor.startup(() => {
  137. Tracker.autorun(() => {
  138. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  139. const titleStack = [appTitle];
  140. if (currentBoard) {
  141. titleStack.push(currentBoard.title);
  142. }
  143. DocHead.setTitle(titleStack.reverse().join(' - '));
  144. });
  145. });