router.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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', { content: 'boardList' });
  14. },
  15. });
  16. FlowRouter.route('/b/:id/:slug', {
  17. name: 'board',
  18. action(params) {
  19. const currentBoard = params.id;
  20. const previousBoard = Session.get('currentBoard');
  21. Session.set('currentBoard', currentBoard);
  22. Session.set('currentCard', null);
  23. // If we close a card, we'll execute again this route action but we don't
  24. // want to excape every current actions (filters, etc.)
  25. if (previousBoard !== currentBoard) {
  26. EscapeActions.executeAll();
  27. } else {
  28. EscapeActions.executeUpTo('popup-close');
  29. }
  30. BlazeLayout.render('defaultLayout', { content: 'board' });
  31. },
  32. });
  33. FlowRouter.route('/b/:boardId/:slug/:cardId', {
  34. name: 'card',
  35. action(params) {
  36. EscapeActions.executeUpTo('inlinedForm');
  37. Session.set('currentBoard', params.boardId);
  38. Session.set('currentCard', params.cardId);
  39. BlazeLayout.render('defaultLayout', { content: 'board' });
  40. },
  41. });
  42. FlowRouter.route('/shortcuts', {
  43. name: 'shortcuts',
  44. action() {
  45. const shortcutsTemplate = 'keyboardShortcuts';
  46. EscapeActions.executeUpTo('popup-close');
  47. if (previousPath) {
  48. Modal.open(shortcutsTemplate, {
  49. onCloseGoTo: previousPath,
  50. });
  51. } else {
  52. // XXX There is currently no way to escape this page on Sandstorm
  53. BlazeLayout.render('defaultLayout', { content: shortcutsTemplate });
  54. }
  55. },
  56. });
  57. FlowRouter.notFound = {
  58. action() {
  59. BlazeLayout.render('defaultLayout', { content: 'notFound' });
  60. },
  61. };
  62. // We maintain a list of redirections to ensure that we don't break old URLs
  63. // when we change our routing scheme.
  64. const redirections = {
  65. '/boards': '/',
  66. '/boards/:id/:slug': '/b/:id/:slug',
  67. '/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId',
  68. };
  69. _.each(redirections, (newPath, oldPath) => {
  70. FlowRouter.route(oldPath, {
  71. triggersEnter: [(context, redirect) => {
  72. redirect(FlowRouter.path(newPath, context.params));
  73. }],
  74. });
  75. });
  76. // As it is not possible to use template helpers in the page <head> we create a
  77. // reactive function whose role is to set any page-specific tag in the <head>
  78. // using the `kadira:dochead` package. Currently we only use it to display the
  79. // board title if we are in a board page (see #364) but we may want to support
  80. // some <meta> tags in the future.
  81. const appTitle = 'Wekan';
  82. // XXX The `Meteor.startup` should not be necessary -- we don't need to wait for
  83. // the complete DOM to be ready to call `DocHead.setTitle`. But the problem is
  84. // that the global variable `Boards` is undefined when this file loads so we
  85. // wait a bit until hopefully all files are loaded. This will be fixed in a
  86. // clean way once Meteor will support ES6 modules -- hopefully in Meteor 1.3.
  87. Meteor.startup(() => {
  88. Tracker.autorun(() => {
  89. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  90. const titleStack = [appTitle];
  91. if (currentBoard) {
  92. titleStack.push(currentBoard.title);
  93. }
  94. DocHead.setTitle(titleStack.reverse().join(' - '));
  95. });
  96. });