[Search] Add custom input type for users

Automatically adds name/id search
This commit is contained in:
Earlopain 2023-08-04 17:04:43 +02:00
parent 79bada3392
commit cc379af5eb
No known key found for this signature in database
GPG Key ID: 48860312319ADF61
31 changed files with 59 additions and 54 deletions

View File

@ -6,8 +6,16 @@ class FormFieldCollector
@fields = []
end
def input(input_name, *)
@fields.push input_name
def input(input_name, **)
@fields.push(input_name)
end
def user(input_prefix, **)
if input_prefix.is_a?(Array)
@fields.push(*input_prefix)
else
@fields.push(:"#{input_prefix}_id", :"#{input_prefix}_name")
end
end
# Swallow the rest

View File

@ -7,6 +7,16 @@ class SearchFormBuilder < SimpleForm::FormBuilder
super
end
def user(user_attribute, **args)
name_attribute = user_attribute.is_a?(Symbol) ? :"#{user_attribute}_name" : user_attribute[0]
id_attribute = user_attribute.is_a?(Symbol) ? :"#{user_attribute}_id" : user_attribute[1]
label = args[:label] || user_attribute.capitalize
name_input = input(name_attribute, { **args.deep_dup, label: label, autocomplete: "user" })
id_input = input(id_attribute, { **args, label: "#{label} ID", hide_unless_value: true })
name_input + id_input
end
private
def insert_value(value, options)

View File

@ -1,6 +1,6 @@
<%= form_search path: admin_staff_notes_path, always_display: true do |f| %>
<%= f.input :creator_name, label: "Creator Name", autocomplete: "user" %>
<%= f.input :user_name, label: "User Name", autocomplete: "user" %>
<%= f.user :creator %>
<%= f.user :user %>
<%= f.input :body_matches, label: "Body" %>
<%= f.input :without_system_user, as: :boolean, label: "Hide automated?" %>
<% end %>

View File

@ -1,5 +1,4 @@
<%= form_search(path: artist_versions_path) do |f| %>
<%= f.input :updater_name, label: "User", autocomplete: "user" %>
<%= f.input :updater_id, label: "User ID", hide_unless_value: true %>
<%= f.user :updater %>
<%= f.input :name, autocomplete: "artist" %>
<% end %>

View File

@ -1,7 +1,7 @@
<%= form_search(path: artists_path) do |f| %>
<%= f.input :any_name_matches, label: "Name", hint: "Use * for wildcard", autocomplete: "artist" %>
<%= f.input :url_matches, label: "URL", as: :string %>
<%= f.input :creator_name, label: "Creator", autocomplete: "user" %>
<%= f.user :creator %>
<%= f.input :is_active, label: "Active?", collection: [["Yes", true], ["No", false]], include_blank: true %>
<%= f.input :has_tag, label: "Has tag?", collection: [["Yes", true], ["No", false]], include_blank: true %>
<%= f.input :is_linked, label: "Linked Only", as: :boolean %>

View File

@ -1,6 +1,6 @@
<%= form_search(path: bans_path) do |f| %>
<%= f.input :user_name, label: "User", autocomplete: "user" %>
<%= f.input :banner_name, label: "Banner", autocomplete: "user" %>
<%= f.user :user %>
<%= f.user :banner %>
<%= f.input :reason_matches, label: "Reason", hint: "Use * for wildcard" %>
<%= f.input :expired, label: "Expired?", collection: [["Yes", true], ["No", false]], include_blank: true %>
<%= f.input :order, include_blank: false, collection: [%w[Created id_desc], %w[Expiration expires_at_desc]] %>

View File

@ -1,5 +1,5 @@
<%= form_search path: blips_path do |f| %>
<%= f.input :creator_name, label: "Blipper", autocomplete: "user" %>
<%= f.user :creator, label: "Blipper" %>
<%= f.input :body_matches, label: "Body" %>
<%= f.input :response_to, label: "Parent Blip #" %>
<% if CurrentUser.is_admin? %>

View File

@ -1,6 +1,6 @@
<%= form_search(path: bulk_update_requests_path) do |f| %>
<%= f.input :user_name, label: "Creator", autocomplete: "user" %>
<%= f.input :approver_name, label: "Approver", autocomplete: "user" %>
<%= f.user :user, label: "Creator" %>
<%= f.user :approver %>
<%= f.input :title_matches, label: "Title" %>
<%= f.input :script_matches, label: "Script" %>
<%= f.input :status, label: "Status", collection: %w[pending approved rejected], include_blank: true %>

View File

@ -1,7 +1,6 @@
<%= form_search(path: comments_path) do |f| %>
<%= hidden_field_tag "group_by", "comment", id: "group_by_full" %>
<%= f.input :creator_name, label: "Commenter", autocomplete: "user" %>
<%= f.input :creator_id, label: "Commenter ID", hide_unless_value: true %>
<%= f.user :creator, label: "Commenter" %>
<%= f.input :body_matches, label: "Body" %>
<%= f.input :post_tags_match, label: "Tags", autocomplete: "tag-query" %>
<% if CurrentUser.is_admin? %>

View File

@ -2,6 +2,6 @@
<%= f.hidden_field :folder, value: params[:folder] %>
<%= f.input :title_matches, label: "Title", hint: "Use * for wildcard" %>
<%= f.input :message_matches, label: "Message", hint: "Use * for wildcard" %>
<%= f.input :to_name, label: "To" %>
<%= f.input :from_name, label: "From", autocomplete: "user" %>
<%= f.user :to %>
<%= f.user :from %>
<% end %>

View File

@ -1,7 +1,6 @@
<%= form_search(path: forum_posts_path) do |f| %>
<%= f.input :topic_title_matches, label: "Title" %>
<%= f.input :body_matches, label: "Body" %>
<%= f.input :creator_name, label: "Author", autocomplete: "user" %>
<%= f.input :creator_id, label: "Author ID", hide_unless_value: true %>
<%= f.user :creator, label: "Author" %>
<%= f.input :topic_category_id, label: "Category", collection: ForumCategory.visible.reverse_mapping, include_blank: true %>
<% end %>

View File

@ -4,7 +4,7 @@
<%= form_search(path: ip_bans_path) do |f| %>
<%= f.input :ip_addr, label: "IP Address" %>
<%= f.input :banner_name, label: "Banner" %>
<%= f.user :banner %>
<%= f.input :reason %>
<% end %>

View File

@ -1,4 +1,4 @@
<%= form_search(path: mod_actions_path) do |f| %>
<%= f.input :creator_name, label: "Creator", autocomplete: "user" %>
<%= f.user :creator %>
<%= f.input :action, label: "Action", collection: ModAction::KnownActions.map {|k| [k.to_s.capitalize.tr("_"," "), k.to_s]}, include_blank: true %>
<% end %>

View File

@ -3,7 +3,7 @@
<h1>Disapprovals</h1>
<%= form_search(path: moderator_post_disapprovals_path) do |f| %>
<%= f.input :creator_name, label: "Creator", autocomplete: "user" %>
<%= f.user :creator %>
<%= f.input :post_id, label: "Post ID" %>
<%= f.input :post_tags_match, label: "Tags", autocomplete: "tag-query" %>
<%= f.input :message, hint: "Use * for wildcard" %>

View File

@ -1,7 +1,6 @@
<%= form_search(path: note_versions_path) do |f| %>
<%= f.input :body_matches, label: "Body" %>
<%= f.input :updater_name, label: "User", autocomplete: "user" %>
<%= f.input :updater_id, label: "User ID", hide_unless_value: true %>
<%= f.user :updater, label: "Editor" %>
<%= f.input :post_id, label: "Post #"%>
<%= f.input :note_id, label: "Note #"%>
<% end %>

View File

@ -1,6 +1,6 @@
<%= form_search(path: notes_path) do |f| %>
<%= f.input :body_matches, label: "Body" %>
<%= f.input :creator_name, label: "Author", autocomplete: "user" %>
<%= f.user :creator, label: "Author" %>
<%= f.input :post_id, label: "Post #"%>
<%= f.input :post_tags_match, label: "Tags", autocomplete: "tag-query" %>
<%= f.input :is_active, label: "Status", collection: [["Active", "true"], ["Deleted", "false"]], :include_blank => true %>

View File

@ -1,7 +1,7 @@
<%= form_search(path: request.path) do |f| %>
<%= f.input :name_matches, label: "Name", autocomplete: "pool" %>
<%= f.input :description_matches, label: "Description" %>
<%= f.input :creator_name, label: "Creator", autocomplete: "user" %>
<%= f.user :creator %>
<%= f.input :is_active, label: "Status", collection: [["Active", "true"], ["Inactive", "false"]], :include_blank => true %>
<%= f.input :category, label: "Category", collection: [["Series", "series"], ["Collection", "collection"]], :include_blank => true %>
<%= f.input :order, label: "Order", collection: [["Last updated", "updated_at"], ["Name", "name"], ["Recently created", "created_at"], ["Post count", "post_count"]], :include_blank => true %>

View File

@ -4,7 +4,7 @@
<%= render "posts/partials/common/inline_blacklist" %>
<%= form_search(path: post_approvals_path) do |f| %>
<%= f.input :user_name, label: "Approver", autocomplete: "user" %>
<%= f.user :user, label: "Approver" %>
<%= f.input :post_tags_match, label: "Tags", autocomplete: "tag-query" %>
<% end %>

View File

@ -1,5 +1,5 @@
<%= form_search path: post_events_path do |f| %>
<%= f.input :post_id, label: "Post #" %>
<%= f.input :creator_name, label: "Creator", autocomplete: "user" %>
<%= f.user :creator %>
<%= f.input :action, label: "Action", collection: PostEvent.actions.keys.map {|k| [k.to_s.capitalize.tr("_"," "), k.to_s]}, include_blank: true %>
<% end %>

View File

@ -8,8 +8,7 @@
], include_blank: true %>
<%= f.input :is_resolved, label: "Resolved?", collection: [["Yes", true], ["No", false]], include_blank: true %>
<% if CurrentUser.is_janitor? %>
<%= f.input :creator_name, label: "Creator", autocomplete: "user" %>
<%= f.input :creator_id, label: "Creator ID", hide_unless_value: true %>
<%= f.user :creator %>
<% end %>
<% if CurrentUser.is_admin? %>
<%= f.input :ip_addr, label: "Ip Address" %>

View File

@ -1,11 +1,8 @@
<%= form_search(path: post_replacements_path) do |f| %>
<%= f.input :md5, label: "MD5" %>
<%= f.input :post_id, label: "Post ID" %>
<%= f.input :creator_name, label: "Creator", autocomplete: "user" %>
<%= f.input :creator_id, label: "Creator ID", hide_unless_value: true %>
<%= f.input :approver_name, label: "Approver", autocomplete: "user" %>
<%= f.input :approver_id, label: "Approver ID", hide_unless_value: true %>
<%= f.input :uploader_name_on_approve, label: "Original Uploader", autocomplete: "user" %>
<%= f.input :uploader_id_on_approve, label: "Original Uploader ID", hide_unless_value: true %>
<%= f.user :creator %>
<%= f.user :approver %>
<%= f.user %i[uploader_name_on_approve uploader_id_on_approve], label: "Original Uploader" %>
<%= f.input :status, collection: ["pending", "rejected", "approved", "promoted"], include_blank: true %>
<% end %>

View File

@ -1,7 +1,7 @@
<%= form_search path: post_sets_path do |f| %>
<%= f.input :name, label: "Name" %>
<%= f.input :shortname, label: "Short Name" %>
<%= f.input :creator_name, label: "Username", autocomplete: "user" %>
<%= f.user :creator %>
<% if CurrentUser.is_moderator? %>
<%= f.input :is_public, label: "Public?", collection: [["Yes", true], ["No", false]], include_blank: true %>
<% end %>

View File

@ -1,6 +1,5 @@
<%= form_search path: post_versions_path do |f| %>
<%= f.input :updater_name, label: "User", autocomplete: "user" %>
<%= f.input :updater_id, label: "User ID" %>
<%= f.user :updater, label: "User" %>
<%= f.input :post_id, label: "Post #" %>
<%= f.input :reason, label: "Reason" %>
<%= f.input :description, label: "Description" %>

View File

@ -4,8 +4,8 @@
<%= f.input :name_matches, label: "Name", autocomplete: "tag", hint: "Use * for wildcard" %>
<%= f.input :antecedent_name, label: "From", autocomplete: "tag" %>
<%= f.input :consequent_name, label: "To", autocomplete: "tag" %>
<%= f.input :creator_name, label: "Creator", autocomplete: "user" %>
<%= f.input :approver_name, label: "Approver", autocomplete: "user" %>
<%= f.user :creator %>
<%= f.user :approver %>
<%= f.input :antecedent_tag_category, label: "From Category", collection: TagCategory.canonical_mapping.to_a, include_blank: true %>
<%= f.input :consequent_tag_category, label: "To Category", collection: TagCategory.canonical_mapping.to_a, include_blank: true %>
<%= f.input :status, label: "Status", collection: %w[Approved Active Pending Deleted Retired Processing Queued], include_blank: true %>

View File

@ -1,5 +1,4 @@
<%= form_search path: tag_type_versions_path do |f| %>
<%= f.input :tag, label: "Tag" %>
<%= f.input :user_name, label: "Username", autocomplete: "user" %>
<%= f.input :user_id, label: "User ID" %>
<%= f.user :user %>
<% end %>

View File

@ -1,9 +1,7 @@
<%= form_search path: tickets_path do |f| %>
<% if CurrentUser.is_moderator? %>
<%= f.input :creator_name, label: "Reporter", autocomplete: "user" %>
<%= f.input :creator_id, label: "Reporter ID" %>
<%= f.input :accused_name, label: "Accused", autocomplete: "user" %>
<%= f.input :accused_id, label: "Accused ID" %>
<%= f.user :creator, label: "Reporter" %>
<%= f.user :accused %>
<%= f.input :reason %>
<% end %>
<%= f.input :qtype, label: "Type", collection: [

View File

@ -1,5 +1,5 @@
<%= form_search(path: uploads_path) do |f| %>
<%= f.input :uploader_name, label: "Uploader", autocomplete: "user" %>
<%= f.user :uploader %>
<%= f.input :post_tags_match, label: "Post Tags" %>
<%= f.input :source_matches, label: "Source" %>
<%= f.input :status, collection: [%w[Completed completed], %w[Processing processing], %w[Pending pending], %w[Duplicate *duplicate*], %w[Error error*]], include_blank: true %>

View File

@ -1,7 +1,6 @@
<%= form_search(path: user_feedbacks_path) do |f| %>
<%= f.input :user_name, label: "User", autocomplete: "user" %>
<%= f.input :user_id, label: "User ID", hide_unless_value: true %>
<%= f.input :creator_name, label: "Creator", autocomplete: "user" %>
<%= f.user :user %>
<%= f.user :creator %>
<%= f.input :body_matches, label: "Message" %>
<%= f.input :category, collection: %w[positive negative neutral], include_blank: true %>
<% end %>

View File

@ -1,5 +1,5 @@
<%= form_search path: user_name_change_requests_path do |f| %>
<%= f.input :current_name, label: "Current Name", autocomplete: "user" %>
<%= f.user :current %>
<%= f.input :original_name, label: "Original Name", hint: "Use * for wildcard" %>
<%= f.input :desired_name, label: "Desired Name", hint: "Use * for wildcard" %>
<% end %>

View File

@ -2,10 +2,10 @@
<div id="a-index">
<%# path is a string here because of duplicate routes %>
<%= form_search(path: type.model_name.route_key) do |f| %>
<%= f.input :user_name, label: "Voter Username", autocomplete: "user" %>
<%= f.user :user, label: "Voter" %>
<%= f.input :"#{type.model_type}_id", label: "#{type.model_type.capitalize} ID" %>
<br>
<%= f.input :"#{type.model_type}_creator_name", label: "#{type.model_type.capitalize} Creator Username", autocomplete: "user" %>
<%= f.user :"#{type.model_type}_creator", label: "#{type.model_type.capitalize} Creator" %>
<%= f.input :timeframe, label: "Timeframe", include_blank: true, collection: [["Last Week", "7"], ["Last Month", "30"], ["Last Three Months", "90"], ["Last Year", "360"]] %>
<%= f.input :score, label: "Type", include_blank: true, collection: [["Upvote", "1"], ["Locked", "0"], ["Downvote", "-1"]] %>
<% if CurrentUser.is_admin? %>

View File

@ -1,7 +1,7 @@
<%= form_search(path: wiki_pages_path) do |f| %>
<%= f.input :title, label: "Title", hint: "Use * for wildcard searches", autocomplete: "wiki-page" %>
<%= f.input :body_matches, label: "Body" %>
<%= f.input :creator_name, autocomplete: "user" %>
<%= f.user :creator %>
<%= f.input :other_names_match, label: "Other names", hint: "Use * for wildcard searches" %>
<%= f.input :other_names_present, collection: %w[Yes No], include_blank: true %>
<%= f.input :hide_deleted, collection: %w[Yes No] %>