Created
July 28, 2014 13:10
-
-
Save bitomule/0e948266d83c5ee2f67b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subs = new SubsManager({ | |
// will be cached only 20 recently used subscriptions | |
cacheLimit: 20, | |
// any subscription will be expired after 5 minutes of inactivity | |
expireIn: 20 | |
}); | |
Router.configure({ | |
layoutTemplate: 'layout', | |
loadingTemplate: 'loading' | |
}); | |
Deps.autorun(function () { | |
subs.subscribe('userData',this.userId); | |
}); | |
Router.map(function(){ | |
this.route('publichome',{ | |
path: '/', | |
layoutTemplate: 'layout', | |
onAfterAction: function(){ | |
document.title = "Domain"; | |
} | |
}); | |
this.route('register',{ | |
path: '/register', | |
layoutTemplate: 'layout', | |
onAfterAction: function(){ | |
document.title = "Register"; | |
} | |
}); | |
this.route('login',{ | |
path: '/:_domain/login', | |
layoutTemplate: 'layout', | |
data: function(){ | |
if(this.ready()) | |
{ | |
Session.set('_domain', Domains.findOne().fullName); | |
Session.set('urlname', Domains.findOne().name); | |
return {domainname:Domains.findOne().fullName}; | |
} | |
}, | |
waitOn: function(){ | |
return [subs.subscribe('userDomain',this.params._domain)]; | |
}, | |
onAfterAction: function(){ | |
document.title = "Login"; | |
if(this.ready()) | |
{ | |
if(Domains.find().count() === 0) { | |
Router.go('register'); | |
} | |
} | |
} | |
}); | |
this.route('home',{ | |
path: '/:_domain', | |
layoutTemplate: 'privateLayout', | |
data: function(){ | |
return {'domainname':this.params._domain}; | |
}, | |
waitOn: function(){ | |
return [subs.subscribe('userDomain',this.params._domain),subs.subscribe('notes'),subs.subscribe('projects'),subs.subscribe('tasks'),subs.subscribe('images')]; | |
}, | |
onAfterAction: function(){ | |
document.title = "Home"; | |
if(this.ready()) | |
{ | |
if(Domains.find().count() === 0) { | |
Router.go('register'); | |
} | |
} | |
} | |
}); | |
this.route('project',{ | |
path: '/:_domain/projects/:_project', | |
layoutTemplate: 'privateLayout', | |
data: function(){ | |
return {'domainname':this.params._domain}; | |
}, | |
waitOn: function(){ | |
return [subs.subscribe('userDomain',this.params._domain),subs.subscribe('projects'),subs.subscribe('tasks'),subs.subscribe('images')]; | |
}, | |
onAfterAction: function(){ | |
document.title = "Project"; | |
if(this.ready()) | |
{ | |
if(Domains.find().count() === 0) { | |
Router.go('register'); | |
} | |
if(Projects.find({_id:this.params._project}).count() === 0) { | |
Router.go('home',{_domain:this.params._domain}); | |
} | |
} | |
} | |
}); | |
this.route('task',{ | |
path: '/:_domain/tasks/:_task', | |
layoutTemplate: 'privateLayout', | |
data: function(){ | |
return {'domainname':this.params._domain}; | |
}, | |
waitOn: function(){ | |
return [subs.subscribe('userDomain',this.params._domain)]; | |
}, | |
onAfterAction: function(){ | |
document.title = "Task"; | |
if(this.ready()) | |
{ | |
if(Domains.find().count() === 0) { | |
Router.go('register'); | |
} | |
} | |
} | |
}); | |
}); | |
var requireLogin = function(pause){ | |
var routeName = this.route.name; | |
if(!Meteor.userId()){ | |
Router.go('login',{_domain:this.params._domain}); | |
pause(); | |
} | |
}; | |
Router.onBeforeAction(requireLogin, {except: ['login','register','publichome']}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment