diff --git a/app/controllers/forum_post_votes_controller.rb b/app/controllers/forum_post_votes_controller.rb index f84653cd7..b0829f37f 100644 --- a/app/controllers/forum_post_votes_controller.rb +++ b/app/controllers/forum_post_votes_controller.rb @@ -1,32 +1,27 @@ class ForumPostVotesController < ApplicationController - respond_to :js - before_action :load_forum_post - before_action :load_vote, only: [:destroy] - before_action :member_only + respond_to :html, :xml, :json, :js + before_action :member_only, only: [:create, :destroy] + + def index + @forum_post_votes = ForumPostVote.includes(creator: [], forum_post: [:topic]).paginated_search(params) + respond_with(@forum_post_votes) + end def create + @forum_post = ForumPost.find(params[:forum_post_id]) @forum_post_vote = @forum_post.votes.create(forum_post_vote_params) respond_with(@forum_post_vote) end def destroy + @forum_post_vote = CurrentUser.user.forum_post_votes.find(params[:id]) @forum_post_vote.destroy respond_with(@forum_post_vote) end private - - def load_vote - @forum_post_vote = @forum_post.votes.where(creator_id: CurrentUser.id).first - raise ActiveRecord::RecordNotFound.new if @forum_post_vote.nil? - end - def load_forum_post - @forum_post = ForumPost.find(params[:forum_post_id]) - end - def forum_post_vote_params params.fetch(:forum_post_vote, {}).permit(:score) end - end diff --git a/app/models/forum_post_vote.rb b/app/models/forum_post_vote.rb index 4a987e2bf..d2780680c 100644 --- a/app/models/forum_post_vote.rb +++ b/app/models/forum_post_vote.rb @@ -8,6 +8,12 @@ class ForumPostVote < ApplicationRecord scope :by, ->(user_id) {where(creator_id: user_id)} scope :excluding_user, ->(user_id) {where("creator_id <> ?", user_id)} + def self.search(params) + q = super + q = q.search_attributes(params, :creator, :forum_post_id, :score) + q.apply_default_order(params) + end + def up? score == 1 end diff --git a/app/models/user.rb b/app/models/user.rb index cd4b15ef2..8607e4a88 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -91,6 +91,7 @@ class User < ApplicationRecord has_many :comments, foreign_key: :creator_id has_many :wiki_page_versions, foreign_key: :updater_id has_many :feedback, :class_name => "UserFeedback", :dependent => :destroy + has_many :forum_post_votes, dependent: :destroy, foreign_key: :creator_id has_many :posts, :foreign_key => "uploader_id" has_many :post_appeals, foreign_key: :creator_id has_many :post_approvals, :dependent => :destroy diff --git a/app/views/forum_post_votes/_vote.html.erb b/app/views/forum_post_votes/_vote.html.erb index f5b9d9d23..d46d56ab3 100644 --- a/app/views/forum_post_votes/_vote.html.erb +++ b/app/views/forum_post_votes/_vote.html.erb @@ -5,7 +5,7 @@
  • <% if forum_post.tag_change_request && forum_post.tag_change_request.is_pending? && 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 content_tag(:i, nil, class: "far #{vote.fa_class}"), forum_post_vote_path(vote, format: "js"), remote: true, method: :delete %> <%= link_to_user vote.creator %> <% else %> <%= content_tag(:i, nil, class: "far #{vote.fa_class}") %> diff --git a/app/views/forum_post_votes/destroy.js.erb b/app/views/forum_post_votes/destroy.js.erb index 906bd0807..852f05698 100644 --- a/app/views/forum_post_votes/destroy.js.erb +++ b/app/views/forum_post_votes/destroy.js.erb @@ -1,3 +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); +var code = <%= raw render(partial: "forum_post_votes/list", locals: {forum_post: @forum_post_vote.forum_post, votes: @forum_post_vote.forum_post.votes}).to_json %>; +$("#forum-post-votes-for-<%= @forum_post_vote.forum_post_id %>").html(code); diff --git a/app/views/forum_post_votes/index.html.erb b/app/views/forum_post_votes/index.html.erb new file mode 100644 index 000000000..5391fb6b3 --- /dev/null +++ b/app/views/forum_post_votes/index.html.erb @@ -0,0 +1,44 @@ +
    +
    + <%= search_form_for(forum_post_votes_path) do |f| %> + <%= f.input :creator_name, label: "User", input_html: { value: params[:search][:creator_name], data: { autocomplete: "user" } } %> + <%= f.input :forum_post_id, label: "Forum Post", input_html: { value: params[:search][:forum_post_id] } %> + <%= f.input :score, label: "Type", collection: [["Up", "1"], ["Meh", "0"], ["Down", "-1"]], include_blank: true, selected: params[:search][:score] %> + <%= f.submit "Search" %> + <% end %> + + + + + + + + + + + + <% @forum_post_votes.each do |forum_post_vote| %> + + + + + + + <% end %> + +
    Forum PostForum TopicTypeCreated
    + <%= link_to "Forum ##{forum_post_vote.forum_post_id}", forum_post_vote.forum_post %> + <%= link_to "»", forum_post_votes_path(search: { forum_post_id: forum_post_vote.forum_post_id }) %> + + <%= link_to forum_post_vote.forum_post.topic.title, forum_post_vote.forum_post.topic %> + + <%= forum_post_vote.vote_type %> + + <%= link_to_user forum_post_vote.creator %> + <%= link_to "»", forum_post_votes_path(search: { creator_name: forum_post_vote.creator.name }) %> +

    <%= time_ago_in_words_tagged(forum_post_vote.updated_at) %>

    +
    + + <%= numbered_paginator(@forum_post_votes) %> +
    +
    diff --git a/app/views/static/site_map.html.erb b/app/views/static/site_map.html.erb index 7230f56f4..e33c610f5 100644 --- a/app/views/static/site_map.html.erb +++ b/app/views/static/site_map.html.erb @@ -94,6 +94,7 @@
  • <%= link_to("Help", wiki_pages_path(:title => "help:forum")) %>
  • <%= link_to("Listing", forum_topics_path) %>
  • <%= link_to("Search", search_forum_posts_path) %>
  • +
  • <%= link_to("Votes", forum_post_votes_path) %>
  • <%= link_to("RSS", forum_topics_path(:atom)) %>