Extract ApplicationRoute to a separate file
This commit is contained in:
parent
5c280001d3
commit
8715087237
|
@ -1,4 +1,5 @@
|
||||||
require 'travis/location'
|
require 'travis/location'
|
||||||
|
require 'routes/application'
|
||||||
|
|
||||||
Ember.Router.reopen
|
Ember.Router.reopen
|
||||||
location: (if testMode? then Ember.NoneLocation.create() else Travis.Location.create())
|
location: (if testMode? then Ember.NoneLocation.create() else Travis.Location.create())
|
||||||
|
@ -7,64 +8,6 @@ Ember.Router.reopen
|
||||||
url = url.replace(/#.*?$/, '')
|
url = url.replace(/#.*?$/, '')
|
||||||
@_super(url)
|
@_super(url)
|
||||||
|
|
||||||
Travis.Route = Ember.Route.extend
|
|
||||||
beforeModel: (transition) ->
|
|
||||||
@auth.autoSignIn() unless @signedIn()
|
|
||||||
|
|
||||||
if !@signedIn() && @get('needsAuth')
|
|
||||||
@auth.set('afterSignInTransition', transition)
|
|
||||||
Ember.RSVP.reject("needs-auth")
|
|
||||||
else
|
|
||||||
@_super.apply(this, arguments)
|
|
||||||
|
|
||||||
signedIn: ->
|
|
||||||
@controllerFor('currentUser').get('model')
|
|
||||||
|
|
||||||
needsAuth: (->
|
|
||||||
# on pro, we need to auth on every route
|
|
||||||
Travis.config.pro
|
|
||||||
).property()
|
|
||||||
|
|
||||||
Travis.ApplicationRoute = Travis.Route.extend
|
|
||||||
needsAuth: false
|
|
||||||
|
|
||||||
renderTemplate: ->
|
|
||||||
if Travis.config.pro
|
|
||||||
$('body').addClass('pro')
|
|
||||||
|
|
||||||
@_super.apply(this, arguments)
|
|
||||||
|
|
||||||
actions:
|
|
||||||
redirectToGettingStarted: ->
|
|
||||||
# do nothing, we handle it only in index path
|
|
||||||
|
|
||||||
renderDefaultTemplate: ->
|
|
||||||
@renderDefaultTemplate() if @renderDefaultTemplate
|
|
||||||
|
|
||||||
error: (error) ->
|
|
||||||
if error == 'needs-auth'
|
|
||||||
authController = @container.lookup('controller:auth')
|
|
||||||
authController.set('redirected', true)
|
|
||||||
@transitionTo('auth')
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
|
|
||||||
renderFirstSync: ->
|
|
||||||
@transitionTo 'first_sync'
|
|
||||||
|
|
||||||
afterSignIn: ->
|
|
||||||
if transition = @auth.get('afterSignInTransition')
|
|
||||||
@auth.set('afterSignInTransition', null)
|
|
||||||
transition.retry()
|
|
||||||
else
|
|
||||||
@transitionTo('main')
|
|
||||||
|
|
||||||
afterSignOut: ->
|
|
||||||
if Travis.config.pro
|
|
||||||
@transitionTo('auth')
|
|
||||||
else
|
|
||||||
@transitionTo('main')
|
|
||||||
|
|
||||||
Travis.Router.map ->
|
Travis.Router.map ->
|
||||||
@resource 'main', path: '/', ->
|
@resource 'main', path: '/', ->
|
||||||
@resource 'getting_started'
|
@resource 'getting_started'
|
||||||
|
|
45
assets/scripts/app/routes/application.coffee
Normal file
45
assets/scripts/app/routes/application.coffee
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
require 'routes/route'
|
||||||
|
|
||||||
|
TravisRoute = Travis.Route
|
||||||
|
|
||||||
|
Route = TravisRoute.extend
|
||||||
|
needsAuth: false
|
||||||
|
|
||||||
|
renderTemplate: ->
|
||||||
|
if @get('config').pro
|
||||||
|
$('body').addClass('pro')
|
||||||
|
|
||||||
|
@_super.apply(this, arguments)
|
||||||
|
|
||||||
|
actions:
|
||||||
|
redirectToGettingStarted: ->
|
||||||
|
# do nothing, we handle it only in index path
|
||||||
|
|
||||||
|
renderDefaultTemplate: ->
|
||||||
|
@renderDefaultTemplate() if @renderDefaultTemplate
|
||||||
|
|
||||||
|
error: (error) ->
|
||||||
|
if error == 'needs-auth'
|
||||||
|
authController = @container.lookup('controller:auth')
|
||||||
|
authController.set('redirected', true)
|
||||||
|
@transitionTo('auth')
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
|
||||||
|
renderFirstSync: ->
|
||||||
|
@transitionTo 'first_sync'
|
||||||
|
|
||||||
|
afterSignIn: ->
|
||||||
|
if transition = @auth.get('afterSignInTransition')
|
||||||
|
@auth.set('afterSignInTransition', null)
|
||||||
|
transition.retry()
|
||||||
|
else
|
||||||
|
@transitionTo('main')
|
||||||
|
|
||||||
|
afterSignOut: ->
|
||||||
|
if @get('config').pro
|
||||||
|
@transitionTo('auth')
|
||||||
|
else
|
||||||
|
@transitionTo('main')
|
||||||
|
|
||||||
|
Travis.ApplicationRoute = Route
|
19
assets/scripts/app/routes/route.coffee
Normal file
19
assets/scripts/app/routes/route.coffee
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
Route = Ember.Route.extend
|
||||||
|
beforeModel: (transition) ->
|
||||||
|
@auth.autoSignIn() unless @signedIn()
|
||||||
|
|
||||||
|
if !@signedIn() && @get('needsAuth')
|
||||||
|
@auth.set('afterSignInTransition', transition)
|
||||||
|
Ember.RSVP.reject("needs-auth")
|
||||||
|
else
|
||||||
|
@_super.apply(this, arguments)
|
||||||
|
|
||||||
|
signedIn: ->
|
||||||
|
@controllerFor('currentUser').get('model')
|
||||||
|
|
||||||
|
needsAuth: (->
|
||||||
|
# on pro, we need to auth on every route
|
||||||
|
Travis.config.pro
|
||||||
|
).property()
|
||||||
|
|
||||||
|
Travis.Route = Route
|
|
@ -180,6 +180,7 @@ Travis.initializer
|
||||||
application.register 'config:main', Travis.config, { instantiate: false }
|
application.register 'config:main', Travis.config, { instantiate: false }
|
||||||
|
|
||||||
application.inject('controller', 'config', 'config:main')
|
application.inject('controller', 'config', 'config:main')
|
||||||
|
application.inject('route', 'config', 'config:main')
|
||||||
|
|
||||||
|
|
||||||
Travis.Router.reopen
|
Travis.Router.reopen
|
||||||
|
|
Loading…
Reference in New Issue
Block a user