From 249003d2ff9ef772148d95d242876e2ec50ee3ca Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 21 Apr 2015 17:46:49 +0200 Subject: [PATCH 1/6] First stab at hooks activation error message --- app/components/hook-switch.coffee | 17 +++++++++++++++++ app/components/hooks-list-item.coffee | 11 +++++++++++ app/templates/account.hbs | 15 +-------------- app/templates/components/hook-switch.hbs | 6 ++++++ app/templates/components/hooks-list-item.hbs | 18 ++++++++++++++++++ tests/unit/components/hook-switch-test.coffee | 17 +++++++++++++++++ .../components/hooks-list-item-test.coffee | 17 +++++++++++++++++ 7 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 app/components/hook-switch.coffee create mode 100644 app/components/hooks-list-item.coffee create mode 100644 app/templates/components/hook-switch.hbs create mode 100644 app/templates/components/hooks-list-item.hbs create mode 100644 tests/unit/components/hook-switch-test.coffee create mode 100644 tests/unit/components/hooks-list-item-test.coffee diff --git a/app/components/hook-switch.coffee b/app/components/hook-switch.coffee new file mode 100644 index 00000000..196e35ec --- /dev/null +++ b/app/components/hook-switch.coffee @@ -0,0 +1,17 @@ +`import Ember from 'ember'` + +HookSwitchComponent = Ember.Component.extend + tagName: 'a' + classNames: ['travis-switch', 'switch'] + classNameBindings: ['active'] + activeBinding: "hook.active" + + click: -> + hook = @get('hook') + hook.toggle().then( (->), => + @toggleProperty('hook.active') + @sendAction('onToggleError', hook) + ) + + +`export default HookSwitchComponent` diff --git a/app/components/hooks-list-item.coffee b/app/components/hooks-list-item.coffee new file mode 100644 index 00000000..7cf32639 --- /dev/null +++ b/app/components/hooks-list-item.coffee @@ -0,0 +1,11 @@ +`import Ember from 'ember'` + +HooksListItemComponent = Ember.Component.extend + tagName: 'li' + classNames: ['row'] + classNameBindings: ['hook.active:active'] + actions: + handleToggleError: -> + @set("errorMessage", "There was an error") + +`export default HooksListItemComponent` diff --git a/app/templates/account.hbs b/app/templates/account.hbs index a7ef4634..76a79f94 100644 --- a/app/templates/account.hbs +++ b/app/templates/account.hbs @@ -73,20 +73,7 @@
- {{#if hooksWithoutAdmin.length}} -
-

You require admin rights to enable these repositories

+ {{#if hooksWithoutAdmin.length}} +
+

You require admin rights to enable these repositories

- -
- {{/if}} + +
{{/if}} + {{else}} {{/if}} diff --git a/app/templates/components/hooks-list-item.hbs b/app/templates/components/hooks-list-item.hbs index 98480303..4a1e485c 100644 --- a/app/templates/components/hooks-list-item.hbs +++ b/app/templates/components/hooks-list-item.hbs @@ -1,4 +1,4 @@ -
+
{{hook-switch hook=hook onToggleError="handleToggleError"}} {{!-- --}} {{#if hook.isSaving}} @@ -13,6 +13,6 @@ {{#if errorMessage}}
- {{errorMessage}} +

{{errorMessage}}

{{/if}} From c76d4de614c1f797d1c8b7f209bede2300d90fc9 Mon Sep 17 00:00:00 2001 From: Lisa Passing Date: Wed, 22 Apr 2015 16:20:26 +0200 Subject: [PATCH 3/6] add closing icon and action to hook error --- app/components/hooks-list-item.coffee | 3 +++ app/styles/app/layouts/profile.sass | 6 ++++++ app/templates/components/hooks-list-item.hbs | 4 +++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/components/hooks-list-item.coffee b/app/components/hooks-list-item.coffee index 7cf32639..1a7b3d72 100644 --- a/app/components/hooks-list-item.coffee +++ b/app/components/hooks-list-item.coffee @@ -8,4 +8,7 @@ HooksListItemComponent = Ember.Component.extend handleToggleError: -> @set("errorMessage", "There was an error") + close: -> + @set("errorMessage", null) + `export default HooksListItemComponent` diff --git a/app/styles/app/layouts/profile.sass b/app/styles/app/layouts/profile.sass index f5394b08..83ebceee 100644 --- a/app/styles/app/layouts/profile.sass +++ b/app/styles/app/layouts/profile.sass @@ -213,3 +213,9 @@ p.profile-user-last height: 1.2em background: #f1b6ad transform: rotate(45deg) + .close + @extend .icon + position: absolute + top: 1em + right: 1em + @extend .icon--dismiss-red diff --git a/app/templates/components/hooks-list-item.hbs b/app/templates/components/hooks-list-item.hbs index 4a1e485c..b8cd6234 100644 --- a/app/templates/components/hooks-list-item.hbs +++ b/app/templates/components/hooks-list-item.hbs @@ -13,6 +13,8 @@ {{#if errorMessage}}
-

{{errorMessage}}

+

+ {{errorMessage}} +

{{/if}} From f9563187d39f04336e69750a7c300b2eb1053021 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 22 Apr 2015 16:51:41 +0200 Subject: [PATCH 4/6] Add a better error message --- app/components/hooks-list-item.coffee | 8 ++++++-- app/styles/app/layouts/profile.sass | 2 +- app/templates/components/hooks-list-item.hbs | 14 +++++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/components/hooks-list-item.coffee b/app/components/hooks-list-item.coffee index 1a7b3d72..5298c717 100644 --- a/app/components/hooks-list-item.coffee +++ b/app/components/hooks-list-item.coffee @@ -1,14 +1,18 @@ `import Ember from 'ember'` +`import config from 'travis/config/environment'` HooksListItemComponent = Ember.Component.extend tagName: 'li' classNames: ['row'] classNameBindings: ['hook.active:active'] + + githubOrgsOauthAccessSettingsUrl: config.githubOrgsOauthAccessSettingsUrl + actions: handleToggleError: -> - @set("errorMessage", "There was an error") + @set("showError", true) close: -> - @set("errorMessage", null) + @set("showError", false) `export default HooksListItemComponent` diff --git a/app/styles/app/layouts/profile.sass b/app/styles/app/layouts/profile.sass index 83ebceee..50669d75 100644 --- a/app/styles/app/layouts/profile.sass +++ b/app/styles/app/layouts/profile.sass @@ -201,7 +201,7 @@ p.profile-user-last padding: 0 $column-gutter/2; p position: relative - padding: $column-gutter/2; + padding: $column-gutter/2 $column-gutter*2 $column-gutter/2 $column-gutter/2; color: #de4248 background-color: #f1b6ad &:after diff --git a/app/templates/components/hooks-list-item.hbs b/app/templates/components/hooks-list-item.hbs index b8cd6234..50dde162 100644 --- a/app/templates/components/hooks-list-item.hbs +++ b/app/templates/components/hooks-list-item.hbs @@ -11,10 +11,18 @@ {{hook.slug}} {{hook.description}} -{{#if errorMessage}} +{{#if showError}}

- {{errorMessage}} -

+ An error happened when we tried to alter settings on GitHub. + {{#if githubOrgsOauthAccessSettingsUrl}} + It may be caused by API restrictions, please + + review and add + your authorized Orgs. + {{/if}} + +

{{/if}} From cc1ae3c2e7f62111d05309b9cd995d2f3c2ae482 Mon Sep 17 00:00:00 2001 From: Lisa Passing Date: Wed, 22 Apr 2015 17:06:36 +0200 Subject: [PATCH 5/6] add some simple tests to hooks-list-item --- .../components/hooks-list-item-test.coffee | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/unit/components/hooks-list-item-test.coffee b/tests/unit/components/hooks-list-item-test.coffee index 848f84ba..f0ddafdc 100644 --- a/tests/unit/components/hooks-list-item-test.coffee +++ b/tests/unit/components/hooks-list-item-test.coffee @@ -2,16 +2,23 @@ moduleForComponent 'hooks-list-item', 'HooksListItemComponent', { # specify the other units that are required for this test - # needs: ['component:foo', 'helper:bar'] + needs: ['component:hook-switch'] } test 'it renders', -> - expect 2 - # creates the component instance - component = @subject() - equal component._state, 'preRender' - - # appends the component to the page + attributes = { + id: 10000, + name: "foo-bar", + owner_name: "foo", + description: "A foo repo", + active: true, + urlGithub: "https://github.com/foo/foobar", + slug: "foo/foo-bar" + } + component = @subject(hook: attributes) @append() - equal component._state, 'inDOM' + + ok component.$().hasClass('active'), 'component should have active class' + ok component.$('.travis-switch').hasClass('active'), 'switch should have active class' + equal component.$('.profile-repo span').text().trim(), 'A foo repo', 'repo description should be displayed' From 268bc6096a63bab60b3bb867f693719b9f37607b Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 23 Apr 2015 10:52:53 +0200 Subject: [PATCH 6/6] Remove error message when toggling hook --- app/components/hook-switch.coffee | 1 + app/components/hooks-list-item.coffee | 3 +++ app/templates/components/hooks-list-item.hbs | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/components/hook-switch.coffee b/app/components/hook-switch.coffee index 196e35ec..18468089 100644 --- a/app/components/hook-switch.coffee +++ b/app/components/hook-switch.coffee @@ -7,6 +7,7 @@ HookSwitchComponent = Ember.Component.extend activeBinding: "hook.active" click: -> + @sendAction('onToggle') hook = @get('hook') hook.toggle().then( (->), => @toggleProperty('hook.active') diff --git a/app/components/hooks-list-item.coffee b/app/components/hooks-list-item.coffee index 5298c717..f0f69e3e 100644 --- a/app/components/hooks-list-item.coffee +++ b/app/components/hooks-list-item.coffee @@ -13,6 +13,9 @@ HooksListItemComponent = Ember.Component.extend @set("showError", true) close: -> + @send('resetErrors') + + resetErrors: -> @set("showError", false) `export default HooksListItemComponent` diff --git a/app/templates/components/hooks-list-item.hbs b/app/templates/components/hooks-list-item.hbs index 50dde162..91fa3d36 100644 --- a/app/templates/components/hooks-list-item.hbs +++ b/app/templates/components/hooks-list-item.hbs @@ -1,5 +1,5 @@
- {{hook-switch hook=hook onToggleError="handleToggleError"}} + {{hook-switch hook=hook onToggleError="handleToggleError" onToggle="resetErrors"}} {{!-- --}} {{#if hook.isSaving}}