mirror of https://github.com/wekan/wekan
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.pull/195/merge
parent
f315ee4430
commit
d5eec54c72
@ -1,58 +0,0 @@ |
||||
Meteor.subscribe('boards'); |
||||
|
||||
var boardSubsManager = new SubsManager(); |
||||
|
||||
Router.route('/boards', { |
||||
name: 'Boards', |
||||
template: 'boards', |
||||
authenticated: true, |
||||
onBeforeAction: function() { |
||||
Session.set('currentBoard', ''); |
||||
Filter.reset(); |
||||
this.next(); |
||||
} |
||||
}); |
||||
|
||||
Router.route('/boards/:_id/:slug', { |
||||
name: 'Board', |
||||
template: 'board', |
||||
onAfterAction: function() { |
||||
// XXX We probably shouldn't rely on Session
|
||||
Session.set('sidebarIsOpen', true); |
||||
Session.set('menuWidgetIsOpen', false); |
||||
}, |
||||
waitOn: function() { |
||||
var params = this.params; |
||||
Session.set('currentBoard', params._id); |
||||
Session.set('currentCard', null); |
||||
|
||||
return boardSubsManager.subscribe('board', params._id, params.slug); |
||||
}, |
||||
data: function() { |
||||
return Boards.findOne(this.params._id); |
||||
} |
||||
}); |
||||
|
||||
Router.route('/boards/:boardId/:slug/:cardId', { |
||||
name: 'Card', |
||||
template: 'board', |
||||
noEscapeActions: true, |
||||
onAfterAction: function() { |
||||
Tracker.nonreactive(function() { |
||||
if (! Session.get('currentCard') && Sidebar) { |
||||
Sidebar.hide(); |
||||
} |
||||
}); |
||||
EscapeActions.executeUpTo('popup'); |
||||
var params = this.params; |
||||
Session.set('currentBoard', params.boardId); |
||||
Session.set('currentCard', params.cardId); |
||||
}, |
||||
waitOn: function() { |
||||
var params = this.params; |
||||
return boardSubsManager.subscribe('board', params.boardId, params.slug); |
||||
}, |
||||
data: function() { |
||||
return Boards.findOne(this.params.boardId); |
||||
} |
||||
}); |
||||
@ -0,0 +1,5 @@ |
||||
Meteor.subscribe('boards'); |
||||
|
||||
Template.userFormsLayout.onRendered(function() { |
||||
EscapeActions.executeAll(); |
||||
}); |
||||
@ -1,5 +0,0 @@ |
||||
Router.route('/', { |
||||
name: 'Home', |
||||
redirectLoggedInUsers: true, |
||||
authenticated: true |
||||
}); |
||||
@ -1,15 +0,0 @@ |
||||
Router.route('/profile/:username', { |
||||
name: 'Profile', |
||||
template: 'profile', |
||||
waitOn: function() { |
||||
return Meteor.subscribe('profile', this.params.username); |
||||
}, |
||||
data: function() { |
||||
var params = this.params; |
||||
return { |
||||
profile: function() { |
||||
return Users.findOne({ username: params.username }); |
||||
} |
||||
}; |
||||
} |
||||
}); |
||||
@ -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)); |
||||
}] |
||||
}); |
||||
}); |
||||
|
||||
Loading…
Reference in new issue