Implement forum topic voting and tag change pruning (#3580)

This commit is contained in:
Albert Yi
2018-04-16 16:09:39 -07:00
parent 45fad069d7
commit f2b525a6d2
182 changed files with 558 additions and 554 deletions

View File

@@ -0,0 +1,11 @@
<%-
# forum_post
%>
<li>
<%= link_to content_tag(:i, nil, class: "far fa-thumbs-up"), forum_post_votes_path(forum_post_id: forum_post.id, format: "js"), remote: true, method: :post, data: {params: "forum_post_vote[score]=1"}, title: "Vote up" %>
<%= link_to content_tag(:i, nil, class: "far fa-meh"), forum_post_votes_path(forum_post_id: forum_post.id, format: "js"), remote: true, method: :post, data: {params: "forum_post_vote[score]=0"}, title: "Vote meh" %>
<%= link_to content_tag(:i, nil, class: "far fa-thumbs-down"), forum_post_votes_path(forum_post_id: forum_post.id, format: "js"), remote: true, method: :post, data: {params: "forum_post_vote[score]=-1"}, title: "Vote down" %>
</li>

View File

@@ -0,0 +1,16 @@
<%-
# votes
# forum_post
%>
<% votes.by(CurrentUser.user.id).each do |vote| %>
<%= render "forum_post_votes/vote", vote: vote, forum_post: forum_post %>
<% end %>
<% votes.excluding(CurrentUser.user.id).each do |vote| %>
<%= render "forum_post_votes/vote", vote: vote, forum_post: forum_post %>
<% end %>
<% if !votes.by(CurrentUser.user.id).exists? %>
<%= render "forum_post_votes/add_vote", vote: votes.by(CurrentUser.user.id).first, forum_post: forum_post %>
<% end %>

View File

@@ -0,0 +1,14 @@
<%-
# vote
# forum_post
%>
<li class="vote-score-<%= vote.vote_type %>">
<% if vote.creator_id == CurrentUser.id %>
<%= link_to content_tag(:i, nil, class: "far #{vote.fa_class}"), forum_post_votes_path(forum_post_id: forum_post.id, format: "js"), remote: true, method: :delete %>
<%= link_to_user vote.creator %>
<% else %>
<%= content_tag(:i, nil, class: "far #{vote.fa_class}") %>
<%= link_to_user vote.creator %>
<% end %>
</li>

View File

@@ -0,0 +1,7 @@
<% if @forum_post_vote.invalid? %>
Danbooru.error(<%= raw @forum_post_vote.errors.full_messages.join("; ").to_json %>);
<% else %>
Danbooru.notice("Voted");
var code = <%= raw render(partial: "forum_post_votes/list", locals: {forum_post: @forum_post, votes: @forum_post.votes}).to_json %>;
$("#forum-post-votes-for-<%= @forum_post.id %>").html(code);
<% end %>

View File

@@ -0,0 +1,3 @@
Danbooru.notice("Unvoted");
var code = <%= raw render(partial: "forum_post_votes/list", locals: {forum_post: @forum_post, votes: @forum_post.votes}).to_json %>;
$("#forum-post-votes-for-<%= @forum_post.id %>").html(code);