BigW Consortium Gitlab

Commit 6592bfbb by Jacob Schatz

Moves star code to a class

parent 7ba4482f
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
...@@ -38,3 +38,6 @@ ...@@ -38,3 +38,6 @@
= render 'projects/buttons/dropdown' = render 'projects/buttons/dropdown'
= render 'projects/buttons/notifications' = render 'projects/buttons/notifications'
:coffeescript
new Star()
\ No newline at end of file
...@@ -11,41 +11,6 @@ ...@@ -11,41 +11,6 @@
%span.count.star-count %span.count.star-count
= @project.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 - else
= link_to new_user_session_path, class: 'btn has_tooltip star-btn', title: 'You must sign in to star a project' do = 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') = icon('star fw')
......
...@@ -31,7 +31,7 @@ class Spinach::Features::ProjectCreate < Spinach::FeatureSteps ...@@ -31,7 +31,7 @@ class Spinach::Features::ProjectCreate < Spinach::FeatureSteps
end end
step 'Remote url should update to http link' do 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 end
step 'If I click on SSH' do step 'If I click on SSH' do
...@@ -40,6 +40,6 @@ class Spinach::Features::ProjectCreate < Spinach::FeatureSteps ...@@ -40,6 +40,6 @@ class Spinach::Features::ProjectCreate < Spinach::FeatureSteps
end end
step 'Remote url should update to ssh link' do 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
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment