From 83bbb1d87fc7de2a1dbf23fc38901b492586a432 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 15 Jan 2015 15:55:01 +0100 Subject: [PATCH] Move logic from FirstSyncView to the route --- assets/scripts/app/routes/first_sync.coffee | 26 +++++++++++++++++++++ assets/scripts/app/views.coffee | 20 ---------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/assets/scripts/app/routes/first_sync.coffee b/assets/scripts/app/routes/first_sync.coffee index 66d90319..466dbea3 100644 --- a/assets/scripts/app/routes/first_sync.coffee +++ b/assets/scripts/app/routes/first_sync.coffee @@ -1,9 +1,35 @@ require 'routes/route' require 'routes/simple_layout' +require 'models/repo' SimpleLayoutRoute = Travis.SimpleLayoutRoute +Repo = Travis.Repo Route = SimpleLayoutRoute.extend + activate: -> + controller = @controllerFor('firstSync') + controller.addObserver('isSyncing', this, @isSyncingDidChange) + + deactivate: -> + controller = @controllerFor('firstSync') + controller.removeObserver('controller.isSyncing', this, @isSyncingDidChange) + + isSyncingDidChange: -> + controller = @controllerFor('firstSync') + + if !controller.get('isSyncing') + self = this + Ember.run.later this, -> + Repo.fetch(member: @get('controller.user.login')).then( (repos) -> + if repos.get('length') + self.transitionTo('main') + else + self.transitionTo('profile') + ).then(null, (e) -> + console.log('There was a problem while redirecting from first sync', e) + ) + , @get('config').syncingPageRedirectionTime + actions: redirectToGettingStarted: -> # do nothing, we are showing first sync, so it's normal that there is diff --git a/assets/scripts/app/views.coffee b/assets/scripts/app/views.coffee index d8aa406c..39ee6bb9 100644 --- a/assets/scripts/app/views.coffee +++ b/assets/scripts/app/views.coffee @@ -24,26 +24,6 @@ Travis.InsufficientOauthPermissionsView = Travis.View.extend Travis.FirstSyncView = Travis.View.extend layoutName: 'layouts/simple' classNames: ['application'] - didInsertElement: -> - this.addObserver('controller.isSyncing', this, this.isSyncingDidChange) - - willDestroyElement: -> - this.removeObserver('controller.isSyncing', this, this.isSyncingDidChange) - - isSyncingDidChange: -> - if !@get('controller.isSyncing') - self = this - Ember.run.later this, -> - Travis.Repo.fetch(member: @get('controller.user.login')).then( (repos) -> - if repos.get('length') - self.get('controller').transitionToRoute('index') - else - self.get('controller').transitionToRoute('profile') - ).then(null, (e) -> - console.log('There was a problem while redirecting from first sync', e) - ) - , Travis.config.syncingPageRedirectionTime - Travis.SidebarView = Travis.View.extend classQueues: (->