Move settings out of the profile page

This commit is contained in:
Piotr Sarnacki 2013-12-11 13:34:06 +01:00
parent ac6b394ec4
commit 8482c4c286
6 changed files with 22 additions and 25 deletions

View File

@ -48,18 +48,16 @@ Travis.FirstSyncController = Em.Controller.extend
isSyncing: Ember.computed.alias('user.isSyncing')
Travis.ProfileRepoController = Em.ObjectController.extend()
Travis.ProfileRepoSettingsTabController = Em.ObjectController.extend()
Travis.ProfileRepoSettingsController = Em.Controller.extend
needs: ['profileRepoSettingsTab', 'profileRepo']
tab: Ember.computed.alias('controllers.profileRepoSettingsTab.model.tab')
repo: Ember.computed.alias('controllers.profileRepo.content')
Travis.RepoSettingsTabController = Em.ObjectController.extend()
Travis.RepoSettingsController = Em.ObjectController.extend
needs: ['repoSettingsTab']
tab: Ember.computed.alias('controllers.repoSettingsTab.model.tab')
settings: Ember.computed.alias('model.settings')
submit: ->
@set('saving', true)
self = this
@get('repo').saveSettings(@get('settings')).then ->
@get('model').saveSettings(@get('settings')).then ->
self.set('saving', false)
Travis.flash(success: 'Settings were saved successfully')
, ->

View File

@ -34,11 +34,12 @@ Travis.TabsView = Ember.View.extend
tab.show() unless tab.get('visible')
# TODO: remove hardcoded link
layout: Ember.Handlebars.compile(
'<ul class="tabs">' +
' {{#each tab in tabs}}' +
' <li {{bindAttr class="tab.visible:active"}}>' +
' <h5>{{#linkTo "profile.repo.settings.tab" tab.id}}{{tab.name}}{{/linkTo}}</h5>' +
' <h5>{{#linkTo "repo.settings.tab" tab.id}}{{tab.name}}{{/linkTo}}</h5>' +
' </li>' +
' {{/each}}' +
'</ul>' +

View File

@ -99,16 +99,17 @@ Travis.Router.map ->
@resource 'pullRequests', path: '/pull_requests'
@resource 'branches', path: '/branches'
# this can't be nested in repo, because we want a set of different
# templates rendered for settings (for example no "current", "builds", ... tabs)
@resource 'repo.settings', path: '/:owner/:name/settings', ->
@route 'tab', path: ':tab'
@route 'getting_started'
@route 'first_sync'
@route 'stats', path: '/stats'
@route 'auth', path: '/auth'
@route 'notFound', path: '/not-found'
@resource 'profile.repo', path: '/profile/:owner/:name', ->
@resource 'profile.repo.settings', path: 'settings', ->
@route 'tab', path: ':tab'
@resource 'profile', path: '/profile', ->
@route 'index', path: '/'
@resource 'account', path: '/:login', ->
@ -398,15 +399,13 @@ Travis.AuthRoute = Ember.Route.extend
deactivate: ->
@controllerFor('auth').set('redirected', false)
Travis.ProfileRepoRoute = Travis.ProfileRoute.extend
Travis.RepoSettingsRoute = Ember.Route.extend
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
@_super(controller, model)
controller.set('content', model)
serialize: (repo) ->
slug = if repo.get then repo.get('slug') else repo.slug
[owner, name] = slug.split('/')
@ -416,10 +415,8 @@ Travis.ProfileRepoRoute = Travis.ProfileRoute.extend
slug = "#{params.owner}/#{params.name}"
Travis.Repo.fetchBySlug(slug)
Travis.ProfileRepoSettingsRoute = Ember.Route.extend
setupController: (controller, model) ->
controller.set('settings', model)
model: ->
repo = @modelFor('profileRepo')
repo.fetchSettings()
afterModel: (repo) ->
# I'm using afterModel to fetch settings, because model is not always called.
# If link-to already provides a model, it will be just set as a route context.
repo.fetchSettings().then (settings) ->
repo.set('settings', settings)

View File

@ -1,3 +1,5 @@
<h1>Settings: {{slug}}</h1>
{{#travis-tabs}}
{{#travis-tab "general" "General Settings"}}
{{#settings-form}}

View File

@ -24,4 +24,3 @@
{{/if}}
{{/if}}
</div>

View File

@ -13,7 +13,7 @@
{{/if}}
{{#if view.displaySettingsLink}}
<li>
{{#linkTo "profile.repo.settings" view.repo}}Settings{{/linkTo}}
{{#linkTo "repo.settings" view.repo}}Settings{{/linkTo}}
</li>
{{/if}}