Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
ISSUE-203: ajaxified star/unstar
Browse files Browse the repository at this point in the history
  • Loading branch information
lsamayoa committed Jul 25, 2015
1 parent 5aacd3e commit 475a55f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def star
respond_to do |format|
format.html { redirect_to(repository_path(@repository)) }
format.json { render json: @repository }
format.js {}
end
end

Expand All @@ -32,6 +33,7 @@ def unstar
respond_to do |format|
format.html { redirect_to(repository_path(@repository)) }
format.json { render json: @repository }
format.js {}
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/views/repositories/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
= link_to @repository.namespace.clean_name, @repository.namespace
| /
= @repository.name
.pull-right
#repo-stars.pull-right
- if can_star_repository?(@repository)
= link_to 'Star', star_repository_path(@repository), method: :post, id: 'star_repo', class: 'btn btn-small btn-default'
= link_to 'Star', star_repository_path(@repository), method: :post, class: 'btn btn-small btn-default', remote: true
i.fa.fa-star-o
- else
= link_to 'Unstar', unstar_repository_path(@repository), method: :post, id: 'unstar_repo', class: 'btn btn-small btn-default'
= link_to 'Unstar', unstar_repository_path(@repository), method: :post, class: 'btn btn-small btn-default', remote: true
i.fa.fa-star
span#star-counter= @repository.stars.count
.panel-body
Expand Down
15 changes: 15 additions & 0 deletions app/views/repositories/star.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% if @repository.errors.any? %>
$('#alert p').html("<%= escape_javascript(@repository.errors.full_messages.join('<br/>')) %>");
$('#alert').fadeIn();
<% else %>
(function () {
var link = $('#repo-stars a');
var icon = $('#repo-stars i')
var counter = $('#repo-stars #star-counter');
link.html("<%= escape_javascript(t('Unstar')) %>");
link.attr("href", "<%= escape_javascript(unstar_repository_path(@repository)) %>");
icon.addClass("fa-star");
icon.removeClass("fa-star-o");
counter.html("<%= escape_javascript(@repository.stars.count.to_s) %>");
})();
<% end %>
15 changes: 15 additions & 0 deletions app/views/repositories/unstar.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% if @repository.errors.any? %>
$('#alert p').html("<%= escape_javascript(@repository.errors.full_messages.join('<br/>')) %>");
$('#alert').fadeIn();
<% else %>
(function () {
var link = $('#repo-stars a');
var icon = $('#repo-stars i')
var counter = $('#repo-stars #star-counter');
link.html("<%= escape_javascript(t('Star')) %>");
link.attr("href", "<%= escape_javascript(star_repository_path(@repository)) %>");
icon.addClass("fa-star-o");
icon.removeClass("fa-star");
counter.html("<%= escape_javascript(@repository.stars.count.to_s) %>");
})();
<% end %>

0 comments on commit 475a55f

Please sign in to comment.