From e7aa74872dd4543bc3cb2e8acd991e18f844f494 Mon Sep 17 00:00:00 2001 From: Lisa Passing Date: Tue, 21 Jul 2015 17:24:18 +0200 Subject: [PATCH] add general settings functionality --- app/components/settings-switch.coffee | 27 ++++++++------------ app/routes/settings.coffee | 1 + app/styles/app/modules/tooltips.sass | 8 +++--- app/templates/components/settings-switch.hbs | 5 +++- app/templates/settings.hbs | 6 ++--- tests/integration/components/ssh-key-test.js | 4 +-- 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/app/components/settings-switch.coffee b/app/components/settings-switch.coffee index 4f21d6ab..53677cce 100644 --- a/app/components/settings-switch.coffee +++ b/app/components/settings-switch.coffee @@ -4,23 +4,18 @@ SettingsSwitchComponent = Ember.Component.extend tagName: 'a' classNames: ['switch'] - classNameBindings: ['_active:active'] - - # TODO: how to handle overriding properties to - # avoid naming it _action? - _active: (-> - @get('target.active') || @get('active') - ).property('target.active', 'active') + classNameBindings: ['active'] click: -> - target = @get('target') - if @get('toggleAutomatically') != 'false' - if target - @set('target.active', !@get('target.active')) - else - @set('active', !@get('active')) - # allow for bindings to propagate - Ember.run.next this, -> - @sendAction('action', target) + return if @get('isSaving') + @set('isSaving', true) + @toggleProperty('active') + setting = {} + setting[@get('key')] = @get('active') + @get('repo').saveSettings(setting).then => + @set('isSaving', false) + , => + @set('isSaving', false) + Travis.flash(error: 'There was an error while saving settings. Please try again.') `export default SettingsSwitchComponent` diff --git a/app/routes/settings.coffee b/app/routes/settings.coffee index 6e95d53e..669bb17c 100644 --- a/app/routes/settings.coffee +++ b/app/routes/settings.coffee @@ -29,6 +29,7 @@ Route = TravisRoute.extend model: () -> return Ember.RSVP.hash({ + settings: @modelFor('repo').fetchSettings(), envVars: this.fetchEnvVars(), sshKey: this.fetchSshKey(), customSshKey: this.fetchCustomSshKey() diff --git a/app/styles/app/modules/tooltips.sass b/app/styles/app/modules/tooltips.sass index 957d462d..9f917e65 100644 --- a/app/styles/app/modules/tooltips.sass +++ b/app/styles/app/modules/tooltips.sass @@ -1,8 +1,8 @@ %tooltip - &:hover - .tooltip-bubble - transform: translateY(0) - opacity: 1 + &:hover .tooltip-bubble, + &:hover + .tooltip-bubble + transform: translateY(0) + opacity: 1 .tooltip-bubble position: absolute diff --git a/app/templates/components/settings-switch.hbs b/app/templates/components/settings-switch.hbs index 8ebee2b5..e6f90dd4 100644 --- a/app/templates/components/settings-switch.hbs +++ b/app/templates/components/settings-switch.hbs @@ -6,4 +6,7 @@ OFF -Some label text +{{description}} +{{#if isSaving}} + {{loading-indicator}} +{{/if}} \ No newline at end of file diff --git a/app/templates/settings.hbs b/app/templates/settings.hbs index d455bac8..af325a1e 100644 --- a/app/templates/settings.hbs +++ b/app/templates/settings.hbs @@ -4,12 +4,12 @@

General Settings

diff --git a/tests/integration/components/ssh-key-test.js b/tests/integration/components/ssh-key-test.js index 9cb898d9..0844f31b 100644 --- a/tests/integration/components/ssh-key-test.js +++ b/tests/integration/components/ssh-key-test.js @@ -53,10 +53,10 @@ test('it deletes a custom key', function(assert) { this.set('key', key); this.render(hbs`{{ssh-key key=key sshKeyDeleted="sshKeyDeleted"}}`); - this.on('sshKeyDeleted', function() {}) + this.on('sshKeyDeleted', function() {}); this.$('.ssh-key-action a').click(); - assert.ok(key.get('isDeleted'), 'key should be deleted') + assert.ok(key.get('isDeleted'), 'key should be deleted'); });