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);

View File

@@ -1,3 +1,5 @@
<%- # original_forum_post_id: used to accelerate #is_original_post? calls %>
<% if forum_post.visible?(CurrentUser.user) %>
<article class="forum-post" id="forum_post_<%= forum_post.id %>" data-forum-post-id="<%= forum_post.id %>" data-creator="<%= forum_post.creator.name %>">
<div class="author">
@@ -23,7 +25,7 @@
<% if CurrentUser.is_member? && @forum_topic %>
<li><%= link_to "Quote", new_forum_post_path(:post_id => forum_post.id), :method => :get, :remote => true %></li>
<% end %>
<% if CurrentUser.is_moderator? && !forum_post.is_original_post? %>
<% if CurrentUser.is_moderator? && !forum_post.is_original_post?(original_forum_post_id) %>
<% if forum_post.is_deleted %>
<li><%= link_to "Undelete", undelete_forum_post_path(forum_post.id), :method => :post, :remote => true %></li>
<% else %>
@@ -31,7 +33,7 @@
<% end %>
<% end %>
<% if forum_post.editable_by?(CurrentUser.user) %>
<% if forum_post.is_original_post? %>
<% if forum_post.is_original_post?(original_forum_post_id) %>
<li><%= link_to "Edit", edit_forum_topic_path(forum_post.topic), :id => "edit_forum_topic_link_#{forum_post.topic.id}", :class => "edit_forum_topic_link" %></li>
<% else %>
<li><%= link_to "Edit", edit_forum_post_path(forum_post.id), :id => "edit_forum_post_link_#{forum_post.id}", :class => "edit_forum_post_link" %></li>
@@ -42,9 +44,14 @@
<% else %>
<li><%= link_to "Permalink", forum_post_path(forum_post) %></li>
<% end %>
<% if forum_post.is_original_post?(original_forum_post_id) %>
<ul class="votes" id="forum-post-votes-for-<%= forum_post.id %>">
<%= render "forum_post_votes/list", votes: forum_post.votes, forum_post: forum_post %>
</ul>
<% end %>
</menu>
<% if forum_post.editable_by?(CurrentUser.user) %>
<% if forum_post.is_original_post? %>
<% if forum_post.is_original_post?(original_forum_post_id) %>
<%= render "forum_topics/form", :forum_topic => forum_post.topic %>
<% else %>
<%= render "forum_posts/partials/edit/form", :forum_post => forum_post %>

View File

@@ -1,6 +1,9 @@
<%- # forum_post %>
<%- # original_forum_post_id %>
<div class="list-of-forum-posts">
<% forum_posts.each do |forum_post| %>
<%= render "forum_posts/forum_post", :forum_post => forum_post %>
<%= render "forum_posts/forum_post", :forum_post => forum_post, :original_forum_post_id => original_forum_post_id %>
<% end %>
</div>

View File

@@ -1,7 +1,7 @@
<div id="c-forum-posts">
<div id="a-show" class="single-forum-post list-of-forum-posts">
<h1>Topic: <%= @forum_post.topic.title %></h1>
<%= render "forum_post", :forum_post => @forum_post %>
<%= render "forum_post", :forum_post => @forum_post, :original_forum_post_id => @forum_post.topic.original_post.id %>
</div>
</div>

View File

@@ -20,7 +20,7 @@
</div>
<% end %>
<%= render "forum_posts/listing", :forum_posts => @forum_posts %>
<%= render "forum_posts/listing", :forum_posts => @forum_posts, :original_forum_post_id => @forum_topic.original_post.id %>
<% if CurrentUser.is_member? %>
<% if CurrentUser.is_moderator? || !@forum_topic.is_locked? %>

View File

@@ -7,9 +7,9 @@
<%= csrf_meta_tag %>
<%= auto_discovery_link_tag :atom, posts_path(:format => "atom", :tags => params[:tags]) %>
<%= stylesheet_link_tag "application", :media => "screen" %>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<%= javascript_include_tag "application" %>
<%= Danbooru.config.custom_html_header_content %>
<meta name="enable-auto-complete" content="<%= CurrentUser.user.enable_auto_complete %>">
<%= yield :html_header %>
</head>
<body lang="en">

View File

@@ -71,6 +71,7 @@
"url" : "<%= root_url %>"
}
</script>
<script defer src="https://use.fontawesome.com/releases/v5.0.10/js/all.js" integrity="sha384-slN8GvtUJGnv6ca26v8EzVaR9DC58QEwsIk9q1QXdCU8Yu8ck/tL/5szYlBbqmS+" crossorigin="anonymous"></script>
</head>
<body lang="en" <%= body_attributes(CurrentUser.user) %>>
<header id="top">