router.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. action() {
  90. BlazeLayout.render('defaultLayout', {
  91. headerBar: 'settingHeaderBar',
  92. content: 'setting',
  93. });
  94. },
  95. });
  96. FlowRouter.notFound = {
  97. action() {
  98. BlazeLayout.render('defaultLayout', { content: 'notFound' });
  99. },
  100. };
  101. // We maintain a list of redirections to ensure that we don't break old URLs
  102. // when we change our routing scheme.
  103. const redirections = {
  104. '/boards': '/',
  105. '/boards/:id/:slug': '/b/:id/:slug',
  106. '/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId',
  107. };
  108. _.each(redirections, (newPath, oldPath) => {
  109. FlowRouter.route(oldPath, {
  110. triggersEnter: [(context, redirect) => {
  111. redirect(FlowRouter.path(newPath, context.params));
  112. }],
  113. });
  114. });
  115. // As it is not possible to use template helpers in the page <head> we create a
  116. // reactive function whose role is to set any page-specific tag in the <head>
  117. // using the `kadira:dochead` package. Currently we only use it to display the
  118. // board title if we are in a board page (see #364) but we may want to support
  119. // some <meta> tags in the future.
  120. const appTitle = 'Wekan';
  121. // XXX The `Meteor.startup` should not be necessary -- we don't need to wait for
  122. // the complete DOM to be ready to call `DocHead.setTitle`. But the problem is
  123. // that the global variable `Boards` is undefined when this file loads so we
  124. // wait a bit until hopefully all files are loaded. This will be fixed in a
  125. // clean way once Meteor will support ES6 modules -- hopefully in Meteor 1.3.
  126. Meteor.isClient && Meteor.startup(() => {
  127. Tracker.autorun(() => {
  128. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  129. const titleStack = [appTitle];
  130. if (currentBoard) {
  131. titleStack.push(currentBoard.title);
  132. }
  133. DocHead.setTitle(titleStack.reverse().join(' - '));
  134. });
  135. });