router.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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('/accessibility', {
  49. name: 'accessibility',
  50. triggersEnter: [AccountsTemplates.ensureSignedIn],
  51. action() {
  52. Session.set('currentBoard', null);
  53. Session.set('currentList', null);
  54. Session.set('currentCard', null);
  55. Session.set('popupCardId', null);
  56. Session.set('popupCardBoardId', null);
  57. Filter.reset();
  58. Session.set('sortBy', '');
  59. EscapeActions.executeAll();
  60. Utils.manageCustomUI();
  61. Utils.manageMatomo();
  62. BlazeLayout.render('defaultLayout', {
  63. headerBar: 'accessibilityHeaderBar',
  64. content: 'accessibility',
  65. });
  66. },
  67. });
  68. FlowRouter.route('/b/:id/:slug', {
  69. name: 'board',
  70. action(params) {
  71. const currentBoard = params.id;
  72. const previousBoard = Session.get('currentBoard');
  73. Session.set('currentBoard', currentBoard);
  74. Session.set('currentCard', null);
  75. Session.set('popupCardId', null);
  76. Session.set('popupCardBoardId', null);
  77. // If we close a card, we'll execute again this route action but we don't
  78. // want to excape every current actions (filters, etc.)
  79. if (previousBoard !== currentBoard) {
  80. Filter.reset();
  81. Session.set('sortBy', '');
  82. EscapeActions.executeAll();
  83. } else {
  84. EscapeActions.executeUpTo('popup-close');
  85. }
  86. Utils.manageCustomUI();
  87. Utils.manageMatomo();
  88. BlazeLayout.render('defaultLayout', {
  89. headerBar: 'boardHeaderBar',
  90. content: 'board',
  91. });
  92. },
  93. });
  94. FlowRouter.route('/b/:boardId/:slug/:cardId', {
  95. name: 'card',
  96. action(params) {
  97. EscapeActions.executeUpTo('inlinedForm');
  98. Session.set('currentBoard', params.boardId);
  99. Session.set('currentCard', params.cardId);
  100. Session.set('popupCardId', null);
  101. Session.set('popupCardBoardId', null);
  102. Utils.manageCustomUI();
  103. Utils.manageMatomo();
  104. BlazeLayout.render('defaultLayout', {
  105. headerBar: 'boardHeaderBar',
  106. content: 'board',
  107. });
  108. },
  109. });
  110. FlowRouter.route('/shortcuts', {
  111. name: 'shortcuts',
  112. action() {
  113. const shortcutsTemplate = 'keyboardShortcuts';
  114. EscapeActions.executeUpTo('popup-close');
  115. if (previousPath) {
  116. Modal.open(shortcutsTemplate, {
  117. header: 'shortcutsModalTitle',
  118. onCloseGoTo: previousPath,
  119. });
  120. } else {
  121. BlazeLayout.render('defaultLayout', {
  122. headerBar: 'shortcutsHeaderBar',
  123. content: shortcutsTemplate,
  124. });
  125. }
  126. },
  127. });
  128. FlowRouter.route('/b/templates', {
  129. name: 'template-container',
  130. triggersEnter: [AccountsTemplates.ensureSignedIn],
  131. action() {
  132. Session.set('currentBoard', null);
  133. Session.set('currentList', null);
  134. Session.set('currentCard', null);
  135. Session.set('popupCardId', null);
  136. Session.set('popupCardBoardId', null);
  137. Filter.reset();
  138. Session.set('sortBy', '');
  139. EscapeActions.executeAll();
  140. Utils.manageCustomUI();
  141. Utils.manageMatomo();
  142. BlazeLayout.render('defaultLayout', {
  143. headerBar: 'boardListHeaderBar',
  144. content: 'boardList',
  145. });
  146. },
  147. });
  148. FlowRouter.route('/my-cards', {
  149. name: 'my-cards',
  150. triggersEnter: [AccountsTemplates.ensureSignedIn],
  151. action() {
  152. Filter.reset();
  153. Session.set('sortBy', '');
  154. // EscapeActions.executeAll();
  155. EscapeActions.executeUpTo('popup-close');
  156. Utils.manageCustomUI();
  157. Utils.manageMatomo();
  158. BlazeLayout.render('defaultLayout', {
  159. headerBar: 'myCardsHeaderBar',
  160. content: 'myCards',
  161. });
  162. // }
  163. },
  164. });
  165. FlowRouter.route('/due-cards', {
  166. name: 'due-cards',
  167. triggersEnter: [AccountsTemplates.ensureSignedIn],
  168. action() {
  169. Filter.reset();
  170. Session.set('sortBy', '');
  171. // EscapeActions.executeAll();
  172. EscapeActions.executeUpTo('popup-close');
  173. Utils.manageCustomUI();
  174. Utils.manageMatomo();
  175. BlazeLayout.render('defaultLayout', {
  176. headerBar: 'dueCardsHeaderBar',
  177. content: 'dueCards',
  178. });
  179. // }
  180. },
  181. });
  182. FlowRouter.route('/global-search', {
  183. name: 'global-search',
  184. triggersEnter: [AccountsTemplates.ensureSignedIn],
  185. action() {
  186. Filter.reset();
  187. Session.set('sortBy', '');
  188. // EscapeActions.executeAll();
  189. EscapeActions.executeUpTo('popup-close');
  190. Utils.manageCustomUI();
  191. Utils.manageMatomo();
  192. const currentSetting = ReactiveCache.getCurrentSetting && ReactiveCache.getCurrentSetting();
  193. const productName = currentSetting && currentSetting.productName ? currentSetting.productName : 'Wekan';
  194. DocHead.setTitle(`${TAPi18n.__('globalSearch-title')} - ${productName}`);
  195. if (FlowRouter.getQueryParam('q')) {
  196. Session.set(
  197. 'globalQuery',
  198. decodeURIComponent(FlowRouter.getQueryParam('q')),
  199. );
  200. }
  201. BlazeLayout.render('defaultLayout', {
  202. headerBar: 'globalSearchHeaderBar',
  203. content: 'globalSearch',
  204. });
  205. },
  206. });
  207. FlowRouter.route('/broken-cards', {
  208. name: 'broken-cards',
  209. action() {
  210. const brokenCardsTemplate = 'brokenCards';
  211. Filter.reset();
  212. Session.set('sortBy', '');
  213. // EscapeActions.executeAll();
  214. EscapeActions.executeUpTo('popup-close');
  215. Utils.manageCustomUI();
  216. Utils.manageMatomo();
  217. BlazeLayout.render('defaultLayout', {
  218. headerBar: 'brokenCardsHeaderBar',
  219. content: brokenCardsTemplate,
  220. });
  221. },
  222. });
  223. FlowRouter.route('/import/:source', {
  224. name: 'import',
  225. triggersEnter: [AccountsTemplates.ensureSignedIn],
  226. action(params) {
  227. if (Session.get('currentBoard')) {
  228. Session.set('fromBoard', Session.get('currentBoard'));
  229. }
  230. Session.set('currentBoard', null);
  231. Session.set('currentList', null);
  232. Session.set('currentCard', null);
  233. Session.set('popupCardId', null);
  234. Session.set('popupCardBoardId', null);
  235. Session.set('importSource', params.source);
  236. Filter.reset();
  237. Session.set('sortBy', '');
  238. EscapeActions.executeAll();
  239. BlazeLayout.render('defaultLayout', {
  240. headerBar: 'importHeaderBar',
  241. content: 'import',
  242. });
  243. },
  244. });
  245. FlowRouter.route('/setting', {
  246. name: 'setting',
  247. triggersEnter: [
  248. AccountsTemplates.ensureSignedIn,
  249. () => {
  250. Session.set('currentBoard', null);
  251. Session.set('currentList', null);
  252. Session.set('currentCard', null);
  253. Session.set('popupCardId', null);
  254. Session.set('popupCardBoardId', null);
  255. Filter.reset();
  256. Session.set('sortBy', '');
  257. EscapeActions.executeAll();
  258. },
  259. ],
  260. action() {
  261. Utils.manageCustomUI();
  262. BlazeLayout.render('defaultLayout', {
  263. headerBar: 'settingHeaderBar',
  264. content: 'setting',
  265. });
  266. },
  267. });
  268. FlowRouter.route('/information', {
  269. name: 'information',
  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: 'information',
  287. });
  288. },
  289. });
  290. FlowRouter.route('/people', {
  291. name: 'people',
  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: 'people',
  309. });
  310. },
  311. });
  312. FlowRouter.route('/admin-reports', {
  313. name: 'admin-reports',
  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: 'adminReports',
  331. });
  332. },
  333. });
  334. FlowRouter.route('/attachments', {
  335. name: 'attachments',
  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: 'attachments',
  353. });
  354. },
  355. });
  356. FlowRouter.route('/translation', {
  357. name: 'translation',
  358. triggersEnter: [
  359. AccountsTemplates.ensureSignedIn,
  360. () => {
  361. Session.set('currentBoard', null);
  362. Session.set('currentList', null);
  363. Session.set('currentCard', null);
  364. Session.set('popupCardId', null);
  365. Session.set('popupCardBoardId', null);
  366. Filter.reset();
  367. Session.set('sortBy', '');
  368. EscapeActions.executeAll();
  369. },
  370. ],
  371. action() {
  372. BlazeLayout.render('defaultLayout', {
  373. headerBar: 'settingHeaderBar',
  374. content: 'translation',
  375. });
  376. },
  377. });
  378. FlowRouter.notFound = {
  379. action() {
  380. BlazeLayout.render('defaultLayout', { content: 'notFound' });
  381. },
  382. };
  383. // We maintain a list of redirections to ensure that we don't break old URLs
  384. // when we change our routing scheme.
  385. const redirections = {
  386. '/boards': '/',
  387. '/boards/:id/:slug': '/b/:id/:slug',
  388. '/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId',
  389. '/import': '/import/trello',
  390. };
  391. _.each(redirections, (newPath, oldPath) => {
  392. FlowRouter.route(oldPath, {
  393. triggersEnter: [
  394. (context, redirect) => {
  395. redirect(FlowRouter.path(newPath, context.params));
  396. },
  397. ],
  398. });
  399. });
  400. // As it is not possible to use template helpers in the page <head> we create a
  401. // reactive function whose role is to set any page-specific tag in the <head>
  402. // using the `kadira:dochead` package. Currently we only use it to display the
  403. // board title if we are in a board page (see #364) but we may want to support
  404. // some <meta> tags in the future.
  405. //const appTitle = Utils.manageCustomUI();
  406. // XXX The `Meteor.startup` should not be necessary -- we don't need to wait for
  407. // the complete DOM to be ready to call `DocHead.setTitle`. But the problem is
  408. // that the global variable `Boards` is undefined when this file loads so we
  409. // wait a bit until hopefully all files are loaded. This will be fixed in a
  410. // clean way once Meteor will support ES6 modules -- hopefully in Meteor 1.3.
  411. //Meteor.isClient && Meteor.startup(() => {
  412. // Tracker.autorun(() => {
  413. // const currentBoard = Utils.getCurrentBoard();
  414. // const titleStack = [appTitle];
  415. // if (currentBoard) {
  416. // titleStack.push(currentBoard.title);
  417. // }
  418. // DocHead.setTitle(titleStack.reverse().join(' - '));
  419. // });
  420. //});