router.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.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. '/import': '/import/trello',
  118. };
  119. _.each(redirections, (newPath, oldPath) => {
  120. FlowRouter.route(oldPath, {
  121. triggersEnter: [(context, redirect) => {
  122. redirect(FlowRouter.path(newPath, context.params));
  123. }],
  124. });
  125. });
  126. // As it is not possible to use template helpers in the page <head> we create a
  127. // reactive function whose role is to set any page-specific tag in the <head>
  128. // using the `kadira:dochead` package. Currently we only use it to display the
  129. // board title if we are in a board page (see #364) but we may want to support
  130. // some <meta> tags in the future.
  131. const appTitle = 'Wekan';
  132. // XXX The `Meteor.startup` should not be necessary -- we don't need to wait for
  133. // the complete DOM to be ready to call `DocHead.setTitle`. But the problem is
  134. // that the global variable `Boards` is undefined when this file loads so we
  135. // wait a bit until hopefully all files are loaded. This will be fixed in a
  136. // clean way once Meteor will support ES6 modules -- hopefully in Meteor 1.3.
  137. Meteor.isClient && Meteor.startup(() => {
  138. Tracker.autorun(() => {
  139. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  140. const titleStack = [appTitle];
  141. if (currentBoard) {
  142. titleStack.push(currentBoard.title);
  143. }
  144. DocHead.setTitle(titleStack.reverse().join(' - '));
  145. });
  146. });