Skip to content

Commit

Permalink
Redirect now works with a non-default layoutTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
lmaccherone committed Oct 12, 2014
1 parent 6baf5c7 commit b5d2153
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 53 deletions.
3 changes: 3 additions & 0 deletions .meteor/packages
Expand Up @@ -12,3 +12,6 @@ coffeescript
linto:fontawesome
mizzao:bootstrap-3
mquandalle:jade
accounts-github
accounts-ui
accounts-password
15 changes: 15 additions & 0 deletions .meteor/versions
@@ -1,3 +1,9 @@
accounts-base@1.1.1
accounts-github@1.0.1
accounts-oauth@1.1.1
accounts-password@1.0.2
accounts-ui-unstyled@1.1.2
accounts-ui@1.1.1
application-configuration@1.0.2
autopublish@1.0.0
autoupdate@1.1.1
Expand All @@ -14,9 +20,11 @@ ctl@1.0.1
ddp@1.0.9
deps@1.0.4
ejson@1.0.3
email@1.0.3
fastclick@1.0.0
follower-livedata@1.0.1
geojson-utils@1.0.0
github@1.1.0
html-tools@1.0.1
htmljs@1.0.1
http@1.0.6
Expand All @@ -31,6 +39,7 @@ json@1.0.0
less@1.0.9
linto:fontawesome@1.0.1
livedata@1.0.10
localstorage@1.0.0
logging@1.0.3
meteor-platform@1.1.1
meteor@1.1.1
Expand All @@ -40,6 +49,9 @@ mizzao:bootstrap-3@3.2.0_1
mobile-status-bar@1.0.0
mongo@1.0.6
mquandalle:jade@0.2.8
npm-bcrypt@0.7.7
oauth2@1.1.0
oauth@1.1.0
observe-sequence@1.0.2
ordered-dict@1.0.0
random@1.0.0
Expand All @@ -48,9 +60,12 @@ reactive-var@1.0.2
reload@1.1.0
retry@1.0.0
routepolicy@1.0.1
service-configuration@1.0.1
session@1.0.2
sha@1.0.0
spacebars-compiler@1.0.2
spacebars@1.0.2
srp@1.0.0
templating@1.0.7
tracker@1.0.2
ui@1.0.3
Expand Down
58 changes: 22 additions & 36 deletions client/login.jade
@@ -1,40 +1,26 @@
head
meta(charset="utf-8")
meta(http-equiv="X-UA-Compatible", content="IE=edge")
meta(name="viewport", content="width=device-width, initial-scale=1")
meta(name="description", content="")
meta(name="author", content="")
title SB Admin 2 Meteor

template(name="loginLayout")
+head
body
.container
.row
.col-md-4.col-md-offset-4
.login-panel.panel.panel-default
.panel-heading
h3.panel-title Please Sign In
.panel-body
form(role="form")
fieldset
.form-group
input.form-control(type="email", placeholder="E-mail", name="email", autofocus="")
.form-group
input.form-control(type="password", placeholder="Password", name="password", value="")
.checkbox
label
input(type="checkbox", name="remember", value="Remember Me")
| Remember Me
// Change this to a button or input when using this as a form
a.btn.btn-lg.btn-success.btn-block(href="index.html") Login
// jQuery Version 1.11.0
script(src="js/jquery-1.11.0.js")
// Bootstrap Core JavaScript
script(src="js/bootstrap.min.js")
// Metis Menu Plugin JavaScript
script(src="js/plugins/metisMenu/metisMenu.min.js")
// Custom Theme JavaScript
script(src="js/sb-admin-2.js")
h1 Something
+yield

+yield
template(name="login")
.container
.row
.col-md-4.col-md-offset-4
.login-panel.panel.panel-default
.panel-heading
h3.panel-title Please Sign In
.panel-body
form(role="form")
fieldset
.form-group
input.form-control(type="email", placeholder="E-mail", name="email", autofocus="")
.form-group
input.form-control(type="password", placeholder="Password", name="password", value="")
.checkbox
label
input(type="checkbox", name="remember", value="Remember Me")
| Remember Me
// Change this to a button or input when using this as a form
a.btn.btn-lg.btn-success.btn-block(href="/") Login
13 changes: 6 additions & 7 deletions client/routes.coffee
Expand Up @@ -13,13 +13,12 @@ navRoutes = [
new NavRoute('panels-and-wells', '', {parentName: 'ui-elements', label: 'Panels and Wells'})
new NavRoute('pages', 'fa-files-o', {label: "Sample Pages"})
new NavRoute('blank', '', {parentName: 'pages', label: "Blank Page"})
new NavRoute('login', '', {parentName: 'pages'})
new NavRoute('login-ref', '', {redirect: 'login', parentName: 'pages', template: 'login', layoutTemplate: 'loginLayout'})
new NavRoute('login', '', {isMainNav: false, layoutTemplate: 'loginLayout'})
new NavRoute('', '', {isMainNav: false, redirect: 'dashboard'})
new NavRoute('index', '', {isMainNav: false, redirect: 'dashboard'})
]

redirects = [
{from: ['/', '/index'], to: '/dashboard'}
]

navRouteList = new NavRouteList(navRoutes, redirects)
navRouteList = new NavRouteList(navRoutes)

Session.set('navRoots', navRouteList.rootRoutes)
Session.set('navRoots', navRouteList.rootNavRoutes)
31 changes: 21 additions & 10 deletions lib/nav-route.coffee
@@ -1,53 +1,64 @@
DEFAULT_MAIN_LAYOUT = 'mainLayout'

class NavRoute
constructor: (@name, @icon, @config) ->
unless @name?
throw new Error('Must provide a name for each NavRoute')
unless @config?
@config = {}
{@template, @isMainNav, @label, @path, @parentName} = @config
{@template, @isMainNav, @label, @path, @parentName, @layoutTemplate, @redirect} = @config
unless @template?
@template = @name
unless @isMainNav?
@isMainNav = true
unless @label?
@label = @name.substr(0, 1).toUpperCase() + @name.substr(1)
if @redirect?
@label = @redirect.substr(0, 1).toUpperCase() + @redirect.substr(1)
else
@label = @name.substr(0, 1).toUpperCase() + @name.substr(1)
unless @path?
@path = '/' + @name
unless @icon?
@icon = null
unless @layoutTemplate?
@layoutTemplate = DEFAULT_MAIN_LAYOUT

class NavRouteList
constructor: (navRoutes, @redirects) ->
constructor: (navRoutes) ->
@routes = []
@routeIndex = {}
@rootRoutes = []
@rootNavRoutes = []
@redirects = []
for route in navRoutes
@addRoute(route)
@setRouter()

addRoute: (route) ->
if @routeIndex.hasOwnProperty(route.name)
throw new Error('Route names must be unique')
if route.parentName? and not route.isMainNav
throw new Error('Children nav nodes must set isMainNav to true.')
unless route.children?
route.children = []
if route.parentName?
parentRoute = @getRoute(route.parentName)
unless parentRoute.isMainNav
throw new Error('Parent nav nodes must set isMainNav to true.')
route.path = parentRoute.path + route.path
parentRoute.children.push(route)
else
@rootRoutes.push(route)
if route.isMainNav
@rootNavRoutes.push(route)
@routes.push(route)
@routeIndex[route.name] = route
if route.redirect?
@redirects.push({from: [route.path], to: route.redirect})

getRoute: (name) ->
return @routeIndex[name]

setRouter: (layoutTemplate = 'mainLayout', redirectTemplate = 'loading', notFoundTemplate = '404') ->
setRouter: (layoutTemplate = DEFAULT_MAIN_LAYOUT, redirectTemplate = 'loading', notFoundTemplate = '404') ->
Router.configure({layoutTemplate})
# set redirects in routes
for r in @redirects
for f in r.from
Router.route('redirect', {path: f, template: redirectTemplate})
# set regular routes
for r in @routes
Router.route(r.name, r)
Expand Down
1 change: 1 addition & 0 deletions server/config.coffee
@@ -0,0 +1 @@
#Accounts.loginServiceConfiguration.

0 comments on commit b5d2153

Please sign in to comment.