travis-web/assets/scripts/app/controllers/repo.coffee
Piotr Sarnacki 50cdc4cf98 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.
2013-06-05 11:37:29 +02:00

61 lines
1.4 KiB
CoffeeScript

Travis.RepoController = Travis.Controller.extend
bindings: []
needs: ['repos', 'currentUser']
currentUserBinding: 'controllers.currentUser'
slug: (-> @get('repo.slug') ).property('repo.slug')
isLoading: (-> @get('repo.isLoading') ).property('repo.isLoading')
init: ->
@_super.apply this, arguments
Visibility.every Travis.INTERVALS.updateTimes, @updateTimes.bind(this)
updateTimes: ->
if builds = @get('builds')
builds.forEach (b) -> b.updateTimes()
if build = @get('build')
build.updateTimes()
if build && jobs = build.get('jobs')
jobs.forEach (j) -> j.updateTimes()
activate: (action) ->
this["view#{$.camelize(action)}"]()
viewIndex: ->
@connectTab('current')
viewCurrent: ->
@connectTab('current')
viewBuilds: ->
@connectTab('builds')
viewPullRequests: ->
@connectTab('pull_requests')
viewBranches: ->
@connectTab('branches')
viewBuild: ->
@connectTab('build')
viewJob: ->
@connectTab('job')
connectTab: (tab) ->
# TODO: such implementation seems weird now, because we render
# in the renderTemplate function in routes
name = if tab == 'current' then 'build' else tab
viewClass = if name in ['builds', 'branches', 'pull_requests']
Travis.BuildsView
else
Travis["#{$.camelize(name)}View"]
@set('tab', tab)
urlGithub: (->
Travis.Urls.githubRepo(@get('repo.slug'))
).property('repo.slug')