un-dry router in order to figure out whats wrong with url generation

This commit is contained in:
Sven Fuchs 2012-06-22 12:38:47 +02:00
parent 23d74a53a7
commit 2437f79845
7 changed files with 99 additions and 136 deletions

View File

@ -17,8 +17,8 @@ Travis.store = DS.Store.extend(
).create()
# apparently fixtures behave weird unless preloaded :/ should move to mockjax for testing
Travis.Build.find()
Travis.Repository.find()
Travis.Build.find()
Travis.Commit.find()
Travis.Job.find()
Travis.Artifact.find()

View File

@ -54,10 +54,10 @@ require 'travis/model'
Travis.store.findMany this, ids
@Travis.Job.FIXTURES = [
{ id: 1, repository_id: 1, build_id: 1, log_id: 1, number: '1.1', config: { rvm: 'rbx' }, finished_at: '2012-06-20T00:21:20Z', duration: 35, result: 0 }
{ id: 2, repository_id: 1, build_id: 1, log_id: 2, number: '1.2', config: { rvm: '1.9.3' } }
{ id: 3, repository_id: 1, build_id: 2, log_id: 3, number: '2.1' }
{ id: 4, repository_id: 2, build_id: 3, log_id: 4, number: '3.1' }
{ id: 5, repository_id: 3, build_id: 5, log_id: 5, number: '4.1' }
{ id: 1, repository_id: 1, build_id: 1, commit_id: 1, log_id: 1, number: '1.1', config: { rvm: 'rbx' }, finished_at: '2012-06-20T00:21:20Z', duration: 35, result: 0 }
{ id: 2, repository_id: 1, build_id: 1, commit_id: 1, log_id: 2, number: '1.2', config: { rvm: '1.9.3' } }
{ id: 3, repository_id: 1, build_id: 2, commit_id: 2, log_id: 3, number: '2.1' }
{ id: 4, repository_id: 2, build_id: 3, commit_id: 3, log_id: 4, number: '3.1' }
{ id: 5, repository_id: 3, build_id: 4, commit_id: 4, log_id: 5, number: '4.1' }
]

View File

@ -1,8 +1,7 @@
require 'travis/model'
@Travis.Repository = Travis.Model.extend
name: DS.attr('string')
owner: DS.attr('string')
slug: DS.attr('string')
description: DS.attr('string')
last_build_id: DS.attr('number')
last_build_number: DS.attr('string')
@ -10,6 +9,8 @@ require 'travis/model'
last_build_started_at: DS.attr('string')
last_build_finished_at: DS.attr('string')
primaryKey: 'slug'
lastBuild: DS.belongsTo('Travis.Build')
builds: (->
@ -20,8 +21,12 @@ require 'travis/model'
Travis.Build.byRepositoryId @get('id'), event_type: 'pull_request'
).property()
slug: (->
"#{@get('owner')}/#{@get('name')}"
owner: (->
(@get('slug') || '').split('/')[0]
).property('owner', 'name'),
name: (->
(@get('slug') || '').split('/')[1]
).property('owner', 'name'),
last_build_duration: (->
@ -63,9 +68,9 @@ require 'travis/model'
repository.set 'selected', repository.get('id') is id
@Travis.Repository.FIXTURES = [
{ id: 1, owner: 'travis-ci', name: 'travis-core', build_ids: [1, 2], last_build_id: 1, last_build_number: 1, last_build_result: 0 },
{ id: 2, owner: 'travis-ci', name: 'travis-assets', build_ids: [3] , last_build_id: 3, last_build_number: 3},
{ id: 3, owner: 'travis-ci', name: 'travis-hub', build_ids: [4] , last_build_id: 4, last_build_number: 4},
{ id: 1, owner: 'travis-ci', name: 'travis-core', slug: 'travis-ci/travis-core', build_ids: [1, 2], last_build_id: 1, last_build_number: 1, last_build_result: 0 },
{ id: 2, owner: 'travis-ci', name: 'travis-assets', slug: 'travis-ci/travis-assets', build_ids: [3], last_build_id: 3, last_build_number: 3},
{ id: 3, owner: 'travis-ci', name: 'travis-hub', slug: 'travis-ci/travis-hub', build_ids: [4], last_build_id: 4, last_build_number: 4},
]

View File

@ -5,68 +5,109 @@ require 'hax0rs'
location: 'hash'
root: Em.Route.extend
viewRepository: Ember.Route.transitionTo('current')
viewCurrent: Ember.Route.transitionTo('current')
viewBuilds: Ember.Route.transitionTo('builds')
viewBuild: Ember.Route.transitionTo('build')
viewJob: Ember.Route.transitionTo('job')
index: Em.Route.extend
route: '/'
connectOutlets: (router) ->
router.connectLayout {}, (repository) ->
router.connectCurrent repository.get('lastBuild')
viewCurrent: Ember.Route.transitionTo('current')
viewHistory: Ember.Route.transitionTo('history')
viewBuild: Ember.Route.transitionTo('build')
connectOutlets: (router) ->
repositories = Travis.Repository.find()
router.connectLeft(repositories)
onceLoaded repositories, =>
repository = repositories.get('firstObject')
router.connectRepository repository
router.connectTabs repository
router.connectCurrent repository.get('lastBuild')
current: Em.Route.extend
route: '/:owner/:name'
serialize: (router, repository) ->
router.serializeRepository repository
connectOutlets: (router, repository) ->
params = router.serializeRepository(repository)
router.connectLayout params, (repository) ->
builds = repository.get('builds')
onceLoaded builds, ->
router.connectCurrent builds.get('firstObject')
repositories = Travis.Repository.find()
router.connectLeft(repositories)
onceLoaded repository, =>
router.connectRepository repository
router.connectTabs repository
router.connectCurrent repository.get('lastBuild')
history: Em.Route.extend
builds: Em.Route.extend
route: '/:owner/:name/builds'
serialize: (router, repository) ->
router.serializeRepository repository
connectOutlets: (router, repository) ->
params = router.serializeRepository(repository)
router.connectLayout params, (repository) ->
builds = repository.get('builds')
onceLoaded builds, ->
router.connectHistory builds
repositories = Travis.Repository.find()
router.connectLeft(repositories)
onceLoaded repository, =>
router.connectRepository repository
router.connectTabs repository
router.connectBuilds repository.get('builds')
build: Em.Route.extend
route: '/:owner/:name/builds/:id'
serialize: (router, build) ->
router.serializeObject build
connectOutlets: (router, build) ->
params = router.serializeObject(build)
build = Travis.Build.find(params.id) unless build instanceof Travis.Build
router.connectLayout params, build, (repository, build) ->
repositories = Travis.Repository.find()
repository = build.get('repository')
router.connectLeft(repositories)
onceLoaded repository, =>
router.connectRepository repository
router.connectTabs repository, build
router.connectBuild build
job: Em.Route.extend
route: '/:owner/:name/jobs/:id'
serialize: (router, job) ->
router.serializeObject job
connectOutlets: (router, job) ->
params = router.serializeObject(job)
job = Travis.Job.find(params.id) unless build instanceof Travis.Job
repositories = Travis.Repository.find()
repository = job.get('repository')
build = job.get('build')
router.connectLayout params, build, job, (repository, job) ->
router.connectLeft(repositories)
onceLoaded repository, build, =>
router.connectRepository repository
router.connectTabs repository, build, job
router.connectJob job
viewCurrent: Ember.Route.transitionTo('current')
viewHistory: Ember.Route.transitionTo('history')
viewBuild: Ember.Route.transitionTo('build')
viewJob: Ember.Route.transitionTo('job')
connectLeft: (repositories) ->
@get('applicationController').connectOutlet outletName: 'left', name: 'repositories', context: repositories
connectRepository: (repository) ->
@get('applicationController').connectOutlet outletName: 'main', name: 'repository', context: repository
connectTabs: (repository, build, job) ->
@setPath 'tabsController.repository', repository
@setPath 'tabsController.build', build
@setPath 'tabsController.job', job
@get('repositoryController').connectOutlet outletName: 'tabs', name: 'tabs'
connectCurrent: (build) ->
@get('repositoryController').connectOutlet outletName: 'tab', name: 'current', context: build
connectBuilds: (builds) ->
@get('repositoryController').connectOutlet outletName: 'tab', name: 'history', context: builds
connectBuild: (build) ->
@get('repositoryController').connectOutlet outletName: 'tab', name: 'build', context: build
connectJob: (job) ->
@get('repositoryController').connectOutlet outletName: 'tab', name: 'job', context: job
serializeRepository: (repository) ->
if repository instanceof DS.Model
@ -82,84 +123,3 @@ require 'hax0rs'
id: object.get('id')
else
object or {}
connectLeft: (repositories) ->
@get('applicationController').connectOutlet
outletName: 'left'
name: 'repositories'
context: repositories
connectRight: ->
# ...
connectLoading: ->
@get('applicationController').connectOutlet
outletName: 'main'
name: 'loading'
connectLayout: (params, callback) ->
args = Array.prototype.slice.call(arguments, 1)
callback = args.pop()
build = args.shift()
job = args.shift()
repositories = Travis.Repository.find()
@connectLeft repositories
@connectMain repositories, params, build, job, callback
@connectRight()
connectMain: (repositories, params, build, job, callback) ->
@connectLoading()
if params.owner and params.name
# TODO this might be wrong for /:owner/:name ... when this repo is not contained
# in the current list of recent repositories
repositories = Travis.Repository.find().filter (data) ->
data.get('owner_name') is params.owner_name and data.get('name') is params.name
build = job.get('build') if job && !build
# build = (if params.id then Travis.Build.find(params.id) else `undefined`)
onceLoaded repositories, build, =>
repository = repositories.get('firstObject')
@connectRepository repository
@connectTabs repository, build, job
callback repository, build
connectRepository: (repository) ->
@get('applicationController').connectOutlet
outletName: 'main'
name: 'repository'
context: repository
connectTabs: (repository, build, job) ->
@setPath 'tabsController.repository', repository
@setPath 'tabsController.build', build
@setPath 'tabsController.job', job
@get('repositoryController').connectOutlet
outletName: 'tabs'
name: 'tabs'
connectCurrent: (build) ->
@get('repositoryController').connectOutlet
outletName: 'tab'
name: 'current'
context: build
connectHistory: (builds) ->
@get('repositoryController').connectOutlet
outletName: 'tab'
name: 'history'
context: builds
connectBuild: (build) ->
@get('repositoryController').connectOutlet
outletName: 'tab'
name: 'build'
context: build
connectJob: (job) ->
@get('repositoryController').connectOutlet
outletName: 'tab'
name: 'job'
context: job

View File

@ -1,8 +1,10 @@
{{#collection tagName="ul" id="repositories" contentBinding="content" itemViewClass="Travis.RepositoriesItemView" itemClassBinding="classes"}}
{{#with view.content}}
<div class="wrapper">
<a {{action viewCurrent href=true context="content"}} class="slug">{{slug}}</a>
<a {{action viewBuild href=true context="lastBuild"}} class="build">#{{last_build_number}}</a>
<ul>
{{#each content}}
<li>
<div class="wrapper">
<a {{action viewCurrent href=true}} class="slug">{{slug}}</a>
<a {{action viewBuild href=true context="lastBuild"}} class="build">#{{last_build_number}}</a>
</div>
<p class="summary">
<span class="duration_label">{{t repositories.duration}}:</span>
<abbr class="duration" {{bindAttr title="last_build_started_at"}}>{{formatDuration last_build_duration}}</abbr>,
@ -13,10 +15,6 @@
<p class="description">{{description}}</p>
{{/if}}
<span class="indicator"></span>
</div>
{{/with}}
{{/collection}}
{{^collection contentBinding="repositories" id="list" class="loading"}}
<p></p>
{{/collection}}
</li>
{{/each}}
<ul>

View File

@ -1,6 +1,6 @@
<ul class="tabs">
<li><a {{action viewCurrent href=true context="repository"}} class="current">Current</a></li>
<li><a {{action viewHistory href=true context="repository"}} class="history">History</a></li>
<li><a {{action viewBuilds href=true context="repository"}} class="history">History</a></li>
{{#if build}}
<li><a {{action viewBuild href=true context="build"}} class="build">Build #{{build.number}}</a></li>
{{/if}}

File diff suppressed because one or more lines are too long