post votes: add index page.
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
class PostVotesController < ApplicationController
|
||||
before_action :voter_only
|
||||
before_action :voter_only, only: [:create, :destroy]
|
||||
skip_before_action :api_check
|
||||
respond_to :js, :json, :xml
|
||||
respond_to :js, :json, :xml, :html
|
||||
rescue_with PostVote::Error, status: 422
|
||||
|
||||
def index
|
||||
@post_votes = PostVote.includes(:post, :user).paginated_search(params)
|
||||
respond_with(@post_votes)
|
||||
end
|
||||
|
||||
def create
|
||||
@post = Post.find(params[:post_id])
|
||||
@post.vote!(params[:score])
|
||||
|
||||
@@ -23,6 +23,18 @@ class PostVote < ApplicationRecord
|
||||
select_values_sql("select post_id from post_votes where score > 0 and user_id = ?", user_id)
|
||||
end
|
||||
|
||||
def self.visible(user = CurrentUser.user)
|
||||
return all if user.is_admin?
|
||||
where(user: user)
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
q = super
|
||||
q = q.visible
|
||||
q = q.search_attributes(params, :post, :user, :score)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
def initialize_attributes
|
||||
self.user_id ||= CurrentUser.user.id
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<span>
|
||||
<span id="score-for-post-<%= post.id %>"><%= post.score %></span>
|
||||
<% if CurrentUser.is_voter? %>
|
||||
(vote <%= link_to(content_tag("i", nil, class: "far fa-thumbs-up"), post_votes_path(:score => "up", :post_id => post.id), :remote => true, :method => :post) %>/<%= link_to(content_tag("i", nil, class: "far fa-thumbs-down"), post_votes_path(:score => "down", :post_id => post.id), :remote => true, :method => :post) %>)
|
||||
(vote <%= link_to(content_tag("i", nil, class: "far fa-thumbs-up"), post_post_votes_path(:score => "up", :post_id => post.id), :remote => true, :method => :post) %>/<%= link_to(content_tag("i", nil, class: "far fa-thumbs-down"), post_post_votes_path(:score => "down", :post_id => post.id), :remote => true, :method => :post) %>)
|
||||
<% end %>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
46
app/views/post_votes/index.html.erb
Normal file
46
app/views/post_votes/index.html.erb
Normal file
@@ -0,0 +1,46 @@
|
||||
<div id="c-post-votes">
|
||||
<div id="a-index">
|
||||
<%= search_form_for(post_votes_path) do |f| %>
|
||||
<%= f.input :user_name, label: "User", input_html: { value: params[:search][:user_name], "data-autocomplete": "user" } %>
|
||||
<%= f.input :post_id, label: "Post", input_html: { value: params[:search][:post_id] } %>
|
||||
<%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match], "data-autocomplete": "tag-query" } %>
|
||||
<%= f.input :score, collection: [["+3", "3"], ["+1", "1"], ["-1", "-1"], ["-3", "-3"]], include_blank: true, selected: params[:search][:score] %>
|
||||
<%= f.submit "Search" %>
|
||||
<% end %>
|
||||
|
||||
<table class="striped autofit">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Post</th>
|
||||
<th>Tags</th>
|
||||
<th>Score</th>
|
||||
<th>Created</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @post_votes.each do |vote| %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= PostPresenter.preview(vote.post, show_deleted: true) %>
|
||||
</td>
|
||||
<td class="col-expand">
|
||||
<%= TagSetPresenter.new(vote.post.tag_array).inline_tag_list_html %>
|
||||
</td>
|
||||
<td><%= link_to sprintf("%+d", vote.score), post_votes_path(search: { score: vote.score }) %></td>
|
||||
<td>
|
||||
<%= link_to_user vote.user %>
|
||||
<%= link_to "»", post_votes_path(search: { user_name: vote.user.name }) %>
|
||||
<div><%= time_ago_in_words_tagged(vote.created_at) %></div>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to "undo", post_post_votes_path(vote.post), remote: true, method: :delete %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= numbered_paginator(@post_votes) %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -22,11 +22,11 @@
|
||||
<% if CurrentUser.is_voter? %>
|
||||
<%= tag.span id: "vote-links-for-post-#{post.id}", style: ("display: none;" if !@post.can_be_voted_by?(CurrentUser.user)) do %>
|
||||
(vote
|
||||
<%= link_to tag.i(class: "far fa-thumbs-up"), post_votes_path(post_id: post.id, score: "up"), remote: true, method: :post %>
|
||||
<%= link_to tag.i(class: "far fa-thumbs-down"), post_votes_path(post_id: post.id, score: "down"), remote: true, method: :post %>)
|
||||
<%= link_to tag.i(class: "far fa-thumbs-up"), post_post_votes_path(post_id: post.id, score: "up"), remote: true, method: :post %>
|
||||
<%= link_to tag.i(class: "far fa-thumbs-down"), post_post_votes_path(post_id: post.id, score: "down"), remote: true, method: :post %>)
|
||||
<% end %>
|
||||
<%= tag.span id: "unvote-link-for-post-#{post.id}", style: ("display: none;" if @post.can_be_voted_by?(CurrentUser.user)) do %>
|
||||
(<%= link_to "undo vote", post_votes_path(post), remote: true, method: :delete, class: "unvote-post-link" %>)
|
||||
(<%= link_to "undo vote", post_post_votes_path(post), remote: true, method: :delete, class: "unvote-post-link" %>)
|
||||
<% end %>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
<li><%= link_to("Upload Listing", uploads_path) %></li>
|
||||
<li><%= link_to("Popular", popular_explore_posts_path) %></li>
|
||||
<li><%= link_to("Most Viewed", viewed_explore_posts_path) %></li>
|
||||
<li><%= link_to("Votes", post_votes_path) %></li>
|
||||
<% if CurrentUser.can_approve_posts? %>
|
||||
<li><%= link_to("Moderate", moderator_post_queue_path) %></li>
|
||||
<% end %>
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<li><%= link_to("Mass Edit", edit_moderator_tag_path) %></li>
|
||||
<% end %>
|
||||
<li><%= link_to("Similar Images Search", iqdb_queries_path) %></li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><h1>Post Events</h1></li>
|
||||
@@ -36,6 +36,7 @@
|
||||
<li><%= link_to("Bookmarklet", bookmarklet_path) %></li>
|
||||
<li><%= link_to("User Scripts", wiki_pages_path(title: "about:userscripts")) %></li>
|
||||
<li><%= link_to("API Documentation", wiki_pages_path(:title => "help:api")) %></li>
|
||||
<li><%= link_to("Similar Images Search", iqdb_queries_path) %></li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><h1>Artists</h1></li>
|
||||
|
||||
Reference in New Issue
Block a user