views: migrate search forms to use simple form.

Migrate various forms to be built using simple form instead of raw html.
Also adds autocomplete="off" to these forms (#4162).
This commit is contained in:
evazion
2019-09-10 14:29:07 -05:00
parent 1743f3797f
commit a1b48f5e3f
13 changed files with 68 additions and 177 deletions

View File

@@ -10,12 +10,12 @@ module Moderator
def show
cookies.permanent[:moderated] = Time.now.to_i
if params[:per_page]
cookies.permanent["mq_per_page"] = params[:per_page]
if search_params[:per_page]
cookies.permanent["mq_per_page"] = search_params[:per_page]
end
::Post.without_timeout do
@posts = ::Post.includes(:disapprovals, :uploader).order("posts.id asc").pending_or_flagged.available_for_moderation(params[:hidden]).tag_match(params[:query]).paginate(params[:page], :limit => per_page)
@posts = ::Post.includes(:disapprovals, :uploader).order("posts.id asc").pending_or_flagged.available_for_moderation(search_params[:hidden]).tag_match(search_params[:tags]).paginate(params[:page], :limit => per_page)
@posts.each # hack to force rails to eager load
end
respond_with(@posts)
@@ -45,7 +45,7 @@ module Moderator
end
def per_page
cookies["mq_per_page"] || params[:per_page] || 25
cookies["mq_per_page"] || search_params[:per_page] || 25
end
end
end

View File

@@ -8,11 +8,11 @@ module Moderator
def execute
if params[:user_id].present?
search_by_user_id(params[:user_id].split(/,/).map(&:strip))
search_by_user_id(params[:user_id].split)
elsif params[:user_name].present?
search_by_user_name(params[:user_name].split(/,/).map(&:strip))
search_by_user_name(params[:user_name].split)
elsif params[:ip_addr].present?
search_by_ip_addr(params[:ip_addr].split(/,/).map(&:strip))
search_by_ip_addr(params[:ip_addr].split)
else
[]
end

View File

@@ -2,13 +2,11 @@
<div id="a-search">
<h1>Search Changes</h1>
<div id="search">
<%= form_tag(artist_versions_path, :method => :get, :class => "simple_form") do %>
<%= search_field "updater_name", :label => "User", :data => { autocomplete: "user" } %>
<%= search_field "name", :label => "Name", :data => { autocomplete: "artist" } %>
<%= submit_tag "Search" %>
<% end %>
</div>
<%= search_form_for(artist_versions_path) do |f| %>
<%= f.input :updater_name, label: "Updater", input_html: { value: params.dig(:search, :updater_name), "data-autocomplete": "user" } %>
<%= f.input :name, label: "Artist", input_html: { value: params.dig(:search, :name), "data-autocomplete": "artist" } %>
<%= f.submit "Search" %>
<% end %>
</div>
</div>

View File

@@ -1,15 +1,13 @@
<div id="c-forum-posts">
<div id="a-search">
<h1>Search Forum</h1>
<%= form_tag(forum_posts_path, :method => :get, :class => "simple_form") do %>
<%= search_field "topic_title_matches", :label => "Title" %>
<%= search_field "body_matches", :label => "Body" %>
<%= search_field "creator_name", :label => "Author", :data => { autocomplete: "user" } %>
<div class="input">
<label for="search_topic_category_id">Category</label>
<%= select "search", "topic_category_id", ForumTopic::CATEGORIES.invert.to_a, :include_blank => true %>
</div>
<%= submit_tag "Search" %>
<%= search_form_for(forum_posts_path) do |f| %>
<%= f.input :topic_title_matches, label: "Title" %>
<%= f.input :body_matches, label: "Body" %>
<%= f.input :creator_name, label: "Creator", input_html: { "data-autocomplete": "user" } %>
<%= f.input :topic_category_id, label: "Category", collection: ForumTopic::CATEGORIES.invert.to_a, include_blank: true %>
<%= f.submit "Search" %>
<% end %>
</div>
</div>

View File

@@ -3,9 +3,9 @@
<h1>MetaSearch Tags</h1>
<section>
<%= form_tag(meta_searches_tags_path, :method => :get) do %>
<%= text_field_tag "name", params[:name], :data => { :autocomplete => "tag" } %>
<%= submit_tag "Go" %>
<%= search_form_for(meta_searches_tags_path) do |f| %>
<%= f.input :name, input_html: { value: params.dig(:search, :name), "data-autocomplete": "tag" } %>
<%= f.submit "Search" %>
<% end %>
</section>

View File

@@ -1,19 +1,5 @@
<%= form_tag(moderator_ip_addrs_path, :method => :get, :class => "simple_form") do %>
<div class="input">
<label for="user_ids">Search IPs</label>
<%= text_field_tag "search[ip_addr]", params[:ip_addrs] %>
<span class="hint">Separate with commas</span>
</div>
<%= submit_tag "Search" %>
<% end %>
<%= form_tag(moderator_ip_addrs_path, :method => :get, :class => "simple_form") do %>
<div class="input">
<label for="user_names">Search User Names</label>
<%= text_field_tag "search[user_name]", params[:user_names], data: { autocomplete: "user" } %>
<span class="hint">Separate with commas</span>
</div>
<%= submit_tag "Search" %>
<%= search_form_for(moderator_ip_addrs_path) do |f| %>
<%= f.input :ip_addr, label: "IPs ", hint: "Separate with spaces", input_html: { value: params.dig(:search, :ip_addr) } %>
<%= f.input :user_name, label: "Users", hint: "Separate with spaces", input_html: { value: params.dig(:search, :user_name), "data-autocomplete": "user" } %>
<%= f.submit "Search" %>
<% end %>

View File

@@ -2,10 +2,10 @@
<div id="a-search">
<h1>Search IP Addresses</h1>
<%= form_tag(moderator_ip_addrs_path, :method => :get, :class => "simple_form") do %>
<%= search_field "user_name", :label => "User" %>
<%= search_field "ip_addr", :label => "IP Addr" %>
<%= submit_tag "Search" %>
<%= search_form_for(moderator_ip_addrs_path) do |f| %>
<%= f.input :ip_addr, label: "IPs ", hint: "Separate with spaces", input_html: { value: params.dig(:search, :ip_addr) } %>
<%= f.input :user_name, label: "Users", hint: "Separate with spaces", input_html: { value: params.dig(:search, :user_name), "data-autocomplete": "user" } %>
<%= f.submit "Search" %>
<% end %>
</div>
</div>

View File

@@ -3,13 +3,11 @@
<div>
<h1>Moderation Queue</h1>
<div id="search">
<%= form_tag(moderator_post_queue_path, :method => :get) do %>
<%= text_field_tag "query", params[:query], :size => 40, :data => { :autocomplete => "tag-query" } %>
<%= select_tag "per_page", options_for_select(%w(25 50 100 200), cookies["mq_per_page"])%>
<%= submit_tag "Search" %>
<% end %>
</div>
<%= search_form_for(moderator_post_queue_path) do |f| %>
<%= f.input :tags, input_html: { value: params.dig(:search, :tags), "data-autocomplete": "tag-query" } %>
<%= f.input :per_page, label: "Posts", collection: %w[25 50 100 200], selected: cookies[:mq_per_page] %>
<%= f.submit "Search" %>
<% end %>
<div id="moderation-guideline">
<h1>Deletion Guidelines</h1>
@@ -17,10 +15,10 @@
<%= render "desc" %>
<p>
<% if params[:hidden] %>
<%= link_to "View pending posts", moderator_post_queue_path(:query => params[:query], :hidden => nil) %>.
<% if params.dig(:search, :hidden) %>
<%= link_to "View pending posts", moderator_post_queue_path(search: { tags: params.dig(:search, :tags), hidden: nil }) %>.
<% else %>
<%= link_to "View hidden posts", moderator_post_queue_path(:query => params[:query], :hidden => true) %>.
<%= link_to "View hidden posts", moderator_post_queue_path(search: { tags: params.dig(:search, :tags), hidden: true, }) %>.
<% end %>
</p>
</div>

View File

@@ -1,72 +1,10 @@
<table class="search">
<tbody>
<%= form_tag path, :method => :get, :class => "simple_form" do %>
<tr>
<th><label for="search_name_matches">Name</label></th>
<td>
<div class="input">
<%= text_field "search", "name_matches", :value => params[:search][:name_matches], :data => { autocomplete: "pool" } %>
</div>
</td>
</tr>
<tr>
<th><label for="search_description_matches">Description</label></th>
<td>
<div class="input">
<%= text_field "search", "description_matches", :value => params[:search][:description_matches] %>
</div>
</td>
</tr>
<tr>
<th><label for="search_post_tags">Post Tags</th>
<td>
<div class="input">
<%= text_field "search", "post_tags_match", :value => params[:search][:post_tags_match], :data => { autocomplete: "tag-query" } %>
</div>
</td>
</tr>
<tr>
<th><label for="search_creator_name">Creator</th>
<td>
<div class="input">
<%= text_field "search", "creator_name", :value => params[:search][:creator_name], :data => { autocomplete: "pool" } %>
</div>
</td>
</tr>
<tr>
<th><label for="search_is_active">Status</th>
<td>
<div class="input">
<%= select "search", "is_active", ["", ["Active", "true"], ["Inactive", "false"]], :selected => params[:search][:is_active] %>
</div>
</td>
</tr>
<tr>
<th><label for="search_category">Category</th>
<td>
<div class="input">
<%= select "search", "category", [["Series", "series"], ["Collection", "collection"]], :selected => params[:search][:category], :include_blank => true %>
</div>
</td>
</tr>
<tr>
<th><label for="search_order">Order</th>
<td>
<div class="input">
<%= select "search", "order", [["Last updated", "updated_at"], ["Name", "name"], ["Recently created", "created_at"], ["Post count", "post_count"]], :selected => params[:search][:order], :include_blank => true %>
</div>
</td>
</tr>
<tr>
<td><%= submit_tag "Search" %></td>
</tr>
<% end %>
</tbody>
</table>
<%= search_form_for(path) do |f| %>
<%= f.input :name_matches, label: "Name", input_html: { value: params.dig(:search, :name_matches), "data-autocomplete": "pool" } %>
<%= f.input :description_matches, label: "Description", input_html: { value: params.dig(:search, :description_matches) } %>
<%= f.input :post_tags_match, label: "Post tags", input_html: { value: params.dig(:search, :post_tags_match), "data-autocomplete": "tag-query" } %>
<%= f.input :creator_name, label: "Creator", input_html: { value: params.dig(:search, :creator_name), "data-autocomplete": "user" } %>
<%= f.input :is_active, label: "Status", as: :select, collection: [%w[Active true], %w[Inactive false]], include_blank: true, selected: params.dig(:search, :is_active) %>
<%= f.input :category, collection: %w[series collection], include_blank: true, selected: params[:search][:category] %>
<%= f.input :order, collection: [%w[Last\ updated updated_at], %w[Name name], %w[Recently\ created created_at], %w[Post\ count post_count]], include_blank: true, selected: params.dig(:search, :order) %>
<%= f.submit "Search" %>
<% end %>

View File

@@ -2,13 +2,11 @@
<div id="a-search">
<h1>Search Changes</h1>
<div id="search">
<%= form_tag(post_versions_path, :method => :get, :class => "simple_form") do %>
<%= search_field "updater_name", :label => "User", :data => { autocomplete: "user" } %>
<%= search_field "post_id", :label => "Post" %>
<%= submit_tag "Search" %>
<% end %>
</div>
<%= search_form_for(post_versions_path) do |f| %>
<%= f.input :updater_name, label: "Updater", input_html: { "data-autocomplete": "user" } %>
<%= f.input :post_id %>
<%= f.submit "Search" %>
<% end %>
</div>
</div>

View File

@@ -2,19 +2,12 @@
<div id="a-search">
<h1>Search User Feedbacks</h1>
<%= form_tag(user_feedbacks_path, :method => :get, :class => "simple_form") do %>
<%= search_field "user_name", :label => "User", :data => { autocomplete: "user" } %>
<%= search_field "creator_name", :label => "Creator", :data => { autocomplete: "user" } %>
<%= search_field "body_matches", :label => "Message" %>
<div class="input">
<label for="search_category">Category</label>
<%= select "search", "category", %w(positive negative neutral), :include_blank => true %>
</div>
<div class="input">
<%= submit_tag "Search" %>
</div>
<%= search_form_for(user_feedbacks_path) do |f| %>
<%= f.input :user_name, input_html: { value: params.dig(:search, :user_name), "data-autocomplete": "user" } %>
<%= f.input :creator_name, input_html: { value: params.dig(:search, :creator_name), "data-autocomplete": "user" } %>
<%= f.input :body_matches, label: "Message", input_html: { value: params.dig(:search, :body_matches) } %>
<%= f.input :category, collection: %w[positive negative neutral], include_blank: true, selected: params.dig(:search, :category) %>
<%= f.submit "Search" %>
<% end %>
</div>
</div>

View File

@@ -2,11 +2,6 @@
<div id="a-index">
<h1>Users</h1>
<% form_tag(users_path, :method => :get, :class => "simple_form") do %>
<%= search_field "name_matches", :label => "Name" %>
<%= submit_tag "Search" %>
<% end %>
<table width="100%" class="striped">
<thead>
<tr>

View File

@@ -1,27 +1,14 @@
<div id="c-wiki-pages">
<div id="a-search">
<%= form_tag(wiki_pages_path, :method => :get, :class => "simple_form") do %>
<%= search_field "title", :hint => "Use * for wildcard searches", :data => { :autocomplete => "wiki-page" } %>
<%= search_field "creator_name", :data => { :autocomplete => "user" } %>
<%= search_field "body_matches", :label => "Body" %>
<%= search_field "other_names_match", :label => "Other names", :hint => "Use * for wildcard searches" %>
<div class="input">
<label for="search_other_names_present">Other names present?</label>
<%= select "search", "other_names_present", ["yes", "no"], :include_blank => true %>
</div>
<div class="input">
<label for="search_order">Order</label>
<%= select "search", "order", [%w[Name title], %w[Date time], %w[Posts post_count]] %>
</div>
<div class="input">
<label for="search_hide_deleted">Hide Deleted</label>
<%= select "search", "hide_deleted", ["Yes", "No"] %>
</div>
<%= submit_tag "Search" %>
<%= search_form_for(wiki_pages_path) do |f| %>
<%= f.input :title, hint: "Use * for wildcard searches", input_html: { "data-autocomplete": "wiki-page" } %>
<%= f.input :other_names_match, label: "Other names", hint: "Use * for wildcard searches" %>
<%= f.input :creator_name, input_html: { "data-autocomplete": "user" } %>
<%= f.input :body_matches, label: "Body" %>
<%= f.input :other_names_present, as: :select %>
<%= f.input :hide_deleted, as: :select, include_blank: false %>
<%= f.input :order, collection: [%w[Name title], %w[Date time], %w[Posts post_count]], include_blank: false %>
<%= f.submit "Search" %>
<% end %>
</div>
</div>