Extract routes to individual files

This commit is contained in:
Piotr Sarnacki 2015-01-14 15:59:33 +01:00
parent 8715087237
commit 1ab14e9188
37 changed files with 635 additions and 407 deletions

View File

@ -40,7 +40,7 @@ Travis.FirstSyncController = Em.Controller.extend
isSyncing: Ember.computed.alias('user.isSyncing')
Travis.IndexErrorController = Em.Controller.extend()
Travis.MainErrorController = Em.Controller.extend()
Travis.BuildsItemController = Em.ObjectController.extend(Travis.GithubUrlProperties,
needs: ['builds']
isPullRequestsListBinding: 'controllers.builds.isPullRequestsList'

View File

@ -44,408 +44,39 @@ Travis.Router.map ->
@route 'notFound', path: "/*path"
Travis.RequestsRoute = Travis.Route.extend
needsAuth: true
setupController: ->
@_super.apply this, arguments
@controllerFor('repo').activate('requests')
model: ->
Travis.Request.fetch repository_id: @modelFor('repo').get('id')
Travis.CachesRoute = Travis.Route.extend
needsAuth: true
setupController: ->
@_super.apply this, arguments
@controllerFor('repo').activate('caches')
model: ->
repo = @modelFor('repo')
Travis.ajax.get("/repos/#{repo.get('id')}/caches").then( (data) ->
groups = {}
data["caches"].forEach (cacheData) ->
branch = cacheData["branch"]
group = groups[branch]
unless group
group = groups[branch] = Ember.Object.create(branch: branch, caches: [])
cache = Ember.Object.create(cacheData)
cache.set('parent', group)
group.get('caches').pushObject(cache)
result = []
for branch, caches of groups
result.push caches
result
)
Travis.RequestRoute = Travis.Route.extend
setupController: ->
@_super.apply this, arguments
@controllerFor('repo').activate('request')
model: (params) ->
Travis.Request.fetch params.request_id
Travis.GettingStartedRoute = Travis.Route.extend
renderTemplate: ->
@render('no_owned_repos')
Travis.SimpleLayoutRoute = Travis.Route.extend
setupController: ->
$('body').attr('id', 'home')
toActivate = if @signedIn() then 'owned' else 'recent'
@container.lookup('controller:repos').activate(toActivate)
@_super.apply(this, arguments)
renderTemplate: ->
@_super.apply(this, arguments)
Travis.FirstSyncRoute = Travis.SimpleLayoutRoute.extend
actions:
redirectToGettingStarted: ->
# do nothing, we are showing first sync, so it's normal that there is
# no owned repos
Travis.InsufficientOauthPermissionsRoute = Travis.SimpleLayoutRoute.extend
setupController: (controller) ->
@_super.apply this, arguments
existingUser = document.location.hash.match(/#existing[_-]user/)
controller.set('existingUser', existingUser)
Travis.MainTabRoute = Travis.Route.extend
renderTemplate: ->
@render 'repo'
@render 'build', into: 'repo'
setupController: ->
@_super.apply this, arguments
@controllerFor('repo').activate('index')
@controllerFor('repos').activate(@get('reposTabName'))
@currentRepoDidChange()
@controllerFor('repos').addObserver('firstObject', this, 'currentRepoDidChange')
deactivate: ->
@controllerFor('repos').removeObserver('firstObject', this, 'currentRepoDidChange')
currentRepoDidChange: ->
if repo = @controllerFor('repos').get('firstObject')
@controllerFor('repo').set('repo', repo)
actions:
redirectToGettingStarted: ->
@transitionTo('getting_started')
Travis.MainMyRepositoriesRoute = Travis.Route.extend
redirect: ->
@transitionTo("main.repositories")
Travis.MainRepositoriesRoute = Travis.MainTabRoute.extend
needsAuth: true
reposTabName: 'owned'
afterModel: ->
@controllerFor('repos').possiblyRedirectToGettingStartedPage()
Travis.MainRecentRoute = Travis.MainTabRoute.extend
reposTabName: 'recent'
Travis.MainSearchRoute = Travis.MainTabRoute.extend
renderTemplate: ->
@render 'repo'
@render 'build', into: 'repo'
setupController: (controller, searchPhrase) ->
# TODO: this method is almost the same as _super, refactor this
@controllerFor('repo').activate('index')
@controllerFor('repos').activate('search', searchPhrase)
@currentRepoDidChange()
@controllerFor('repos').addObserver('firstObject', this, 'currentRepoDidChange')
model: (params) ->
params.phrase
deactivate: ->
@_super.apply(this, arguments)
@controllerFor('repos').set('search', undefined)
Travis.AbstractBuildsRoute = Travis.Route.extend
renderTemplate: ->
@render 'builds'
setupController: ->
@controllerFor('repo').activate(@get('contentType'))
@contentDidChange()
@controllerFor('repo').addObserver(@get('path'), this, 'contentDidChange')
deactivate: ->
@controllerFor('repo').removeObserver(@get('path'), this, 'contentDidChange')
contentDidChange: ->
path = @get('path')
@controllerFor('builds').set('model', @controllerFor('repo').get(path))
path: (->
type = @get('contentType')
"repo.#{type.camelize()}"
).property('contentType')
Travis.BuildsRoute = Travis.AbstractBuildsRoute.extend(contentType: 'builds')
Travis.BranchesRoute = Travis.AbstractBuildsRoute.extend(contentType: 'branches')
Travis.PullRequestsRoute = Travis.AbstractBuildsRoute.extend(
contentType: 'pull_requests'
# TODO: it would be better to have separate controller for branches and PRs list
setupController: (controller, model) ->
@_super(controller, model)
this.controllerFor('builds').set('isPullRequestsList', true)
deactivate: ->
this.controllerFor('builds').set('isPullRequestsList', false)
)
Travis.BuildRoute = Travis.Route.extend
serialize: (model, params) ->
id = if model.get then model.get('id') else model
{ build_id: id }
setupController: (controller, model) ->
model = Travis.Build.find(model) if model && !model.get
repo = @controllerFor('repo')
#repo.set('build', model)
@controllerFor('build').set('build', model)
repo.activate('build')
#repo.set('build', model)
model: (params) ->
Travis.Build.fetch(params.build_id)
deactivate: ->
@controllerFor('job').set('job', null)
@controllerFor('build').set('build', null)
Travis.JobRoute = Travis.Route.extend
serialize: (model, params) ->
id = if model.get then model.get('id') else model
{ job_id: id }
setupController: (controller, model) ->
model = Travis.Job.find(model) if model && !model.get
repo = @controllerFor('repo')
@controllerFor('job').set('job', model)
repo.activate('job')
if build = model.get('build')
@controllerFor('build').set('build', build)
model: (params) ->
Travis.Job.fetch(params.job_id)
deactivate: ->
@controllerFor('build').set('build', null)
@controllerFor('job').set('job', null)
Travis.RepoIndexRoute = Travis.Route.extend
setupController: (controller, model) ->
@_super.apply this, arguments
@controllerFor('repo').activate('current')
renderTemplate: ->
if @modelFor('repo').get('lastBuildId')
@render 'build'
else
@render 'builds/not_found'
deactivate: ->
repo = @controllerFor('repo')
@controllerFor('build').set('build', null)
@controllerFor('job').set('job', null)
Travis.RepoRoute = Travis.Route.extend
renderTemplate: ->
@render 'repo', into: 'main'
setupController: (controller, model) ->
# TODO: if repo is just a data hash with id and slug load it
# as incomplete record
model = Travis.Repo.find(model.id) if model && !model.get
controller.set('repo', model)
serialize: (repo) ->
slug = if repo.get then repo.get('slug') else repo.slug
[owner, name] = slug.split('/')
{ owner: owner, name: name }
model: (params) ->
slug = "#{params.owner}/#{params.name}"
Travis.Repo.fetchBySlug(slug)
resetController: ->
@controllerFor('repo').deactivate()
actions:
error: (error) ->
# if error throwed has a slug (ie. it was probably repo not found)
# set the slug on main.error controller to allow to properly
# display the repo information
if error.slug
this.controllerFor('main.error').set('slug', error.slug)
# bubble to the top
return true
Travis.MainIndexRoute = Travis.Route.extend
redirect: ->
target = if @signedIn() then 'repositories' else 'recent'
@transitionTo("main.#{target}")
Travis.MainRoute = Travis.Route.extend
renderTemplate: ->
$('body').attr('id', 'home')
@_super.apply this, arguments
@render 'repos', outlet: 'left', into: 'main'
setupController: (controller)->
# TODO: this is redundant with repositories and recent routes
toActivate = if @signedIn() then 'owned' else 'recent'
@container.lookup('controller:repos').activate(toActivate)
Travis.StatsRoute = Travis.Route.extend
renderTemplate: ->
$('body').attr('id', 'stats')
@render 'stats'
Travis.NotFoundRoute = Travis.Route.extend
renderTemplate: ->
$('body').attr('id', 'not-found')
@render 'not_found'
Travis.ProfileRoute = Travis.Route.extend
needsAuth: true
setupController: (controller, model) ->
@controllerFor('accounts').set('model', model)
renderTemplate: ->
$('body').attr('id', 'profile')
@_super.apply(this, arguments)
@render 'loading', outlet: 'left', into: 'profile'
Travis.AccountsRoute = Travis.Route.extend
model: ->
Travis.Account.fetch(all: true)
renderTemplate: ->
@_super.apply(this, arguments)
@render 'profile_accounts', outlet: 'left', into: 'profile'
Travis.AccountsIndexRoute = Travis.Route.extend
redirect: ->
# TODO: setting accounts model in ProfileRoute is wrong, but
# at this stage it's better than what we had before
accounts = @modelFor('accounts')
login = @controllerFor('currentUser').get('login')
account = accounts.find (account) -> account.get('login') == login
@replaceWith 'account', account
Travis.AccountRoute = Travis.Route.extend
setupController: (controller, account) ->
@_super.apply this, arguments
@controllerFor('profile').activate 'hooks'
model: (params) ->
@modelFor('accounts').find (account) -> account.get('login') == params.login
serialize: (account) ->
if account && account.get
{ login: account.get('login') }
else
{}
Travis.AccountsInfoRoute = Travis.Route.extend
setupController: ->
user = @controllerFor('currentUser').get('model')
@controllerFor('account').set('model', user)
@controllerFor('profile').activate 'user'
renderTemplate: ->
@render 'accounts_info'
Travis.AuthRoute = Travis.Route.extend
needsAuth: false
renderTemplate: ->
$('body').attr('id', 'auth')
@render 'auth.signin'
deactivate: ->
@controllerFor('auth').set('redirected', false)
actions:
afterSignIn: ->
@transitionTo('index')
return true
redirect: ->
if @signedIn()
@transitionTo('index')
Travis.SettingsRoute = Travis.Route.extend
needsAuth: true
setupController: (controller, model) ->
@controllerFor('repo').activate('settings')
Travis.SettingsIndexRoute = Travis.Route.extend
model: ->
repo = @modelFor('repo')
repo.fetchSettings().then (settings) ->
repo.set('settings', settings)
Travis.EnvVarsRoute = Travis.Route.extend
model: (params) ->
repo = @modelFor('repo')
repo.get('envVars.promise')
Travis.SshKeyRoute = Travis.Route.extend
model: (params) ->
repo = @modelFor('repo')
self = this
Travis.SshKey.fetch(repo.get('id')).then ( (result) -> result unless result.get('isNew') ), (xhr) ->
if xhr.status == 404
# if there is no model, just return null. I'm not sure if this is the
# best answer, maybe we should just redirect to different route, like
# ssh_key.new or ssh_key.no_key
return null
afterModel: (model, transition) ->
repo = @modelFor('repo')
Travis.ajax.get "/repositories/#{repo.get('id')}/key", (data) =>
@defaultKey = Ember.Object.create(fingerprint: data.fingerprint)
setupController: (controller, model) ->
controller.reset()
@_super.apply this, arguments
if @defaultKey
controller.set('defaultKey', @defaultKey)
@defaultKey = null
deactivate: ->
@_super.apply(this, arguments)
@controllerFor('ssh_key').send('cancel')
require 'routes/abstract_builds'
require 'routes/account'
require 'routes/accounts/index'
require 'routes/accounts/info'
require 'routes/accounts'
require 'routes/application'
require 'routes/auth'
require 'routes/branches'
require 'routes/build'
require 'routes/builds'
require 'routes/caches'
require 'routes/env_vars'
require 'routes/first_sync'
require 'routes/getting_started'
require 'routes/insufficient_oauth_permissions'
require 'routes/job'
require 'routes/main/index'
require 'routes/main/my_repositories'
require 'routes/main/recent'
require 'routes/main/repositories'
require 'routes/main/search'
require 'routes/main'
require 'routes/main_tab'
require 'routes/not_found'
require 'routes/profile'
require 'routes/pull_requests'
require 'routes/repo/index'
require 'routes/repo'
require 'routes/request'
require 'routes/requests'
require 'routes/route'
require 'routes/settings/index'
require 'routes/settings'
require 'routes/simple_layout'
require 'routes/ssh_key'
require 'routes/stats'

View File

@ -0,0 +1,26 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
renderTemplate: ->
@render 'builds'
setupController: ->
@controllerFor('repo').activate(@get('contentType'))
@contentDidChange()
@controllerFor('repo').addObserver(@get('path'), this, 'contentDidChange')
deactivate: ->
@controllerFor('repo').removeObserver(@get('path'), this, 'contentDidChange')
contentDidChange: ->
path = @get('path')
@controllerFor('builds').set('model', @controllerFor('repo').get(path))
path: (->
type = @get('contentType')
"repo.#{type.camelize()}"
).property('contentType')
Travis.AbstractBuildsRoute = Route

View File

@ -0,0 +1,20 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
setupController: (controller, account) ->
@_super.apply this, arguments
@controllerFor('profile').activate 'hooks'
model: (params) ->
@modelFor('accounts').find (account) -> account.get('login') == params.login
serialize: (account) ->
if account && account.get
{ login: account.get('login') }
else
{}
Travis.AccountRoute = Route

View File

@ -0,0 +1,15 @@
require 'routes/route'
Account = Travis.Account
TravisRoute = Travis.Route
Route = TravisRoute.extend
model: ->
Account.fetch(all: true)
renderTemplate: ->
@_super.apply(this, arguments)
@render 'profile_accounts', outlet: 'left', into: 'profile'
Travis.AccountsRoute = Route

View File

@ -0,0 +1,15 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
redirect: ->
# TODO: setting accounts model in ProfileRoute is wrong, but
# at this stage it's better than what we had before
accounts = @modelFor('accounts')
login = @controllerFor('currentUser').get('login')
account = accounts.find (account) -> account.get('login') == login
@replaceWith 'account', account
Travis.AccountsIndexRoute = Route

View File

@ -0,0 +1,14 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
setupController: ->
user = @controllerFor('currentUser').get('model')
@controllerFor('account').set('model', user)
@controllerFor('profile').activate 'user'
renderTemplate: ->
@render 'accounts_info'
Travis.AccountsInfoRoute = Route

View File

@ -1,6 +1,6 @@
require 'routes/route'
TravisRoute = Travis.Route
TravisRoute = TravisRoute
Route = TravisRoute.extend
needsAuth: false

View File

@ -0,0 +1,25 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
needsAuth: false
renderTemplate: ->
$('body').attr('id', 'auth')
@render 'auth.signin'
deactivate: ->
@controllerFor('auth').set('redirected', false)
actions:
afterSignIn: ->
@transitionTo('index')
return true
redirect: ->
if @signedIn()
@transitionTo('index')
Travis.AuthRoute = Route

View File

@ -0,0 +1,7 @@
require 'routes/route'
AbstractBuildsRoute = Travis.AbstractBuildsRoute
Route = AbstractBuildsRoute.extend(contentType: 'branches')
Travis.BranchesRoute = Route

View File

@ -0,0 +1,28 @@
require 'routes/route'
Build = Travis.Build
TravisRoute = Travis.Route
Route = TravisRoute.extend
serialize: (model, params) ->
id = if model.get then model.get('id') else model
{ build_id: id }
setupController: (controller, model) ->
model = Build.find(model) if model && !model.get
repo = @controllerFor('repo')
#repo.set('build', model)
@controllerFor('build').set('build', model)
repo.activate('build')
#repo.set('build', model)
model: (params) ->
Build.fetch(params.build_id)
deactivate: ->
@controllerFor('job').set('job', null)
@controllerFor('build').set('build', null)
Travis.BuildRoute = Route

View File

@ -0,0 +1,7 @@
require 'routes/route'
AbstractBuildsRoute = Travis.AbstractBuildsRoute
Route = AbstractBuildsRoute.extend(contentType: 'builds')
Travis.BuildsRoute = Route

View File

@ -0,0 +1,33 @@
require 'routes/route'
Request = Travis.Request
Ajax = Travis.ajax
TravisRoute = Travis.Route
Route = TravisRoute.extend
needsAuth: true
setupController: ->
@_super.apply this, arguments
@controllerFor('repo').activate('caches')
model: ->
repo = @modelFor('repo')
Ajax.get("/repos/#{repo.get('id')}/caches").then( (data) ->
groups = {}
data["caches"].forEach (cacheData) ->
branch = cacheData["branch"]
group = groups[branch]
unless group
group = groups[branch] = Ember.Object.create(branch: branch, caches: [])
cache = Ember.Object.create(cacheData)
cache.set('parent', group)
group.get('caches').pushObject(cache)
result = []
for branch, caches of groups
result.push caches
result
)
Travis.CachesRoute = Route

View File

@ -0,0 +1,10 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
model: (params) ->
repo = @modelFor('repo')
repo.get('envVars.promise')
Travis.EnvVarsRoute = Route

View File

@ -0,0 +1,12 @@
require 'routes/route'
require 'routes/simple_layout'
SimpleLayoutRoute = Travis.SimpleLayoutRoute
Route = SimpleLayoutRoute.extend
actions:
redirectToGettingStarted: ->
# do nothing, we are showing first sync, so it's normal that there is
# no owned repos
Travis.FirstSyncRoute = Route

View File

@ -0,0 +1,9 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
renderTemplate: ->
@render('no_owned_repos')
Travis.GettingStartedRoute = Route

View File

@ -0,0 +1,12 @@
require 'routes/route'
require 'routes/simple_layout'
SimpleLayoutRoute = Travis.SimpleLayoutRoute
Route = SimpleLayoutRoute.extend
setupController: (controller) ->
@_super.apply this, arguments
existingUser = document.location.hash.match(/#existing[_-]user/)
controller.set('existingUser', existingUser)
Travis.InsufficientOauthPermissionsRoute = Route

View File

@ -0,0 +1,29 @@
require 'routes/route'
Job = Travis.Job
TravisRoute = Travis.Route
Route = TravisRoute.extend
serialize: (model, params) ->
id = if model.get then model.get('id') else model
{ job_id: id }
setupController: (controller, model) ->
model = Job.find(model) if model && !model.get
repo = @controllerFor('repo')
@controllerFor('job').set('job', model)
repo.activate('job')
if build = model.get('build')
@controllerFor('build').set('build', build)
model: (params) ->
Job.fetch(params.job_id)
deactivate: ->
@controllerFor('build').set('build', null)
@controllerFor('job').set('job', null)
Travis.JobRoute = Route

View File

@ -0,0 +1,19 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
renderTemplate: ->
$('body').attr('id', 'home')
@_super.apply this, arguments
@render 'repos', outlet: 'left', into: 'main'
setupController: (controller)->
# TODO: this is redundant with repositories and recent routes
toActivate = if @signedIn() then 'owned' else 'recent'
@container.lookup('controller:repos').activate(toActivate)
Travis.MainRoute = Route

View File

@ -0,0 +1,10 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
redirect: ->
target = if @signedIn() then 'repositories' else 'recent'
@transitionTo("main.#{target}")
Travis.MainIndexRoute = Route

View File

@ -0,0 +1,9 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
redirect: ->
@transitionTo("main.repositories")
Travis.MainMyRepositoriesRoute = Route

View File

@ -0,0 +1,9 @@
require 'routes/route'
require 'routes/main_tab'
MainTabRoute = Travis.MainTabRoute
Route = MainTabRoute.extend
reposTabName: 'recent'
Travis.MainRecentRoute = Route

View File

@ -0,0 +1,12 @@
require 'routes/route'
require 'routes/main_tab'
MainTabRoute = Travis.MainTabRoute
Route = MainTabRoute.extend
needsAuth: true
reposTabName: 'owned'
afterModel: ->
@controllerFor('repos').possiblyRedirectToGettingStartedPage()
Travis.MainRepositoriesRoute = Route

View File

@ -0,0 +1,27 @@
require 'routes/route'
require 'routes/main_tab'
MainTabRoute = Travis.MainTabRoute
Route = MainTabRoute.extend
renderTemplate: ->
@render 'repo'
@render 'build', into: 'repo'
setupController: (controller, searchPhrase) ->
# TODO: this method is almost the same as _super, refactor this
@controllerFor('repo').activate('index')
@controllerFor('repos').activate('search', searchPhrase)
@currentRepoDidChange()
@controllerFor('repos').addObserver('firstObject', this, 'currentRepoDidChange')
model: (params) ->
params.phrase
deactivate: ->
@_super.apply(this, arguments)
@controllerFor('repos').set('search', undefined)
Travis.MainSearchRoute = Route

View File

@ -0,0 +1,30 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
renderTemplate: ->
@render 'repo'
@render 'build', into: 'repo'
setupController: ->
@_super.apply this, arguments
@controllerFor('repo').activate('index')
@controllerFor('repos').activate(@get('reposTabName'))
@currentRepoDidChange()
@controllerFor('repos').addObserver('firstObject', this, 'currentRepoDidChange')
deactivate: ->
@controllerFor('repos').removeObserver('firstObject', this, 'currentRepoDidChange')
currentRepoDidChange: ->
if repo = @controllerFor('repos').get('firstObject')
@controllerFor('repo').set('repo', repo)
actions:
redirectToGettingStarted: ->
@transitionTo('getting_started')
Travis.MainTabRoute = Route

View File

@ -0,0 +1,11 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
renderTemplate: ->
$('body').attr('id', 'not-found')
@render 'not_found'
Travis.NotFoundRoute = Route

View File

@ -0,0 +1,16 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
needsAuth: true
setupController: (controller, model) ->
@controllerFor('accounts').set('model', model)
renderTemplate: ->
$('body').attr('id', 'profile')
@_super.apply(this, arguments)
@render 'loading', outlet: 'left', into: 'profile'
Travis.ProfileRoute = Route

View File

@ -0,0 +1,18 @@
require 'routes/route'
AbstractBuildsRoute = Travis.AbstractBuildsRoute
Route = AbstractBuildsRoute.extend(
contentType: 'pull_requests'
# TODO: it would be better to have separate controller for branches and PRs list
setupController: (controller, model) ->
@_super(controller, model)
this.controllerFor('builds').set('isPullRequestsList', true)
deactivate: ->
this.controllerFor('builds').set('isPullRequestsList', false)
)
Travis.PullRequestsRoute = Route

View File

@ -0,0 +1,40 @@
require 'routes/route'
require 'models/repo'
Repo = Travis.Repo
TravisRoute = Travis.Route
Route = TravisRoute.extend
renderTemplate: ->
@render 'repo', into: 'main'
setupController: (controller, model) ->
# TODO: if repo is just a data hash with id and slug load it
# as incomplete record
model = Repo.find(model.id) if model && !model.get
controller.set('repo', model)
serialize: (repo) ->
slug = if repo.get then repo.get('slug') else repo.slug
[owner, name] = slug.split('/')
{ owner: owner, name: name }
model: (params) ->
slug = "#{params.owner}/#{params.name}"
Repo.fetchBySlug(slug)
resetController: ->
@controllerFor('repo').deactivate()
actions:
error: (error) ->
# if error throwed has a slug (ie. it was probably repo not found)
# set the slug on main.error controller to allow to properly
# display the repo information
if error.slug
this.controllerFor('main.error').set('slug', error.slug)
# bubble to the top
return true
Travis.RepoRoute = Route

View File

@ -0,0 +1,21 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
setupController: (controller, model) ->
@_super.apply this, arguments
@controllerFor('repo').activate('current')
renderTemplate: ->
if @modelFor('repo').get('lastBuildId')
@render 'build'
else
@render 'builds/not_found'
deactivate: ->
repo = @controllerFor('repo')
@controllerFor('build').set('build', null)
@controllerFor('job').set('job', null)
Travis.RepoIndexRoute = Route

View File

@ -0,0 +1,14 @@
require 'routes/route'
Request = Travis.Request
TravisRoute = Travis.Route
Route = TravisRoute.extend
setupController: ->
@_super.apply this, arguments
@controllerFor('repo').activate('request')
model: (params) ->
Request.fetch params.request_id
Travis.RequestRoute = Route

View File

@ -0,0 +1,15 @@
require 'routes/route'
TravisRoute = Travis.Route
Request = Travis.Request
Route = TravisRoute.extend
needsAuth: true
setupController: ->
@_super.apply this, arguments
@controllerFor('repo').activate('requests')
model: ->
Request.fetch repository_id: @modelFor('repo').get('id')
Travis.RequestRoute = Route

View File

@ -0,0 +1,10 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
needsAuth: true
setupController: (controller, model) ->
@controllerFor('repo').activate('settings')
Travis.SettingsRoute = Route

View File

@ -0,0 +1,11 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
model: ->
repo = @modelFor('repo')
repo.fetchSettings().then (settings) ->
repo.set('settings', settings)
Travis.SettingsIndexRoute = Route

View File

@ -0,0 +1,15 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
setupController: ->
$('body').attr('id', 'home')
toActivate = if @signedIn() then 'owned' else 'recent'
@container.lookup('controller:repos').activate(toActivate)
@_super.apply(this, arguments)
renderTemplate: ->
@_super.apply(this, arguments)
Travis.SimpleLayoutRoute = Route

View File

@ -0,0 +1,36 @@
require 'routes/route'
SshKey = Travis.SshKey
Ajax = Travis.ajax
TravisRoute = Travis.Route
Route = TravisRoute.extend
model: (params) ->
repo = @modelFor('repo')
self = this
SshKey.fetch(repo.get('id')).then ( (result) -> result unless result.get('isNew') ), (xhr) ->
if xhr.status == 404
# if there is no model, just return null. I'm not sure if this is the
# best answer, maybe we should just redirect to different route, like
# ssh_key.new or ssh_key.no_key
return null
afterModel: (model, transition) ->
repo = @modelFor('repo')
Ajax.get "/repositories/#{repo.get('id')}/key", (data) =>
@defaultKey = Ember.Object.create(fingerprint: data.fingerprint)
setupController: (controller, model) ->
controller.reset()
@_super.apply this, arguments
if @defaultKey
controller.set('defaultKey', @defaultKey)
@defaultKey = null
deactivate: ->
@_super.apply(this, arguments)
@controllerFor('ssh_key').send('cancel')
Travis.SshKeyRoute = Route

View File

@ -0,0 +1,12 @@
require 'routes/route'
TravisRoute = Travis.Route
Route = TravisRoute.extend
renderTemplate: ->
$('body').attr('id', 'stats')
@render 'stats'
Travis.StatsRoute = Route