Move checking for errors to router rather than template
Previously we were checking if we should display an error message by adding if statements in a template. This is not the best way to do it, because it clutters a template and makes code harder to follow. In this commit I move rendering error templates to the router. Code for rendering error when there is no builds is not the best way to do it either, but it can be improved when new router changes are merged to Ember's master and a way Ember Data is handling promises is revised and improved.
This commit is contained in:
parent
f87e4108a8
commit
50cdc4cf98
|
@ -3,7 +3,6 @@ Travis.RepoController = Travis.Controller.extend
|
|||
needs: ['repos', 'currentUser']
|
||||
currentUserBinding: 'controllers.currentUser'
|
||||
|
||||
isError: (-> @get('repo.isError') ).property('repo.isError')
|
||||
slug: (-> @get('repo.slug') ).property('repo.slug')
|
||||
isLoading: (-> @get('repo.isLoading') ).property('repo.isLoading')
|
||||
|
||||
|
|
|
@ -123,11 +123,19 @@ Travis.SetupLastBuild = Ember.Mixin.create
|
|||
setupController: ->
|
||||
@lastBuildDidChange()
|
||||
@controllerFor('repo').addObserver('repo.lastBuild', this, 'lastBuildDidChange')
|
||||
@repoDidLoad()
|
||||
@controllerFor('repo').addObserver('repo.isLoaded', this, 'repoDidLoad')
|
||||
|
||||
deactivate: ->
|
||||
@_super.apply this, arguments
|
||||
@controllerFor('repo').removeObserver('repo.lastBuild', this, 'lastBuildDidChange')
|
||||
|
||||
repoDidLoad: ->
|
||||
# TODO: it would be nicer to do it with promises
|
||||
repo = @controllerFor('repo').get('repo')
|
||||
if repo && repo.get('isLoaded') && !repo.get('repo.lastBuild')
|
||||
@render('builds/not_found', outlet: 'pane', into: 'repo')
|
||||
|
||||
lastBuildDidChange: ->
|
||||
build = @controllerFor('repo').get('repo.lastBuild')
|
||||
@controllerFor('build').set('build', build)
|
||||
|
@ -238,15 +246,15 @@ Travis.RepoRoute = Ember.Route.extend Travis.DontSetupModelForControllerMixin,
|
|||
|
||||
repos = Travis.Repo.bySlug(slug)
|
||||
|
||||
self = this
|
||||
|
||||
observer = ->
|
||||
if repos.get 'isLoaded'
|
||||
repos.removeObserver 'isLoaded', observer
|
||||
proxy.set 'isLoading', false
|
||||
|
||||
if repos.get('length') == 0
|
||||
# isError is also used in DS.Model, but maybe we should use something
|
||||
# more focused like notFound later
|
||||
proxy.set 'isError', true
|
||||
self.render('repos/not_found', outlet: 'main')
|
||||
else
|
||||
proxy.set 'content', repos.objectAt(0)
|
||||
|
||||
|
|
1
assets/scripts/app/templates/builds/not_found.hbs
Normal file
1
assets/scripts/app/templates/builds/not_found.hbs
Normal file
|
@ -0,0 +1 @@
|
|||
There are no builds for this repository.
|
|
@ -1,7 +1,6 @@
|
|||
{{#if loading}}
|
||||
<span>Loading</span>
|
||||
{{else}}
|
||||
{{#if build}}
|
||||
<dl id="summary">
|
||||
<div class="left">
|
||||
<dt>{{t builds.name}}</dt>
|
||||
|
@ -60,7 +59,4 @@
|
|||
{{else}}
|
||||
{{view Travis.LogView jobBinding="build.jobs.firstObject"}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
There are no builds for this repository.
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
|
3
assets/scripts/app/templates/repos/not_found.hbs
Normal file
3
assets/scripts/app/templates/repos/not_found.hbs
Normal file
|
@ -0,0 +1,3 @@
|
|||
<div id="repo">
|
||||
<span class="not-found">The repository at {{slug}} was not found.</span>
|
||||
</div>
|
|
@ -1,9 +1,6 @@
|
|||
<div id="repo" {{bindAttr class="view.className"}}>
|
||||
{{#if view.isEmpty}}
|
||||
{{view Travis.ReposEmptyView}}
|
||||
{{else}}
|
||||
{{#if isError}}
|
||||
<span class="not-found">The repository at {{slug}} was not found.</span>
|
||||
{{else}}
|
||||
{{#if repo.isLoaded}}
|
||||
{{#with repo}}
|
||||
|
@ -25,6 +22,5 @@
|
|||
<span>Loading</span>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ Travis.reopen
|
|||
# TODO: look into fixing it in more general way
|
||||
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'))
|
||||
|
|
Loading…
Reference in New Issue
Block a user