From 871508723707f0d4331ae6db2c247c7c40578909 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 14 Jan 2015 14:07:05 +0100 Subject: [PATCH] Extract ApplicationRoute to a separate file --- assets/scripts/app/routes.coffee | 59 +------------------- assets/scripts/app/routes/application.coffee | 45 +++++++++++++++ assets/scripts/app/routes/route.coffee | 19 +++++++ assets/scripts/travis.coffee | 1 + 4 files changed, 66 insertions(+), 58 deletions(-) create mode 100644 assets/scripts/app/routes/application.coffee create mode 100644 assets/scripts/app/routes/route.coffee diff --git a/assets/scripts/app/routes.coffee b/assets/scripts/app/routes.coffee index 6d224156..031689aa 100644 --- a/assets/scripts/app/routes.coffee +++ b/assets/scripts/app/routes.coffee @@ -1,4 +1,5 @@ require 'travis/location' +require 'routes/application' Ember.Router.reopen location: (if testMode? then Ember.NoneLocation.create() else Travis.Location.create()) @@ -7,64 +8,6 @@ Ember.Router.reopen url = url.replace(/#.*?$/, '') @_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 -> @resource 'main', path: '/', -> @resource 'getting_started' diff --git a/assets/scripts/app/routes/application.coffee b/assets/scripts/app/routes/application.coffee new file mode 100644 index 00000000..04dc6a7c --- /dev/null +++ b/assets/scripts/app/routes/application.coffee @@ -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 diff --git a/assets/scripts/app/routes/route.coffee b/assets/scripts/app/routes/route.coffee new file mode 100644 index 00000000..318bd68e --- /dev/null +++ b/assets/scripts/app/routes/route.coffee @@ -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 diff --git a/assets/scripts/travis.coffee b/assets/scripts/travis.coffee index 0690389f..e6691600 100644 --- a/assets/scripts/travis.coffee +++ b/assets/scripts/travis.coffee @@ -180,6 +180,7 @@ Travis.initializer application.register 'config:main', Travis.config, { instantiate: false } application.inject('controller', 'config', 'config:main') + application.inject('route', 'config', 'config:main') Travis.Router.reopen