post versions: add more search options to /post_versions/search.

This commit is contained in:
evazion
2019-09-26 16:35:05 -05:00
parent 3341223b40
commit 12de26d2cf
3 changed files with 12 additions and 28 deletions

View File

@@ -18,36 +18,12 @@ class PostArchive < ApplicationRecord
end
module SearchMethods
def for_user(user_id)
if user_id
where("updater_id = ?", user_id)
else
none
end
end
def for_user_name(name)
user_id = User.name_to_id(name)
for_user(user_id)
end
def search(params)
q = super
q = q.search_attributes(params, :updater_id, :post_id, :rating, :rating_changed, :parent_id, :parent_changed, :source, :source_changed, :version)
if params[:updater_name].present?
q = q.for_user_name(params[:updater_name])
end
if params[:updater_id].present?
q = q.where(updater_id: params[:updater_id].split(",").map(&:to_i))
end
if params[:post_id].present?
q = q.where(post_id: params[:post_id].split(",").map(&:to_i))
end
if params[:start_id].present?
q = q.where("id <= ?", params[:start_id].to_i)
q = q.where(updater_id: User.name_to_id(params[:updater_name]))
end
q.apply_default_order(params)

View File

@@ -97,7 +97,7 @@ class User < ApplicationRecord
has_many :post_disapprovals, :dependent => :destroy
has_many :post_flags, foreign_key: :creator_id
has_many :post_votes
has_many :post_archives
has_many :post_versions, class_name: "PostArchive", foreign_key: :updater_id
has_many :bans, -> {order("bans.id desc")}
has_one :recent_ban, -> {order("bans.id desc")}, :class_name => "Ban"
@@ -668,7 +668,7 @@ class User < ApplicationRecord
self.class.without_timeout do
User.where(id: id).update_all(
post_upload_count: posts.count,
post_update_count: PostArchive.for_user(id).count,
post_update_count: post_versions.count,
note_update_count: note_versions.count
)
end

View File

@@ -3,8 +3,16 @@
<h1>Search Changes</h1>
<%= search_form_for(post_versions_path) do |f| %>
<%= f.input :updated_at, label: "Date" %>
<%= f.input :updater_name, label: "Updater", input_html: { "data-autocomplete": "user" } %>
<%= f.input :post_id %>
<%= f.input :parent_id %>
<%= f.input :rating %>
<%= f.input :source_ilike, label: "Source", hint: "Use * for wildcard" %>
<%= f.input :version %>
<%= f.input :rating_changed, as: :select %>
<%= f.input :parent_changed, as: :select %>
<%= f.input :source_changed, as: :select %>
<%= f.submit "Search" %>
<% end %>
</div>