diff options
-rw-r--r-- | app/assets/javascripts/star.js.coffee | 22 | ||||
-rw-r--r-- | app/views/projects/_home_panel.html.haml | 3 | ||||
-rw-r--r-- | app/views/projects/buttons/_star.html.haml | 35 | ||||
-rw-r--r-- | features/steps/project/create.rb | 4 |
4 files changed, 27 insertions, 37 deletions
diff --git a/app/assets/javascripts/star.js.coffee b/app/assets/javascripts/star.js.coffee new file mode 100644 index 00000000000..d849b2e7950 --- /dev/null +++ b/app/assets/javascripts/star.js.coffee @@ -0,0 +1,22 @@ +class @Star + constructor: -> + $('.project-home-panel .toggle-star').on('ajax:success', (e, data, status, xhr) -> + $this = $(this) + $starSpan = $this.find('span') + $starIcon = $this.find('i') + + toggleStar = (isStarred) -> + $this.parent().find('span.count').text data.star_count + if isStarred + $starSpan.removeClass('starred').text 'Star' + $starIcon.removeClass('fa-star').addClass 'fa-star-o' + else + $starSpan.addClass('starred').text 'Unstar' + $starIcon.removeClass('fa-star-o').addClass 'fa-star' + return + + toggleStar $starSpan.hasClass('starred') + return + ).on 'ajax:error', (e, xhr, status, error) -> + new Flash('Star toggle failed. Try again later.', 'alert') + return
\ No newline at end of file diff --git a/app/views/projects/_home_panel.html.haml b/app/views/projects/_home_panel.html.haml index 4420861c9dc..e92115b9b98 100644 --- a/app/views/projects/_home_panel.html.haml +++ b/app/views/projects/_home_panel.html.haml @@ -38,3 +38,6 @@ = render 'projects/buttons/dropdown' = render 'projects/buttons/notifications' + +:coffeescript + new Star()
\ No newline at end of file diff --git a/app/views/projects/buttons/_star.html.haml b/app/views/projects/buttons/_star.html.haml index f92488fd88f..21ba426aaa1 100644 --- a/app/views/projects/buttons/_star.html.haml +++ b/app/views/projects/buttons/_star.html.haml @@ -11,41 +11,6 @@ %span.count.star-count = @project.star_count - :javascript - $('.project-home-panel .toggle-star').on('ajax:success', function (e, data, status, xhr) { - var $this = $(this); - var $starSpan = $this.find('span'); - var $starIcon = $this.find('i'); - - var toggleStar = function(isStarred) { - $this - .parent() - .find('span.count') - .text(data.star_count); - if(isStarred){ - $starSpan - .removeClass('starred') - .text('Star'); - $starIcon - .removeClass('fa-star') - .addClass('fa-star-o'); - - } else { - $starSpan - .addClass('starred') - .text('Unstar'); - $starIcon - .removeClass('fa-star-o') - .addClass('fa-star'); - } - }; - - toggleStar($starSpan.hasClass('starred')); - }) - .on('ajax:error', function (e, xhr, status, error) { - new Flash('Star toggle failed. Try again later.', 'alert'); - }); - - else = link_to new_user_session_path, class: 'btn has_tooltip star-btn', title: 'You must sign in to star a project' do = icon('star fw') diff --git a/features/steps/project/create.rb b/features/steps/project/create.rb index 0c247c83133..8a0e8fc2b6c 100644 --- a/features/steps/project/create.rb +++ b/features/steps/project/create.rb @@ -31,7 +31,7 @@ class Spinach::Features::ProjectCreate < Spinach::FeatureSteps end step 'Remote url should update to http link' do - expect(page).to have_content Project.last.http_url_to_repo + expect(page).to have_content "git remote add origin #{Project.last.http_url_to_repo}" end step 'If I click on SSH' do @@ -40,6 +40,6 @@ class Spinach::Features::ProjectCreate < Spinach::FeatureSteps end step 'Remote url should update to ssh link' do - expect(page).to have_content Project.last.ssh_url_to_repo + expect(page).to have_content "git remote add origin #{Project.last.url_to_repo}" end end |