router.js 11 KB

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