router.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.notFound = {
  70. action() {
  71. BlazeLayout.render('defaultLayout', { content: 'notFound' });
  72. },
  73. };
  74. // We maintain a list of redirections to ensure that we don't break old URLs
  75. // when we change our routing scheme.
  76. const redirections = {
  77. '/boards': '/',
  78. '/boards/:id/:slug': '/b/:id/:slug',
  79. '/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId',
  80. };
  81. _.each(redirections, (newPath, oldPath) => {
  82. FlowRouter.route(oldPath, {
  83. triggersEnter: [(context, redirect) => {
  84. redirect(FlowRouter.path(newPath, context.params));
  85. }],
  86. });
  87. });
  88. // As it is not possible to use template helpers in the page <head> we create a
  89. // reactive function whose role is to set any page-specific tag in the <head>
  90. // using the `kadira:dochead` package. Currently we only use it to display the
  91. // board title if we are in a board page (see #364) but we may want to support
  92. // some <meta> tags in the future.
  93. const appTitle = 'Wekan';
  94. // XXX The `Meteor.startup` should not be necessary -- we don't need to wait for
  95. // the complete DOM to be ready to call `DocHead.setTitle`. But the problem is
  96. // that the global variable `Boards` is undefined when this file loads so we
  97. // wait a bit until hopefully all files are loaded. This will be fixed in a
  98. // clean way once Meteor will support ES6 modules -- hopefully in Meteor 1.3.
  99. Meteor.startup(() => {
  100. Tracker.autorun(() => {
  101. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  102. const titleStack = [appTitle];
  103. if (currentBoard) {
  104. titleStack.push(currentBoard.title);
  105. }
  106. DocHead.setTitle(titleStack.reverse().join(' - '));
  107. });
  108. });