router.js 11 KB

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