diff --git a/app/components/ssh-key.coffee b/app/components/ssh-key.coffee index 72eb23f7..490d7aaa 100644 --- a/app/components/ssh-key.coffee +++ b/app/components/ssh-key.coffee @@ -4,4 +4,7 @@ SshKeyComponent = Ember.Component.extend classNames: ['settings-sshkey'] + isCustom: () -> + false + `export default SshKeyComponent` diff --git a/app/routes/settings.coffee b/app/routes/settings.coffee index cb9a0f0e..1c50a2f5 100644 --- a/app/routes/settings.coffee +++ b/app/routes/settings.coffee @@ -1,4 +1,5 @@ `import TravisRoute from 'travis/routes/basic'` +`import Ajax from 'travis/utils/ajax'` Route = TravisRoute.extend needsAuth: true @@ -11,10 +12,26 @@ Route = TravisRoute.extend repo = @modelFor('repo') repo.get('envVars.promise') + fetchSshKey: () -> + repo = @modelFor('repo') + self = this + @store.find('sshKey', 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 false + + fetchCustomSshKey: () -> + repo = @modelFor('repo') + Ajax.get "/repos/#{repo.get('id')}/key", (data) => + Ember.Object.create(fingerprint: data.fingerprint) + model: () -> return Ember.RSVP.hash({ envVars: this.fetchEnvVars(), - # sshKey: this.fetchSshKey() + sshKey: this.fetchSshKey(), + customSshKey: this.fetchCustomSshKey() }); `export default Route` diff --git a/app/templates/components/ssh-key.hbs b/app/templates/components/ssh-key.hbs index 94c5c741..3e4a2350 100644 --- a/app/templates/components/ssh-key.hbs +++ b/app/templates/components/ssh-key.hbs @@ -1,11 +1,12 @@ -{{#if custom}} +{{#if isCustom}} <div class="ssh-key-name"> <span class="icon-key"></span> - <span>TRAVIS_PRIVATE_KEY</span> + <span>{{key.description}}</span> </div> <div class="ssh-key-value"> <span class="icon-fingerprint"></span> - <span>e1:b1:83:06:7e:51:6d:5e:e0:e0:60:96:ca:ac:3d:8a</span> + <span>{{key.fingerprint}}</span> + <span>{{fingerprint}}</span> </div> <div class="ssh-key-action"> <div class="tooltip"> @@ -22,7 +23,8 @@ </div> <div class="ssh-key-value"> <span class="icon-fingerprint"></span> - <span>e1:b1:83:06:7e:51:6d:5e:e0:e0:60:96:ca:ac:3d:8a</span> + <span>{{key.fingerprint}}</span> + <span>{{fingerprint}}</span> </div> <div class="ssh-key-action"> <div class="tooltip--height"> diff --git a/app/templates/settings.hbs b/app/templates/settings.hbs index 93689a2b..ec8954ae 100644 --- a/app/templates/settings.hbs +++ b/app/templates/settings.hbs @@ -31,23 +31,28 @@ <section class="settings-section"> <h2 class="small-title">SSH Key</h2> - {{ssh-key}} - {{ssh-key custom=true}} + {{#if sshKey}} + {{ssh-key key=sshKey}} - <div class="form--sshkey"> - <a href="" class="button">Add custom SSH Key</a> - <form action=""> - <div class="form-elem"> - <input type="text" placeholder="Description"> - </div> - <div class="form-elem"> - <textarea name="" id="" cols="30" rows="10" placeholder="SSH key"></textarea> - </div> - <div class="form-elem"> - <input type="submit" class="form-submit" value="Add"> - </div> - </form> - </div> + <div class="form--sshkey"> + <a href="" class="button">Add custom SSH Key</a> + <form action=""> + <div class="form-elem"> + <input type="text" placeholder="Description"> + </div> + <div class="form-elem"> + <textarea name="" id="" cols="30" rows="10" placeholder="SSH key"></textarea> + </div> + <div class="form-elem"> + <input type="submit" class="form-submit" value="Add"> + </div> + </form> + </div> + {{else}} + {{ssh-key key=customSshKey}} + {{/if}} + + </section> {{/if}} <section class="settings-section">