From 87ddf9979a75a1e082f2be3015e7c56a38226bc0 Mon Sep 17 00:00:00 2001 From: Lisa Passing Date: Mon, 20 Jul 2015 17:58:32 +0200 Subject: [PATCH] copy some methods from ssh-key controller to add-ssh-key component --- app/components/add-env-var.coffee | 1 - app/components/add-ssh-key.coffee | 51 ++++++++++++++++++++++++ app/templates/components/add-ssh-key.hbs | 12 ++++-- app/templates/settings.hbs | 3 +- 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/app/components/add-env-var.coffee b/app/components/add-env-var.coffee index 830a1fac..df96537e 100644 --- a/app/components/add-env-var.coffee +++ b/app/components/add-env-var.coffee @@ -19,7 +19,6 @@ AddEnvVarComponent = Ember.Component.extend actions: save: -> - console.log('SUBMITTED') return if @get('isSaving') @set('isSaving', true) diff --git a/app/components/add-ssh-key.coffee b/app/components/add-ssh-key.coffee index 3de91684..6a36169f 100644 --- a/app/components/add-ssh-key.coffee +++ b/app/components/add-ssh-key.coffee @@ -4,5 +4,56 @@ AddSshKeyComponent = Ember.Component.extend classNames: ['form--sshkey'] + store: Ember.inject.service() + isSaving: false + + isValid: () -> + true + + reset: -> + @setProperties(description: null, value: null) + + actions: + + add: -> + # not sure how to integrate that with 'save' in the compotent + id = @get('repo.id') + model = @store.recordForId('sshKey', id) + # TODO: this can be removed in favor of simply unloading record + # once https://github.com/emberjs/data/pull/2867 + # and https://github.com/emberjs/data/pull/2870 are merged + if model + @store.dematerializeRecord(model) + typeMap = @store.typeMapFor('sshKey') + idToRecord = typeMap.idToRecord + delete idToRecord[id] + + model = @store.createRecord('sshKey', id: id) + @set('model', model) + @set('isEditing', true) + + save: -> + return if @get('isSaving') + @set('isSaving', true) + + if @isValid() + + ssh_key = @get('store').createRecord('ssh_key', + description: @get('description') + value: @get('value') + fingerprint: 'I dont know?' + repo: @get('repo') + ) + self = this + ssh_key.save().then => + @set('isSaving', false) + @reset() + , => + @set('isSaving', false) + + # if error.errors + # @addErrorsFromResponse(error.errors) + else + @set('isSaving', false) `export default AddSshKeyComponent` diff --git a/app/templates/components/add-ssh-key.hbs b/app/templates/components/add-ssh-key.hbs index 1f44a246..eec4e6d5 100644 --- a/app/templates/components/add-ssh-key.hbs +++ b/app/templates/components/add-ssh-key.hbs @@ -1,11 +1,15 @@ -
+
- + {{input value=description class="ssh-description" placeholder="Description"}}
- + {{textarea value=value class="ssh-value" rows="10" placeholder="SSH Key"}}
- + {{#if isSaving}} + {{loading-indicator}} + {{else}} + + {{/if}}
diff --git a/app/templates/settings.hbs b/app/templates/settings.hbs index 4fd90540..9af9fb47 100644 --- a/app/templates/settings.hbs +++ b/app/templates/settings.hbs @@ -35,10 +35,9 @@ {{ssh-key key=model.customSshKey}} {{else}} {{ssh-key key=model.sshKey}} - {{add-ssh-key }} + {{add-ssh-key repo=repo}} {{/if}} - {{/if}}