router.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. Session.set('sortBy', '');
  16. EscapeActions.executeAll();
  17. Utils.manageCustomUI();
  18. Utils.manageMatomo();
  19. BlazeLayout.render('defaultLayout', {
  20. headerBar: 'boardListHeaderBar',
  21. content: 'boardList',
  22. });
  23. },
  24. });
  25. FlowRouter.route('/public', {
  26. name: 'public',
  27. triggersEnter: [AccountsTemplates.ensureSignedIn],
  28. action() {
  29. Session.set('currentBoard', null);
  30. Session.set('currentList', null);
  31. Session.set('currentCard', null);
  32. Filter.reset();
  33. Session.set('sortBy', '');
  34. EscapeActions.executeAll();
  35. Utils.manageCustomUI();
  36. Utils.manageMatomo();
  37. BlazeLayout.render('defaultLayout', {
  38. headerBar: 'boardListHeaderBar',
  39. content: 'boardList',
  40. });
  41. },
  42. });
  43. FlowRouter.route('/b/:id/:slug', {
  44. name: 'board',
  45. action(params) {
  46. const currentBoard = params.id;
  47. const previousBoard = Session.get('currentBoard');
  48. Session.set('currentBoard', currentBoard);
  49. Session.set('currentCard', null);
  50. // If we close a card, we'll execute again this route action but we don't
  51. // want to excape every current actions (filters, etc.)
  52. if (previousBoard !== currentBoard) {
  53. Filter.reset();
  54. Session.set('sortBy', '');
  55. EscapeActions.executeAll();
  56. } else {
  57. EscapeActions.executeUpTo('popup-close');
  58. }
  59. Utils.manageCustomUI();
  60. Utils.manageMatomo();
  61. BlazeLayout.render('defaultLayout', {
  62. headerBar: 'boardHeaderBar',
  63. content: 'board',
  64. });
  65. },
  66. });
  67. FlowRouter.route('/b/:boardId/:slug/:cardId', {
  68. name: 'card',
  69. action(params) {
  70. EscapeActions.executeUpTo('inlinedForm');
  71. Session.set('currentBoard', params.boardId);
  72. Session.set('currentCard', params.cardId);
  73. Utils.manageCustomUI();
  74. Utils.manageMatomo();
  75. BlazeLayout.render('defaultLayout', {
  76. headerBar: 'boardHeaderBar',
  77. content: 'board',
  78. });
  79. },
  80. });
  81. FlowRouter.route('/shortcuts', {
  82. name: 'shortcuts',
  83. action() {
  84. const shortcutsTemplate = 'keyboardShortcuts';
  85. EscapeActions.executeUpTo('popup-close');
  86. if (previousPath) {
  87. Modal.open(shortcutsTemplate, {
  88. header: 'shortcutsModalTitle',
  89. onCloseGoTo: previousPath,
  90. });
  91. } else {
  92. BlazeLayout.render('defaultLayout', {
  93. headerBar: 'shortcutsHeaderBar',
  94. content: shortcutsTemplate,
  95. });
  96. }
  97. },
  98. });
  99. FlowRouter.route('/my-cards', {
  100. name: 'my-cards',
  101. triggersEnter: [AccountsTemplates.ensureSignedIn],
  102. action() {
  103. Filter.reset();
  104. Session.set('sortBy', '');
  105. // EscapeActions.executeAll();
  106. EscapeActions.executeUpTo('popup-close');
  107. Utils.manageCustomUI();
  108. Utils.manageMatomo();
  109. BlazeLayout.render('defaultLayout', {
  110. headerBar: 'myCardsHeaderBar',
  111. content: 'myCards',
  112. });
  113. // }
  114. },
  115. });
  116. FlowRouter.route('/due-cards', {
  117. name: 'due-cards',
  118. triggersEnter: [AccountsTemplates.ensureSignedIn],
  119. action() {
  120. Filter.reset();
  121. Session.set('sortBy', '');
  122. // EscapeActions.executeAll();
  123. EscapeActions.executeUpTo('popup-close');
  124. Utils.manageCustomUI();
  125. Utils.manageMatomo();
  126. BlazeLayout.render('defaultLayout', {
  127. headerBar: 'dueCardsHeaderBar',
  128. content: 'dueCards',
  129. });
  130. // }
  131. },
  132. });
  133. FlowRouter.route('/global-search', {
  134. name: 'global-search',
  135. triggersEnter: [AccountsTemplates.ensureSignedIn],
  136. action() {
  137. Filter.reset();
  138. Session.set('sortBy', '');
  139. // EscapeActions.executeAll();
  140. EscapeActions.executeUpTo('popup-close');
  141. Utils.manageCustomUI();
  142. Utils.manageMatomo();
  143. DocHead.setTitle(TAPi18n.__('globalSearch-title'));
  144. if (FlowRouter.getQueryParam('q')) {
  145. Session.set(
  146. 'globalQuery',
  147. decodeURIComponent(FlowRouter.getQueryParam('q')),
  148. );
  149. }
  150. BlazeLayout.render('defaultLayout', {
  151. headerBar: 'globalSearchHeaderBar',
  152. content: 'globalSearch',
  153. });
  154. },
  155. });
  156. FlowRouter.route('/broken-cards', {
  157. name: 'broken-cards',
  158. action() {
  159. const brokenCardsTemplate = 'brokenCards';
  160. Filter.reset();
  161. Session.set('sortBy', '');
  162. // EscapeActions.executeAll();
  163. EscapeActions.executeUpTo('popup-close');
  164. Utils.manageCustomUI();
  165. Utils.manageMatomo();
  166. BlazeLayout.render('defaultLayout', {
  167. headerBar: 'brokenCardsHeaderBar',
  168. content: brokenCardsTemplate,
  169. });
  170. },
  171. });
  172. FlowRouter.route('/import/:source', {
  173. name: 'import',
  174. triggersEnter: [AccountsTemplates.ensureSignedIn],
  175. action(params) {
  176. if (Session.get('currentBoard')) {
  177. Session.set('fromBoard', Session.get('currentBoard'));
  178. }
  179. Session.set('currentBoard', null);
  180. Session.set('currentList', null);
  181. Session.set('currentCard', null);
  182. Session.set('importSource', params.source);
  183. Filter.reset();
  184. Session.set('sortBy', '');
  185. EscapeActions.executeAll();
  186. BlazeLayout.render('defaultLayout', {
  187. headerBar: 'importHeaderBar',
  188. content: 'import',
  189. });
  190. },
  191. });
  192. FlowRouter.route('/setting', {
  193. name: 'setting',
  194. triggersEnter: [
  195. AccountsTemplates.ensureSignedIn,
  196. () => {
  197. Session.set('currentBoard', null);
  198. Session.set('currentList', null);
  199. Session.set('currentCard', null);
  200. Filter.reset();
  201. Session.set('sortBy', '');
  202. EscapeActions.executeAll();
  203. },
  204. ],
  205. action() {
  206. Utils.manageCustomUI();
  207. BlazeLayout.render('defaultLayout', {
  208. headerBar: 'settingHeaderBar',
  209. content: 'setting',
  210. });
  211. },
  212. });
  213. FlowRouter.route('/information', {
  214. name: 'information',
  215. triggersEnter: [
  216. AccountsTemplates.ensureSignedIn,
  217. () => {
  218. Session.set('currentBoard', null);
  219. Session.set('currentList', null);
  220. Session.set('currentCard', null);
  221. Filter.reset();
  222. Session.set('sortBy', '');
  223. EscapeActions.executeAll();
  224. },
  225. ],
  226. action() {
  227. BlazeLayout.render('defaultLayout', {
  228. headerBar: 'settingHeaderBar',
  229. content: 'information',
  230. });
  231. },
  232. });
  233. FlowRouter.route('/people', {
  234. name: 'people',
  235. triggersEnter: [
  236. AccountsTemplates.ensureSignedIn,
  237. () => {
  238. Session.set('currentBoard', null);
  239. Session.set('currentList', null);
  240. Session.set('currentCard', null);
  241. Filter.reset();
  242. Session.set('sortBy', '');
  243. EscapeActions.executeAll();
  244. },
  245. ],
  246. action() {
  247. BlazeLayout.render('defaultLayout', {
  248. headerBar: 'settingHeaderBar',
  249. content: 'people',
  250. });
  251. },
  252. });
  253. FlowRouter.route('/admin-reports', {
  254. name: 'admin-reports',
  255. triggersEnter: [
  256. AccountsTemplates.ensureSignedIn,
  257. () => {
  258. Session.set('currentBoard', null);
  259. Session.set('currentList', null);
  260. Session.set('currentCard', null);
  261. Filter.reset();
  262. Session.set('sortBy', '');
  263. EscapeActions.executeAll();
  264. },
  265. ],
  266. action() {
  267. BlazeLayout.render('defaultLayout', {
  268. headerBar: 'settingHeaderBar',
  269. content: 'adminReports',
  270. });
  271. },
  272. });
  273. FlowRouter.notFound = {
  274. action() {
  275. BlazeLayout.render('defaultLayout', { content: 'notFound' });
  276. },
  277. };
  278. // We maintain a list of redirections to ensure that we don't break old URLs
  279. // when we change our routing scheme.
  280. const redirections = {
  281. '/boards': '/',
  282. '/boards/:id/:slug': '/b/:id/:slug',
  283. '/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId',
  284. '/import': '/import/trello',
  285. };
  286. _.each(redirections, (newPath, oldPath) => {
  287. FlowRouter.route(oldPath, {
  288. triggersEnter: [
  289. (context, redirect) => {
  290. redirect(FlowRouter.path(newPath, context.params));
  291. },
  292. ],
  293. });
  294. });
  295. // As it is not possible to use template helpers in the page <head> we create a
  296. // reactive function whose role is to set any page-specific tag in the <head>
  297. // using the `kadira:dochead` package. Currently we only use it to display the
  298. // board title if we are in a board page (see #364) but we may want to support
  299. // some <meta> tags in the future.
  300. //const appTitle = Utils.manageCustomUI();
  301. // XXX The `Meteor.startup` should not be necessary -- we don't need to wait for
  302. // the complete DOM to be ready to call `DocHead.setTitle`. But the problem is
  303. // that the global variable `Boards` is undefined when this file loads so we
  304. // wait a bit until hopefully all files are loaded. This will be fixed in a
  305. // clean way once Meteor will support ES6 modules -- hopefully in Meteor 1.3.
  306. //Meteor.isClient && Meteor.startup(() => {
  307. // Tracker.autorun(() => {
  308. // const currentBoard = Boards.findOne(Session.get('currentBoard'));
  309. // const titleStack = [appTitle];
  310. // if (currentBoard) {
  311. // titleStack.push(currentBoard.title);
  312. // }
  313. // DocHead.setTitle(titleStack.reverse().join(' - '));
  314. // });
  315. //});