First stab at fixing weird view errors
This commit starts refactoring of one of the remaining areas where we do weird tricks to get the desired behaviour. Namely, we were treating "my_repositories" and "recent" not as individual routes with separate URLs, but only different states on the repos controller. Such approach leads to various problem with connecting outlets on rerenders (ie. we don't explicitly connect outlets when changing from one view to another programatically). A new cleaner way is to change both tabs into routes.
This commit is contained in:
parent
0dfb5dc10c
commit
5f2f4c3852
|
@ -3,23 +3,8 @@ require 'travis/limited_array'
|
||||||
Travis.ReposController = Ember.ArrayController.extend
|
Travis.ReposController = Ember.ArrayController.extend
|
||||||
actions:
|
actions:
|
||||||
activate: (name) ->
|
activate: (name) ->
|
||||||
@transitionToRoot()
|
|
||||||
@activate(name)
|
@activate(name)
|
||||||
|
|
||||||
defaultTab: ( ->
|
|
||||||
if @get('currentUser.id')
|
|
||||||
'owned'
|
|
||||||
else
|
|
||||||
'recent'
|
|
||||||
).property('currentUser.id')
|
|
||||||
|
|
||||||
currentUserIdDidChange: (->
|
|
||||||
if @get('currentUser.id')
|
|
||||||
@activate('owned')
|
|
||||||
else if @get('tab') == 'owned'
|
|
||||||
@activate('recent')
|
|
||||||
).observes('currentUser.id')
|
|
||||||
|
|
||||||
tabOrIsLoadedDidChange: (->
|
tabOrIsLoadedDidChange: (->
|
||||||
@possiblyRedirectToGettingStartedPage()
|
@possiblyRedirectToGettingStartedPage()
|
||||||
).observes('isLoaded', 'tab', 'length')
|
).observes('isLoaded', 'tab', 'length')
|
||||||
|
@ -58,13 +43,8 @@ Travis.ReposController = Ember.ArrayController.extend
|
||||||
if content = @get('content')
|
if content = @get('content')
|
||||||
content.forEach (r) -> r.updateTimes()
|
content.forEach (r) -> r.updateTimes()
|
||||||
|
|
||||||
transitionToRoot: ->
|
|
||||||
@container.lookup('router:main').send('renderDefaultTemplate')
|
|
||||||
@container.lookup('router:main').transitionTo('index.current')
|
|
||||||
|
|
||||||
activate: (tab, params) ->
|
activate: (tab, params) ->
|
||||||
@set('sortProperties', ['sortOrder'])
|
@set('sortProperties', ['sortOrder'])
|
||||||
tab ||= @get('defaultTab')
|
|
||||||
@set('tab', tab)
|
@set('tab', tab)
|
||||||
this["view#{$.camelize(tab)}"](params)
|
this["view#{$.camelize(tab)}"](params)
|
||||||
|
|
||||||
|
|
|
@ -43,14 +43,17 @@ Travis.ApplicationRoute = Travis.Route.extend
|
||||||
if transition = @auth.get('afterSignInTransition')
|
if transition = @auth.get('afterSignInTransition')
|
||||||
@auth.set('afterSignInTransition', null)
|
@auth.set('afterSignInTransition', null)
|
||||||
transition.retry()
|
transition.retry()
|
||||||
|
else
|
||||||
|
@transitionTo('index')
|
||||||
|
|
||||||
afterSignOut: ->
|
afterSignOut: ->
|
||||||
@transitionTo('index.current')
|
@transitionTo('index')
|
||||||
|
|
||||||
Travis.Router.map ->
|
Travis.Router.map ->
|
||||||
@resource 'index', path: '/', ->
|
@resource 'index', path: '/', ->
|
||||||
@resource 'getting_started'
|
@resource 'getting_started'
|
||||||
@route 'current', path: '/'
|
@route 'recent', path: '/recent'
|
||||||
|
@route 'my_repositories', path: '/my_repositories'
|
||||||
@resource 'repo', path: '/:owner/:name', ->
|
@resource 'repo', path: '/:owner/:name', ->
|
||||||
@route 'index', path: '/'
|
@route 'index', path: '/'
|
||||||
@resource 'build', path: '/builds/:build_id'
|
@resource 'build', path: '/builds/:build_id'
|
||||||
|
@ -130,7 +133,8 @@ Travis.GettingStartedRoute = Travis.Route.extend
|
||||||
Travis.SimpleLayoutRoute = Travis.Route.extend
|
Travis.SimpleLayoutRoute = Travis.Route.extend
|
||||||
setupController: ->
|
setupController: ->
|
||||||
$('body').attr('id', 'home')
|
$('body').attr('id', 'home')
|
||||||
@container.lookup('controller:repos').activate()
|
toActivate = if @signedIn() then 'owned' else 'recent'
|
||||||
|
@container.lookup('controller:repos').activate(toActivate)
|
||||||
@_super.apply(this, arguments)
|
@_super.apply(this, arguments)
|
||||||
|
|
||||||
renderTemplate: ->
|
renderTemplate: ->
|
||||||
|
@ -148,7 +152,7 @@ Travis.InsufficientOauthPermissionsRoute = Travis.SimpleLayoutRoute.extend
|
||||||
existingUser = document.location.hash.match(/#existing[_-]user/)
|
existingUser = document.location.hash.match(/#existing[_-]user/)
|
||||||
controller.set('existingUser', existingUser)
|
controller.set('existingUser', existingUser)
|
||||||
|
|
||||||
Travis.IndexCurrentRoute = Travis.Route.extend
|
Travis.IndexMyRepositoriesRoute = Travis.Route.extend
|
||||||
renderTemplate: ->
|
renderTemplate: ->
|
||||||
@render 'repo'
|
@render 'repo'
|
||||||
@render 'build', into: 'repo'
|
@render 'build', into: 'repo'
|
||||||
|
@ -158,6 +162,34 @@ Travis.IndexCurrentRoute = Travis.Route.extend
|
||||||
@currentRepoDidChange()
|
@currentRepoDidChange()
|
||||||
|
|
||||||
@controllerFor('repo').activate('index')
|
@controllerFor('repo').activate('index')
|
||||||
|
@controllerFor('repos').activate('owned')
|
||||||
|
@controllerFor('repos').addObserver('firstObject', this, 'currentRepoDidChange')
|
||||||
|
|
||||||
|
afterModel: ->
|
||||||
|
@controllerFor('repos').possiblyRedirectToGettingStartedPage()
|
||||||
|
|
||||||
|
deactivate: ->
|
||||||
|
@controllerFor('repos').removeObserver('firstObject', this, 'currentRepoDidChange')
|
||||||
|
|
||||||
|
currentRepoDidChange: ->
|
||||||
|
@controllerFor('repo').set('repo', @controllerFor('repos').get('firstObject'))
|
||||||
|
|
||||||
|
actions:
|
||||||
|
redirectToGettingStarted: ->
|
||||||
|
@transitionTo('getting_started')
|
||||||
|
|
||||||
|
|
||||||
|
Travis.IndexRecentRoute = Travis.Route.extend
|
||||||
|
renderTemplate: ->
|
||||||
|
@render 'repo'
|
||||||
|
@render 'build', into: 'repo'
|
||||||
|
|
||||||
|
setupController: ->
|
||||||
|
@_super.apply this, arguments
|
||||||
|
@currentRepoDidChange()
|
||||||
|
|
||||||
|
@controllerFor('repo').activate('index')
|
||||||
|
@controllerFor('repos').activate('recent')
|
||||||
@controllerFor('repos').addObserver('firstObject', this, 'currentRepoDidChange')
|
@controllerFor('repos').addObserver('firstObject', this, 'currentRepoDidChange')
|
||||||
|
|
||||||
afterModel: ->
|
afterModel: ->
|
||||||
|
@ -293,6 +325,13 @@ Travis.RepoRoute = Travis.Route.extend
|
||||||
# bubble to the top
|
# bubble to the top
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
# Obviously Index route should be renamed to something
|
||||||
|
# like "main" or "home"
|
||||||
|
Travis.IndexIndexRoute = Travis.Route.extend
|
||||||
|
redirect: ->
|
||||||
|
target = if @signedIn() then 'my_repositories' else 'recent'
|
||||||
|
@transitionTo("index.#{target}")
|
||||||
|
|
||||||
Travis.IndexRoute = Travis.Route.extend
|
Travis.IndexRoute = Travis.Route.extend
|
||||||
renderTemplate: ->
|
renderTemplate: ->
|
||||||
$('body').attr('id', 'home')
|
$('body').attr('id', 'home')
|
||||||
|
@ -302,7 +341,9 @@ Travis.IndexRoute = Travis.Route.extend
|
||||||
@render 'repos', outlet: 'left', into: 'index'
|
@render 'repos', outlet: 'left', into: 'index'
|
||||||
|
|
||||||
setupController: (controller)->
|
setupController: (controller)->
|
||||||
@container.lookup('controller:repos').activate()
|
# TODO: this is redundant with my_repositories and recent routes
|
||||||
|
toActivate = if @signedIn() then 'owned' else 'recent'
|
||||||
|
@container.lookup('controller:repos').activate(toActivate)
|
||||||
|
|
||||||
Travis.StatsRoute = Travis.Route.extend
|
Travis.StatsRoute = Travis.Route.extend
|
||||||
renderTemplate: ->
|
renderTemplate: ->
|
||||||
|
@ -377,7 +418,7 @@ Travis.AuthRoute = Travis.Route.extend
|
||||||
|
|
||||||
actions:
|
actions:
|
||||||
afterSignIn: ->
|
afterSignIn: ->
|
||||||
@transitionTo('index.current')
|
@transitionTo('index')
|
||||||
return true
|
return true
|
||||||
|
|
||||||
Travis.SettingsRoute = Travis.Route.extend
|
Travis.SettingsRoute = Travis.Route.extend
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{{#link-to "index.current"}}
|
{{#link-to "index"}}
|
||||||
<div id="home">
|
<div id="home">
|
||||||
<h1>Travis</h1>
|
<h1>Travis</h1>
|
||||||
</div>
|
</div>
|
||||||
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<ul id="navigation">
|
<ul id="navigation">
|
||||||
<li class="home">
|
<li class="home">
|
||||||
{{#link-to "index.current"}}Home{{/link-to}}
|
{{#link-to "index"}}Home{{/link-to}}
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="http://blog.travis-ci.com">Blog</a>
|
<a href="http://blog.travis-ci.com">Blog</a>
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<ul class="tabs">
|
<ul class="tabs">
|
||||||
<li id="tab_owned" {{bind-attr class="view.classOwned"}}>
|
<li id="tab_owned" {{bind-attr class="view.classOwned"}}>
|
||||||
<h5><a {{action "activate" "owned"}}>My Repositories</a></h5>
|
<h5>{{#link-to "index.my_repositories"}}My Repositories{{/link-to}}</h5>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li id="tab_recent" {{bind-attr class="view.classRecent"}}>
|
<li id="tab_recent" {{bind-attr class="view.classRecent"}}>
|
||||||
<h5><a {{action "activate" "recent"}}>Recent</a></h5>
|
<h5>{{#link-to "index.recent"}}Recent{{/link-to}}</h5>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li id="tab_search" {{bind-attr class="view.classSearch"}}>
|
<li id="tab_search" {{bind-attr class="view.classSearch"}}>
|
||||||
|
|
|
@ -47,7 +47,7 @@ Travis.FirstSyncView = Travis.View.extend
|
||||||
Ember.run.later this, ->
|
Ember.run.later this, ->
|
||||||
Travis.Repo.fetch(member: @get('controller.user.login')).then( (repos) ->
|
Travis.Repo.fetch(member: @get('controller.user.login')).then( (repos) ->
|
||||||
if repos.get('length')
|
if repos.get('length')
|
||||||
self.get('controller').transitionToRoute('index.current')
|
self.get('controller').transitionToRoute('index')
|
||||||
else
|
else
|
||||||
self.get('controller').transitionToRoute('profile')
|
self.get('controller').transitionToRoute('profile')
|
||||||
).then(null, (e) ->
|
).then(null, (e) ->
|
||||||
|
|
|
@ -2,7 +2,7 @@ require 'log'
|
||||||
require 'travis/lines_selector'
|
require 'travis/lines_selector'
|
||||||
require 'travis/log_folder'
|
require 'travis/log_folder'
|
||||||
|
|
||||||
Log.DEBUG = true
|
Log.DEBUG = false
|
||||||
Log.LIMIT = 10000
|
Log.LIMIT = 10000
|
||||||
|
|
||||||
Travis.reopen
|
Travis.reopen
|
||||||
|
|
|
@ -14,24 +14,6 @@ Travis.reopen
|
||||||
@get('repos.isLoaded') && @get('repos.length') == 0
|
@get('repos.isLoaded') && @get('repos.length') == 0
|
||||||
).property('repos.isLoaded', 'repos.length')
|
).property('repos.isLoaded', 'repos.length')
|
||||||
|
|
||||||
repoIsLoadedDidChange: (->
|
|
||||||
# Ember does not automatically rerender outlets and sometimes 'pane' outlet
|
|
||||||
# in repos/show.hbs is empty when view is rerendered without routing
|
|
||||||
# taking place. Try to render the default outlet in such case
|
|
||||||
# TODO: look into fixing it in more general way
|
|
||||||
Ember.run.schedule('afterRender', this, ->
|
|
||||||
pane = Ember.get('_outlets.pane')
|
|
||||||
if @get('controller.repo.isLoaded') && @_state == 'inDOM' &&
|
|
||||||
@get('controller.repo.lastBuild') &&
|
|
||||||
@get('controller.tab') == 'current' && (!pane || pane._state == 'destroyed')
|
|
||||||
view = @get('controller.container').lookup('view:build')
|
|
||||||
view.set('controller', @get('controller.container').lookup('controller:build'))
|
|
||||||
Ember.run.next =>
|
|
||||||
@set('_outlets', {}) if !@get('_outlets') && !@isDestroyed
|
|
||||||
@connectOutlet('pane', view) unless @isDestroyed
|
|
||||||
)
|
|
||||||
).observes('controller.repo.isLoaded')
|
|
||||||
|
|
||||||
statusImages: ->
|
statusImages: ->
|
||||||
@popupCloseAll()
|
@popupCloseAll()
|
||||||
view = Travis.StatusImagesView.create(toolsView: this)
|
view = Travis.StatusImagesView.create(toolsView: this)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user