router.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. let previousPath;
  2. FlowRouter.triggers.exit([
  3. ({ path }) => {
  4. previousPath = path;
  5. },
  6. ]);
  7. FlowRouter.route('/', {
  8. name: 'home',
  9. triggersEnter: [AccountsTemplates.ensureSignedIn],
  10. action() {
  11. Session.set('currentBoard', null);
  12. Session.set('currentList', null);
  13. Session.set('currentCard', null);
  14. Filter.reset();
  15. EscapeActions.executeAll();
  16. Utils.manageCustomUI();
  17. Utils.manageMatomo();
  18. BlazeLayout.render('defaultLayout', {
  19. headerBar: 'boardListHeaderBar',
  20. content: 'boardList',
  21. });
  22. },
  23. });
  24. FlowRouter.route('/public', {
  25. name: 'public',
  26. triggersEnter: [AccountsTemplates.ensureSignedIn],
  27. action() {
  28. Session.set('currentBoard', null);
  29. Session.set('currentList', null);
  30. Session.set('currentCard', null);
  31. Filter.reset();
  32. EscapeActions.executeAll();
  33. Utils.manageCustomUI();
  34. Utils.manageMatomo();
  35. BlazeLayout.render('defaultLayout', {
  36. headerBar: 'boardListHeaderBar',
  37. content: 'boardList',
  38. });
  39. },
  40. });
  41. FlowRouter.route('/b/:id/:slug', {
  42. name: 'board',
  43. action(params) {
  44. const currentBoard = params.id;
  45. const previousBoard = Session.get('currentBoard');
  46. Session.set('currentBoard', currentBoard);
  47. Session.set('currentCard', null);
  48. // If we close a card, we'll execute again this route action but we don't
  49. // want to excape every current actions (filters, etc.)
  50. if (previousBoard !== currentBoard) {
  51. Filter.reset();
  52. EscapeActions.executeAll();
  53. } else {
  54. EscapeActions.executeUpTo('popup-close');
  55. }
  56. Utils.manageCustomUI();
  57. Utils.manageMatomo();
  58. BlazeLayout.render('defaultLayout', {
  59. headerBar: 'boardHeaderBar',
  60. content: 'board',
  61. });
  62. },
  63. });
  64. FlowRouter.route('/b/:boardId/:slug/:cardId', {
  65. name: 'card',
  66. action(params) {
  67. EscapeActions.executeUpTo('inlinedForm');
  68. Session.set('currentBoard', params.boardId);
  69. Session.set('currentCard', params.cardId);
  70. Utils.manageCustomUI();
  71. Utils.manageMatomo();
  72. BlazeLayout.render('defaultLayout', {
  73. headerBar: 'boardHeaderBar',
  74. content: 'board',
  75. });
  76. },
  77. });
  78. FlowRouter.route('/shortcuts', {
  79. name: 'shortcuts',
  80. action() {
  81. const shortcutsTemplate = 'keyboardShortcuts';
  82. EscapeActions.executeUpTo('popup-close');
  83. if (previousPath) {
  84. Modal.open(shortcutsTemplate, {
  85. header: 'shortcutsModalTitle',
  86. onCloseGoTo: previousPath,
  87. });
  88. } else {
  89. BlazeLayout.render('defaultLayout', {
  90. headerBar: 'shortcutsHeaderBar',
  91. content: shortcutsTemplate,
  92. });
  93. }
  94. },
  95. });
  96. FlowRouter.route('/my-cards', {
  97. name: 'my-cards',
  98. action() {
  99. const myCardsTemplate = 'myCards';
  100. Filter.reset();
  101. // EscapeActions.executeAll();
  102. EscapeActions.executeUpTo('popup-close');
  103. Utils.manageCustomUI();
  104. Utils.manageMatomo();
  105. // if (previousPath) {
  106. // Modal.open(myCardsTemplate, {
  107. // header: 'myCardsModalTitle',
  108. // onCloseGoTo: previousPath,
  109. // });
  110. // } else {
  111. BlazeLayout.render('defaultLayout', {
  112. headerBar: 'myCardsHeaderBar',
  113. content: myCardsTemplate,
  114. });
  115. // }
  116. },
  117. });
  118. FlowRouter.route('/import/:source', {
  119. name: 'import',
  120. triggersEnter: [AccountsTemplates.ensureSignedIn],
  121. action(params) {
  122. if (Session.get('currentBoard')) {
  123. Session.set('fromBoard', Session.get('currentBoard'));
  124. }
  125. Session.set('currentBoard', null);
  126. Session.set('currentList', null);
  127. Session.set('currentCard', null);
  128. Session.set('importSource', params.source);
  129. Filter.reset();
  130. EscapeActions.executeAll();
  131. BlazeLayout.render('defaultLayout', {
  132. headerBar: 'importHeaderBar',
  133. content: 'import',
  134. });
  135. },
  136. });
  137. FlowRouter.route('/setting', {
  138. name: 'setting',
  139. triggersEnter: [
  140. AccountsTemplates.ensureSignedIn,
  141. () => {
  142. Session.set('currentBoard', null);
  143. Session.set('currentList', null);
  144. Session.set('currentCard', null);
  145. Filter.reset();
  146. EscapeActions.executeAll();
  147. },
  148. ],
  149. action() {
  150. Utils.manageCustomUI();
  151. BlazeLayout.render('defaultLayout', {
  152. headerBar: 'settingHeaderBar',
  153. content: 'setting',
  154. });
  155. },
  156. });
  157. FlowRouter.route('/information', {
  158. name: 'information',
  159. triggersEnter: [
  160. AccountsTemplates.ensureSignedIn,
  161. () => {
  162. Session.set('currentBoard', null);
  163. Session.set('currentList', null);
  164. Session.set('currentCard', null);
  165. Filter.reset();
  166. EscapeActions.executeAll();
  167. },
  168. ],
  169. action() {
  170. BlazeLayout.render('defaultLayout', {
  171. headerBar: 'settingHeaderBar',
  172. content: 'information',
  173. });
  174. },
  175. });
  176. FlowRouter.route('/people', {
  177. name: 'people',
  178. triggersEnter: [
  179. AccountsTemplates.ensureSignedIn,
  180. () => {
  181. Session.set('currentBoard', null);
  182. Session.set('currentList', null);
  183. Session.set('currentCard', null);
  184. Filter.reset();
  185. EscapeActions.executeAll();
  186. },
  187. ],
  188. action() {
  189. BlazeLayout.render('defaultLayout', {
  190. headerBar: 'settingHeaderBar',
  191. content: 'people',
  192. });
  193. },
  194. });
  195. FlowRouter.notFound = {
  196. action() {
  197. BlazeLayout.render('defaultLayout', { content: 'notFound' });
  198. },
  199. };
  200. // We maintain a list of redirections to ensure that we don't break old URLs
  201. // when we change our routing scheme.
  202. const redirections = {
  203. '/boards': '/',
  204. '/boards/:id/:slug': '/b/:id/:slug',
  205. '/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId',
  206. '/import': '/import/trello',
  207. };
  208. _.each(redirections, (newPath, oldPath) => {
  209. FlowRouter.route(oldPath, {
  210. triggersEnter: [
  211. (context, redirect) => {
  212. redirect(FlowRouter.path(newPath, context.params));
  213. },
  214. ],
  215. });
  216. });
  217. // As it is not possible to use template helpers in the page <head> we create a
  218. // reactive function whose role is to set any page-specific tag in the <head>
  219. // using the `kadira:dochead` package. Currently we only use it to display the
  220. // board title if we are in a board page (see #364) but we may want to support
  221. // some <meta> tags in the future.
  222. //const appTitle = Utils.manageCustomUI();
  223. // XXX The `Meteor.startup` should not be necessary -- we don't need to wait for
  224. // the complete DOM to be ready to call `DocHead.setTitle`. But the problem is
  225. // that the global variable `Boards` is undefined when this file loads so we
  226. // wait a bit until hopefully all files are loaded. This will be fixed in a
  227. // clean way once Meteor will support ES6 modules -- hopefully in Meteor 1.3.
  228. //Meteor.isClient && Meteor.startup(() => {
  229. // Tracker.autorun(() => {
  230. // const currentBoard = Boards.findOne(Session.get('currentBoard'));
  231. // const titleStack = [appTitle];
  232. // if (currentBoard) {
  233. // titleStack.push(currentBoard.title);
  234. // }
  235. // DocHead.setTitle(titleStack.reverse().join(' - '));
  236. // });
  237. //});