diff options
author | Maxime Quandalle <maxime@quandalle.com> | 2015-08-22 22:59:03 +0200 |
---|---|---|
committer | Maxime Quandalle <maxime@quandalle.com> | 2015-08-23 11:11:03 +0200 |
commit | d5eec54c72b755522addc4a839810971ba24f813 (patch) | |
tree | b3f9c1bfde7f4ebd9d2ddca54afa67783c19d983 /client/config | |
parent | f315ee443061c916dc55b291bfe79503fa5e952f (diff) | |
download | wekan-d5eec54c72b755522addc4a839810971ba24f813.tar.gz wekan-d5eec54c72b755522addc4a839810971ba24f813.tar.bz2 wekan-d5eec54c72b755522addc4a839810971ba24f813.zip |
Start the migration from iron-router to flow-router
Motivations:
* Iron-Router foces us to use Tracker.nonreactive black magic in order
to avoid un-necessary re-renders;
* There is a community consensus (supported by some MDG members) that
the flow-router API is easier to reason about;
* The useraccounts now supports flow router (that was a blocking
element when I considered the switch ~3months ago)
On the server we use the Picker router, as encouraged by the Kadira
team (which develop both Flow and Picker routers).
In the current state of things there are some bugs related to the
missing Loading architecure. Previously onRendered callback where
always called when the data the component needed was available, now
we have to handle this ourselves, which we will in a following commit.
Diffstat (limited to 'client/config')
-rw-r--r-- | client/config/accounts.js | 13 | ||||
-rw-r--r-- | client/config/router.js | 97 |
2 files changed, 64 insertions, 46 deletions
diff --git a/client/config/accounts.js b/client/config/accounts.js index e12dd8bc..3852e580 100644 --- a/client/config/accounts.js +++ b/client/config/accounts.js @@ -9,20 +9,25 @@ AccountsTemplates.addFields([{ }, emailField, passwordField]); AccountsTemplates.configure({ + defaultLayout: 'userFormsLayout', + defaultContentRegion: 'content', confirmPassword: false, enablePasswordChange: true, sendVerificationEmail: true, showForgotPasswordLink: true, onLogoutHook: function() { - Router.go('Home'); + var homePage = 'home'; + if (FlowRouter.getRouteName() === homePage) { + FlowRouter.reload(); + } else { + FlowRouter.go(homePage); + } } }); _.each(['signIn', 'signUp', 'resetPwd', 'forgotPwd', 'enrollAccount'], function(routeName) { - AccountsTemplates.configureRoute(routeName, { - layoutTemplate: 'userFormsLayout' - }); + AccountsTemplates.configureRoute(routeName); }); // We display the form to change the password in a popup window that already diff --git a/client/config/router.js b/client/config/router.js index 97871e23..e251aea0 100644 --- a/client/config/router.js +++ b/client/config/router.js @@ -1,44 +1,57 @@ -// XXX Switch to Flow-Router? -var previousRoute; - -Router.configure({ - loadingTemplate: 'spinner', - notFoundTemplate: 'notfound', - layoutTemplate: 'defaultLayout', - - onBeforeAction: function() { - var options = this.route.options; - - var loggedIn = Tracker.nonreactive(function() { - return !! Meteor.userId(); - }); - - // Redirect logged in users to Boards view when they try to open Login or - // signup views. - if (loggedIn && options.redirectLoggedInUsers) { - return this.redirect('Boards'); - } - - // Authenticated - if (! loggedIn && options.authenticated) { - return this.redirect('atSignIn'); - } - - // We want to execute our EscapeActions.executeUpTo method any time the - // route is changed, but not if the stays the same but only the parameters - // change (eg when a user is navigation from a card A to a card B). Iron- - // Router onBeforeAction is a reactive context (which is a bad desig choice - // as explained in - // https://github.com/meteorhacks/flow-router#routercurrent-is-evil) so we - // need to use Tracker.nonreactive - Tracker.nonreactive(function() { - if (! options.noEscapeActions && - ! (previousRoute && previousRoute.options.noEscapeActions)) - EscapeActions.executeAll(); - }); - - previousRoute = this.route; - - this.next(); +FlowRouter.route('/', { + name: 'home', + triggersEnter: [AccountsTemplates.ensureSignedIn], + action: function() { + EscapeActions.executeAll(); + Filter.reset(); + + Session.set('currentBoard', ''); + + BlazeLayout.render('defaultLayout', { content: 'boardList' }); + } +}); + +FlowRouter.route('/b/:id/:slug', { + name: 'board', + action: function(params) { + EscapeActions.executeAll(); + + Session.set('currentBoard', params.id); + Session.set('currentCard', null); + + BlazeLayout.render('defaultLayout', { content: 'board' }); + } +}); + +FlowRouter.route('/b/:boardId/:slug/:cardId', { + name: 'card', + action: function(params) { + Session.set('currentBoard', params.boardId); + Session.set('currentCard', params.cardId); + EscapeActions.executeUpTo('popup'); + + BlazeLayout.render('defaultLayout', { content: 'board' }); + } +}); + +FlowRouter.notFound = { + action: function() { + BlazeLayout.render('defaultLayout', { content: 'notFound' }); } +} + +// We maintain a list of redirections to ensure that we don't break old URLs +// when we change our routing scheme. +var redirections = { + '/boards': '/', + '/boards/:id/:slug': '/b/:id/:slug', + '/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId' +}; + +_.each(redirections, function(newPath, oldPath) { + FlowRouter.route(oldPath, { + triggersEnter: [function(context, redirect) { + redirect(FlowRouter.path(newPath, context.params)); + }] + }); }); |