First stab at ssh key form

This commit is contained in:
Piotr Sarnacki 2014-07-29 13:29:46 +02:00
parent 9fa906aafc
commit 17ed1d94cc
13 changed files with 122 additions and 6 deletions

View File

@ -24,10 +24,11 @@ unless window.TravisApplication
requests: Travis.Request
env_var: Travis.EnvVar
env_vars: Travis.EnvVar
ssh_key: Travis.SshKey
).property()
modelClasses: (->
[Travis.User, Travis.Build, Travis.Job, Travis.Repo, Travis.Commit, Travis.Worker, Travis.Account, Travis.Broadcast, Travis.Hook, Travis.Annotation, Travis.Request, Travis.EnvVar]
[Travis.User, Travis.Build, Travis.Job, Travis.Repo, Travis.Commit, Travis.Worker, Travis.Account, Travis.Broadcast, Travis.Hook, Travis.Annotation, Travis.Request, Travis.EnvVar, Travis.SshKey]
).property()
setup: ->
@ -38,6 +39,9 @@ unless window.TravisApplication
Travis.EnvVar.url = "/settings/env_vars"
Travis.EnvVar.adapter = Travis.EnvVarsAdapter.create()
Travis.SshKey.url = "/settings/ssh_key"
Travis.SshKey.adapter = Travis.SshKeyAdapter.create()
@slider = new Travis.Slider()
@pusher = new Travis.Pusher(Travis.config.pusher_key) if Travis.config.pusher_key
@tailing = new Travis.Tailing($(window), '#tail', '#log')

View File

@ -69,3 +69,4 @@ require 'controllers/requests'
require 'controllers/env_var'
require 'controllers/env_vars'
require 'controllers/env_var_new'
require 'controllers/ssh_key'

View File

@ -0,0 +1,29 @@
Travis.SshKeyController = Ember.ObjectController.extend
isEditing: false
defaultKey: null
needs: ['repoSettings']
repo: Ember.computed.alias('controllers.repoSettings.model')
actions:
add: ->
model = Travis.SshKey.create(id: @get('repo.id'))
@set('model', model)
@set('isEditing', true)
save: ->
@get('model').save().then =>
@set('isEditing', false)
delete: ->
@get('model').deleteRecord().then =>
@set('model', null)
cancel: ->
if model = @get('model')
if model.get('isNew')
@set('model', null)
@set('isEditing', false)
edit: ->
@set('isEditing', true)

View File

@ -6,7 +6,7 @@ safe = (string) ->
Travis.Tab = Ember.Object.extend
url: (->
id = @get('id')
if id == 'env_vars'
if id == 'env_vars' || id == 'ssh_key'
id
else
"repo.settings.#{id}"

View File

@ -14,3 +14,4 @@ require 'models/request'
require 'models/user'
require 'models/worker'
require 'models/env_var'
require 'models/ssh_key'

View File

@ -23,6 +23,10 @@ require 'travis/model'
}
).property('lastBuildId', 'lastBuildNumber')
sshKey: (->
Travis.SshKey.find(@get('id'))
)
envVars: (->
id = @get('id')
envVars = Travis.EnvVar.find repository_id: id
@ -42,7 +46,6 @@ require 'travis/model'
array
).property()
allBuilds: (->
recordArray = Ember.RecordArray.create({ modelClass: Travis.Build, content: Ember.A([]) })
Travis.Build.registerRecordArray(recordArray)

View File

@ -0,0 +1,13 @@
Travis.SshKey = Travis.Model.extend
id: Ember.attr('string')
value: Ember.attr('string')
description: Ember.attr('string')
fingerprint: Ember.attr('string')
isPropertyLoaded: (key) ->
if key == 'value'
return true
else
@_super(key)

View File

@ -67,7 +67,7 @@ Travis.Router.map ->
@route 'index', path: '/'
@resource 'env_vars', ->
@route 'new'
@route 'ssh_key'
@resource 'ssh_key'
@route 'first_sync'
@route 'insufficient_oauth_permissions'
@ -369,3 +369,26 @@ Travis.EnvVarsRoute = Travis.Route.extend
model: (params) ->
repo = @modelFor('repo_settings')
repo.get('envVars')
Travis.SshKeyRoute = Travis.Route.extend
model: (params) ->
repo = @modelFor('repo_settings')
self = this
Travis.SshKey.fetch(repo.get('id')).then ( (result) -> result ), (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_settings')
Travis.ajax.get "/repositories/#{repo.get('id')}/key", (data) =>
@defaultKey = Ember.Object.create(fingerprint: data.fingerprint)
setupController: (controller, model) ->
@_super.apply this, arguments
if @defaultKey
controller.set('defaultKey', @defaultKey)
@defaultKey = null

View File

@ -0,0 +1,31 @@
{{#if model}}
{{#if isEditing}}
<form {{action "save" on="submit"}}>
<p>Description: {{input value=description}}</p>
<p>Value: {{textarea value=value}}</p>
<p>
{{input type="submit" value="Save"}} or <a href="#" {{action "cancel"}}>Cancel</a>
</p>
</form>
{{else}}
<p>
Ssh key is set.<br/>
{{#if description}}
Description: {{description}}<br/>
{{/if}}
Fingerprint: {{fingerprint}}
</p>
<p>
<a href="#" {{action "delete"}}>Delete</a>
<a href="#" {{action "edit"}}>Edit</a>
</p>
{{/if}}
{{else}}
<p>
You don't have any custom key set up.
Currently used key has a following fingerprint: {{defaultKey.fingerprint}}
</p>
<p><a {{action "add"}} href="#">Add a custom ssh key</a></p>
{{/if}}

View File

@ -0,0 +1,10 @@
Travis.SshKeyAdapter = Travis.Adapter.extend
buildURL: (klass, id, record) ->
url = @_super.apply this, arguments
createRecord: (record) ->
url = @buildURL(record.constructor, record.get('id'), record)
self = this
@ajax(url, record.toJSON(), "PATCH").then (data) ->
self.didCreateRecord record, data
record

View File

@ -163,6 +163,7 @@ Ember.LinkView.reopen
require 'travis/ajax'
require 'travis/adapter'
require 'travis/adapters/env_vars'
require 'travis/adapters/ssh_key'
require 'routes'
require 'auth'
require 'controllers'

View File

@ -4,7 +4,7 @@
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,800' rel='stylesheet' type='text/css'>
<meta charset="UTF-8">
<meta rel="travis.api_endpoint" href="https://api.travis-ci.org">
<meta name="travis.pusher_key" value="5df8ac576dcccf4fd076">
<meta name="travis.pusher_key" value="">
<meta name="travis.ga_code" value="UA-24868285-1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Travis CI - Free Hosted Continuous Integration Platform for the Open Source Community</title>