router.js 9.1 KB

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