Completely get rid of params
In the old router params were fetched from url, new router needs to instantiate objects anyway, so we can just set objects on controller instead of passing params.
This commit is contained in:
parent
57ae258803
commit
cd6636bfc5
|
@ -1,6 +1,5 @@
|
|||
Travis.RepositoryController = Travis.Controller.extend
|
||||
bindings: []
|
||||
params: {}
|
||||
|
||||
init: ->
|
||||
@_super.apply this, arguments
|
||||
|
@ -16,55 +15,37 @@ Travis.RepositoryController = Travis.Controller.extend
|
|||
|
||||
Ember.run.later(@updateTimes.bind(this), Travis.INTERVALS.updateTimes)
|
||||
|
||||
activate: (action, params) ->
|
||||
activate: (action) ->
|
||||
@_unbind()
|
||||
@setParams(params)
|
||||
this["view#{$.camelize(action)}"]()
|
||||
|
||||
viewIndex: ->
|
||||
@_bind('repository', 'controllers.repositoriesController.firstObject')
|
||||
@_bind('build', 'repository.lastBuild')
|
||||
@connectTab('current')
|
||||
|
||||
viewCurrent: ->
|
||||
@connectTab('current')
|
||||
@_bind('repository', 'repositoriesByParams.firstObject')
|
||||
@_bind('build', 'repository.lastBuild')
|
||||
|
||||
viewBuilds: ->
|
||||
@connectTab('builds')
|
||||
@_bind('repository', 'repositoriesByParams.firstObject')
|
||||
@_bind('builds', 'repository.builds')
|
||||
|
||||
viewPullRequests: ->
|
||||
@connectTab('pull_requests')
|
||||
@_bind('repository', 'repositoriesByParams.firstObject')
|
||||
@_bind('builds', 'repository.pullRequests')
|
||||
|
||||
viewBranches: ->
|
||||
@connectTab('branches')
|
||||
@_bind('repository', 'repositoriesByParams.firstObject')
|
||||
@_bind('builds', 'repository.branches')
|
||||
|
||||
viewBuild: ->
|
||||
@_bind('repository', 'repositoriesByParams.firstObject')
|
||||
@_bind('build', 'params.build')
|
||||
@connectTab('build')
|
||||
|
||||
viewJob: ->
|
||||
@_bind('repository', 'repositoriesByParams.firstObject')
|
||||
@_bind('build', 'job.build')
|
||||
@_bind('job', 'jobById')
|
||||
@connectTab('job')
|
||||
|
||||
repositoriesByParams: (->
|
||||
Travis.Repository.bySlug("#{@get('params.owner')}/#{@get('params.name')}")
|
||||
).property('params.owner', 'params.name')
|
||||
|
||||
jobById: (->
|
||||
Travis.Job.find(id) if id = @get('params.id')
|
||||
).property('params.id')
|
||||
|
||||
repositoryObserver: (->
|
||||
repository = @get('repository')
|
||||
repository.select() if repository
|
||||
|
@ -80,10 +61,6 @@ Travis.RepositoryController = Travis.Controller.extend
|
|||
@set('tab', tab)
|
||||
@connectOutlet(outletName: 'pane', controller: this, viewClass: viewClass)
|
||||
|
||||
setParams: (params) ->
|
||||
# TODO if we just @set('params', params) it will update the repositoriesByParams property
|
||||
@set("params.#{key}", params[key]) for key, value of params
|
||||
|
||||
_bind: (to, from) ->
|
||||
@bindings.push Ember.oneWay(this, to, from)
|
||||
|
||||
|
|
|
@ -134,12 +134,7 @@ Travis.Router = Ember.Router.extend
|
|||
route: '/:owner/:name'
|
||||
|
||||
connectOutlets: (router, repository) ->
|
||||
params = { owner: repository.get('owner'), name: repository.get('name') }
|
||||
|
||||
# TODO: we can just pass objects instead of params now, I'm leaving this
|
||||
# to not have to rewrite too much, but it would be nice to fix this
|
||||
# later
|
||||
router.get('repositoryController').setParams(params)
|
||||
router.get('repositoryController').set 'repository', repository
|
||||
|
||||
deserialize: (router, params) ->
|
||||
slug = "#{params.owner}/#{params.name}"
|
||||
|
@ -178,7 +173,8 @@ Travis.Router = Ember.Router.extend
|
|||
show: Ember.Route.extend
|
||||
route: '/:build_id'
|
||||
connectOutlets: (router, build) ->
|
||||
router.get('repositoryController').activate 'build', build: build
|
||||
router.get('repositoryController').set 'build', build
|
||||
router.get('repositoryController').activate 'build'
|
||||
|
||||
deserialize: (router, params) ->
|
||||
# Something is wrong here. If I don't use deferred, id is not
|
||||
|
@ -211,7 +207,8 @@ Travis.Router = Ember.Router.extend
|
|||
job: Ember.Route.extend
|
||||
route: '/jobs/:job_id'
|
||||
connectOutlets: (router, job) ->
|
||||
router.get('repositoryController').activate 'job', id: job.get('id')
|
||||
router.get('repositoryController').set 'job', job
|
||||
router.get('repositoryController').activate 'job'
|
||||
|
||||
deserialize: (router, params) ->
|
||||
job = Travis.Job.find params.job_id
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user