uploads: add more search options for /uploads listing (#3657).
This commit is contained in:
@@ -391,19 +391,65 @@ class Upload < ApplicationRecord
|
||||
where(:status => "pending")
|
||||
end
|
||||
|
||||
def post_tags_match(query)
|
||||
PostQueryBuilder.new(query).build(self.joins(:post)).reorder("")
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = super
|
||||
|
||||
if params[:uploader_id].present?
|
||||
q = q.uploaded_by(params[:uploader_id].to_i)
|
||||
q = q.attribute_matches(:uploader_id, params[:uploader_id])
|
||||
end
|
||||
|
||||
if params[:uploader_name].present?
|
||||
q = q.where("uploader_id = (select _.id from users _ where lower(_.name) = ?)", params[:uploader_name].mb_chars.downcase)
|
||||
q = q.where(uploader_id: User.name_to_id(params[:uploader_name]))
|
||||
end
|
||||
|
||||
if params[:source].present?
|
||||
q = q.where("source = ?", params[:source])
|
||||
q = q.where(source: params[:source])
|
||||
end
|
||||
|
||||
if params[:source_matches].present?
|
||||
q = q.where("uploads.source LIKE ? ESCAPE E'\\\\'", params[:source_matches].to_escaped_for_sql_like)
|
||||
end
|
||||
|
||||
if params[:rating].present?
|
||||
q = q.where(rating: params[:rating])
|
||||
end
|
||||
|
||||
if params[:parent_id].present?
|
||||
q = q.attribute_matches(:rating, params[:parent_id])
|
||||
end
|
||||
|
||||
if params[:post_id].present?
|
||||
q = q.attribute_matches(:post_id, params[:post_id])
|
||||
end
|
||||
|
||||
if params[:has_post] == "yes"
|
||||
q = q.where.not(post_id: nil)
|
||||
elsif params[:has_post] == "no"
|
||||
q = q.where(post_id: nil)
|
||||
end
|
||||
|
||||
if params[:post_tags_match].present?
|
||||
q = q.post_tags_match(params[:post_tags_match])
|
||||
end
|
||||
|
||||
if params[:status].present?
|
||||
q = q.where("uploads.status LIKE ? ESCAPE E'\\\\'", params[:status].to_escaped_for_sql_like)
|
||||
end
|
||||
|
||||
if params[:backtrace].present?
|
||||
q = q.where("uploads.backtrace LIKE ? ESCAPE E'\\\\'", params[:backtrace].to_escaped_for_sql_like)
|
||||
end
|
||||
|
||||
if params[:tag_string].present?
|
||||
q = q.where("uploads.tag_string LIKE ? ESCAPE E'\\\\'", params[:tag_string].to_escaped_for_sql_like)
|
||||
end
|
||||
|
||||
if params[:server].present?
|
||||
q = q.where(server: params[:server])
|
||||
end
|
||||
|
||||
q.apply_default_order(params)
|
||||
|
||||
8
app/views/uploads/_search.html.erb
Normal file
8
app/views/uploads/_search.html.erb
Normal file
@@ -0,0 +1,8 @@
|
||||
<%= simple_form_for(:search, url: uploads_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= f.input :uploader_name, label: "Uploader", input_html: { value: params[:search][:uploader_name] } %>
|
||||
<%= f.input :post_tags_match, label: "Post Tags", input_html: { value: params[:search][:post_tags_match] } %>
|
||||
<%= f.input :source_matches, label: "Source", input_html: { value: params[:search][:source_matches] } %>
|
||||
<%= f.input :status, collection: [%w[Completed completed], %w[Processing processing], %w[Pending pending], %w[Duplicate *duplicate*], %w[Error error*]], include_blank: true, selected: params[:search][:status] %>
|
||||
|
||||
<%= f.submit "Search" %>
|
||||
<% end %>
|
||||
@@ -1,5 +1,7 @@
|
||||
<div id="c-uploads">
|
||||
<div id="a-index">
|
||||
<%= render "uploads/search" %>
|
||||
|
||||
<table width="100%" class="striped">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
@@ -63,18 +63,28 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "index action" do
|
||||
setup do
|
||||
as_user do
|
||||
@upload = create(:source_upload)
|
||||
@upload = create(:source_upload, tag_string: "foo bar")
|
||||
end
|
||||
end
|
||||
|
||||
should "render" do
|
||||
get_auth uploads_path, @user
|
||||
get uploads_path
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
context "with search parameters" do
|
||||
should "render" do
|
||||
get_auth uploads_path, @user, params: {:search => {:source => @upload.source}}
|
||||
search_params = {
|
||||
uploader_name: @upload.uploader_name,
|
||||
source_matches: @upload.source,
|
||||
rating: @upload.rating,
|
||||
has_post: "yes",
|
||||
post_tags_match: @upload.tag_string,
|
||||
status: @upload.status,
|
||||
server: @upload.server,
|
||||
}
|
||||
|
||||
get uploads_path, params: { search: search_params }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user