
We observe last build on the repo in order to show the freshest build on repo page. I moved it to router in order to keep such observers in the same place, but this was not a wise move. To make it work properly observer needs to be removed when moving to some other part (like build's page). The problem is that deactivate function is not called when we move to the other route in the same nesting. We have our own 'activate' function on repoController, which is better suited for handling this task.
72 lines
1.8 KiB
CoffeeScript
72 lines
1.8 KiB
CoffeeScript
Travis.RepoController = Travis.Controller.extend
|
|
needs: ['repos', 'currentUser', 'build']
|
|
currentUserBinding: 'controllers.currentUser'
|
|
|
|
build: Ember.computed.alias('controllers.build.build')
|
|
|
|
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: ->
|
|
Ember.run this, ->
|
|
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) ->
|
|
@stopObservingLastBuild()
|
|
this["view#{$.camelize(action)}"]()
|
|
|
|
viewIndex: ->
|
|
@observeLastBuild()
|
|
@connectTab('current')
|
|
|
|
viewCurrent: ->
|
|
@observeLastBuild()
|
|
@connectTab('current')
|
|
|
|
viewBuilds: ->
|
|
@connectTab('builds')
|
|
|
|
viewPullRequests: ->
|
|
@connectTab('pull_requests')
|
|
|
|
viewBranches: ->
|
|
@connectTab('branches')
|
|
|
|
viewBuild: ->
|
|
@connectTab('build')
|
|
|
|
viewJob: ->
|
|
@connectTab('job')
|
|
|
|
lastBuildDidChange: ->
|
|
build = @get('repo.lastBuild')
|
|
@controllerFor('build').set('build', build)
|
|
|
|
stopObservingLastBuild: ->
|
|
@removeObserver('repo.lastBuild', this, 'lastBuildDidChange')
|
|
|
|
observeLastBuild: ->
|
|
@lastBuildDidChange()
|
|
@addObserver('repo.lastBuild', this, 'lastBuildDidChange')
|
|
|
|
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
|
|
@set('tab', tab)
|
|
|
|
urlGithub: (->
|
|
Travis.Urls.githubRepo(@get('repo.slug'))
|
|
).property('repo.slug')
|