From 896f144eb6466c15648dfd38ce3055bb7ee20ec0 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 10 Sep 2019 21:07:28 -0500 Subject: [PATCH] views: refactor quick search forms. --- app/controllers/comments_controller.rb | 2 ++ app/helpers/application_helper.rb | 8 ++++++++ app/javascript/src/styles/common/simple_form.scss | 4 ++++ app/views/artist_commentaries/_quick_search.html.erb | 3 --- app/views/artist_commentaries/_secondary_links.html.erb | 2 +- app/views/artists/_quick_search.html.erb | 3 --- app/views/artists/_secondary_links.html.erb | 2 +- app/views/comments/_quick_search.html.erb | 4 ---- app/views/comments/_secondary_links.html.erb | 2 +- app/views/dmails/_quick_search.html.erb | 3 --- app/views/dmails/_secondary_links.html.erb | 2 +- app/views/forum_posts/_quick_search.html.erb | 3 --- app/views/forum_topics/_secondary_links.html.erb | 2 +- app/views/notes/_quick_search.html.erb | 4 ---- app/views/notes/_secondary_links.html.erb | 2 +- app/views/pools/_quick_search.html.erb | 3 --- app/views/pools/_secondary_links.html.erb | 2 +- app/views/tags/_quick_search.html.erb | 3 --- app/views/tags/_secondary_links.html.erb | 2 +- app/views/users/_quick_search.html.erb | 3 --- app/views/users/_secondary_links.html.erb | 2 +- app/views/wiki_pages/_quick_search.html.erb | 3 --- app/views/wiki_pages/_secondary_links.html.erb | 2 +- 23 files changed, 24 insertions(+), 42 deletions(-) delete mode 100644 app/views/artist_commentaries/_quick_search.html.erb delete mode 100644 app/views/artists/_quick_search.html.erb delete mode 100644 app/views/comments/_quick_search.html.erb delete mode 100644 app/views/dmails/_quick_search.html.erb delete mode 100644 app/views/forum_posts/_quick_search.html.erb delete mode 100644 app/views/notes/_quick_search.html.erb delete mode 100644 app/views/pools/_quick_search.html.erb delete mode 100644 app/views/tags/_quick_search.html.erb delete mode 100644 app/views/users/_quick_search.html.erb delete mode 100644 app/views/wiki_pages/_quick_search.html.erb diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index be70dc328..f6f69f0f9 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -5,6 +5,8 @@ class CommentsController < ApplicationController skip_before_action :api_check def index + params[:group_by] ||= "comment" if params[:search] + if params[:group_by] == "comment" || request.format == Mime::Type.lookup("application/atom+xml") index_by_comment elsif request.format == Mime::Type.lookup("text/javascript") diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c30aeddfd..53b506749 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -158,6 +158,14 @@ module ApplicationHelper tag.input value: "Preview", type: "button", class: "dtext-preview-button", "data-input-id": input_id, "data-preview-id": preview_id end + def quick_search_form_for(attribute, url, name, autocomplete: nil, &block) + tag.li do + search_form_for(url, classes: "quick-search-form one-line-form") do |f| + f.input attribute, label: false, placeholder: "Search #{name}", input_html: { id: nil, "data-autocomplete": autocomplete } + end + end + end + def search_form_for(url, classes: "inline-form", &block) defaults = { required: false } html_options = { autocomplete: "off", class: "search-form #{classes}" } diff --git a/app/javascript/src/styles/common/simple_form.scss b/app/javascript/src/styles/common/simple_form.scss index ea24e0e36..4dc05d850 100644 --- a/app/javascript/src/styles/common/simple_form.scss +++ b/app/javascript/src/styles/common/simple_form.scss @@ -78,6 +78,10 @@ form.inline-form { } } +form.quick-search-form { + margin: 0; +} + form.one-line-form { > input, > div.input { display: inline; diff --git a/app/views/artist_commentaries/_quick_search.html.erb b/app/views/artist_commentaries/_quick_search.html.erb deleted file mode 100644 index 5c24eb488..000000000 --- a/app/views/artist_commentaries/_quick_search.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= form_tag(artist_commentaries_path, :method => :get) do %> - <%= text_field "search", "text_matches", :id => "quick_search_text_matches", :placeholder => "Search commentary" %> -<% end %> diff --git a/app/views/artist_commentaries/_secondary_links.html.erb b/app/views/artist_commentaries/_secondary_links.html.erb index c1fd0226e..45b8a9ebf 100644 --- a/app/views/artist_commentaries/_secondary_links.html.erb +++ b/app/views/artist_commentaries/_secondary_links.html.erb @@ -1,6 +1,6 @@ <% content_for(:secondary_links) do %> -
  • <%= render "artist_commentaries/quick_search" %>
  • + <%= quick_search_form_for(:text_matches, artist_commentaries_path, "commentaries") %> <%= subnav_link_to "Search", search_artist_commentaries_path %> <%= subnav_link_to "Listing", artist_commentaries_path %> <%= subnav_link_to "Recent changes", artist_commentary_versions_path %> diff --git a/app/views/artists/_quick_search.html.erb b/app/views/artists/_quick_search.html.erb deleted file mode 100644 index 5e977cbfc..000000000 --- a/app/views/artists/_quick_search.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= form_tag(artists_path, :method => :get) do %> - <%= text_field "search", "any_name_or_url_matches", id: "quick_search_name", placeholder: "Search artists", "data-autocomplete": "artist" %> -<% end %> diff --git a/app/views/artists/_secondary_links.html.erb b/app/views/artists/_secondary_links.html.erb index a03dc19ec..1dc49188b 100644 --- a/app/views/artists/_secondary_links.html.erb +++ b/app/views/artists/_secondary_links.html.erb @@ -1,6 +1,6 @@ <% content_for(:secondary_links) do %> -
  • <%= render "artists/quick_search" %>
  • + <%= quick_search_form_for(:any_name_or_url_matches, artists_path, "artists", autocomplete: "artist") %> <%= subnav_link_to "Listing", artists_path %> <%= subnav_link_to "Banned", banned_artists_path %> <% if CurrentUser.is_member? %> diff --git a/app/views/comments/_quick_search.html.erb b/app/views/comments/_quick_search.html.erb deleted file mode 100644 index eb41c59e8..000000000 --- a/app/views/comments/_quick_search.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -<%= form_tag(comments_path, :method => :get) do %> - <%= hidden_field_tag "group_by", "comment" %> - <%= text_field "search", "body_matches", :id => "quick_search_body_matches", :placeholder => "Search comments" %> -<% end %> diff --git a/app/views/comments/_secondary_links.html.erb b/app/views/comments/_secondary_links.html.erb index 5c7dd45c5..6aba38203 100644 --- a/app/views/comments/_secondary_links.html.erb +++ b/app/views/comments/_secondary_links.html.erb @@ -1,6 +1,6 @@ <% content_for(:secondary_links) do %> -
  • <%= render "comments/quick_search" %>
  • + <%= quick_search_form_for(:body_matches, comments_path, "comments") %> <%= subnav_link_to "Listing", comments_path(:group_by => "post") %> <%= subnav_link_to "Search", search_comments_path %> <%= subnav_link_to "Help", wiki_pages_path(:title => "help:comments") %> diff --git a/app/views/dmails/_quick_search.html.erb b/app/views/dmails/_quick_search.html.erb deleted file mode 100644 index 8d74ab9eb..000000000 --- a/app/views/dmails/_quick_search.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= form_tag(dmails_path, :method => :get) do %> - <%= text_field "search", "message_matches", :id => "quick_search_message_matches", :placeholder => "Search messages" %> -<% end %> diff --git a/app/views/dmails/_secondary_links.html.erb b/app/views/dmails/_secondary_links.html.erb index 43a70e0a3..0ce8a8467 100644 --- a/app/views/dmails/_secondary_links.html.erb +++ b/app/views/dmails/_secondary_links.html.erb @@ -1,6 +1,6 @@ <% content_for(:secondary_links) do %> -
  • <%= render "quick_search" %>
  • + <%= quick_search_form_for(:message_matches, dmails_path, "dmails") %> <%= subnav_link_to "All", all_dmails_path(set_default_folder: true) %> <%= subnav_link_to "Received", received_dmails_path(set_default_folder: true) %> <%= subnav_link_to "Sent", sent_dmails_path(set_default_folder: true) %> diff --git a/app/views/forum_posts/_quick_search.html.erb b/app/views/forum_posts/_quick_search.html.erb deleted file mode 100644 index 8b830b1e7..000000000 --- a/app/views/forum_posts/_quick_search.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= form_tag(forum_posts_path, :method => :get) do %> - <%= text_field "search", "body_matches", :id => "quick_search_body_matches", :placeholder => "Search forum" %> -<% end %> diff --git a/app/views/forum_topics/_secondary_links.html.erb b/app/views/forum_topics/_secondary_links.html.erb index 59d2b66b9..5416d9dfd 100644 --- a/app/views/forum_topics/_secondary_links.html.erb +++ b/app/views/forum_topics/_secondary_links.html.erb @@ -1,6 +1,6 @@ <% content_for(:secondary_links) do %> -
  • <%= render "forum_posts/quick_search" %>
  • + <%= quick_search_form_for(:body_matches, forum_posts_path, "forum posts") %> <%= subnav_link_to "Listing", forum_topics_path %> <% if CurrentUser.is_member? %> diff --git a/app/views/notes/_quick_search.html.erb b/app/views/notes/_quick_search.html.erb deleted file mode 100644 index 66f1130a2..000000000 --- a/app/views/notes/_quick_search.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -<%= form_tag(notes_path, :method => :get) do %> - <%= hidden_field_tag "group_by", "note" %> - <%= text_field "search", "body_matches", :id => "quick_search_body_matches", :placeholder => "Search notes" %> -<% end %> diff --git a/app/views/notes/_secondary_links.html.erb b/app/views/notes/_secondary_links.html.erb index c5af37b9a..84d768677 100644 --- a/app/views/notes/_secondary_links.html.erb +++ b/app/views/notes/_secondary_links.html.erb @@ -1,6 +1,6 @@ <% content_for(:secondary_links) do %> -
  • <%= render "notes/quick_search" %>
  • + <%= quick_search_form_for(:body_matches, notes_path, "notes") %> <%= subnav_link_to "Listing", notes_path %> <%= subnav_link_to "Posts", posts_path(:tags => "order:note") %> <%= subnav_link_to "Search", search_notes_path %> diff --git a/app/views/pools/_quick_search.html.erb b/app/views/pools/_quick_search.html.erb deleted file mode 100644 index e53d8b366..000000000 --- a/app/views/pools/_quick_search.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= form_tag(pools_path, :method => :get) do %> - <%= text_field "search", "name_matches", id: "quick_search_name_matches", placeholder: "Search pools", data: { autocomplete: "pool" } %> -<% end %> diff --git a/app/views/pools/_secondary_links.html.erb b/app/views/pools/_secondary_links.html.erb index 60cf343b3..cd9f49bdd 100644 --- a/app/views/pools/_secondary_links.html.erb +++ b/app/views/pools/_secondary_links.html.erb @@ -1,6 +1,6 @@ <% content_for(:secondary_links) do %> -
  • <%= render "pools/quick_search" %>
  • + <%= quick_search_form_for(:name_matches, pools_path, "pools", autocomplete: "pool") %> <%= subnav_link_to "Gallery", gallery_pools_path %> <%= subnav_link_to "Listing", pools_path %> <%= subnav_link_to "New", new_pool_path %> diff --git a/app/views/tags/_quick_search.html.erb b/app/views/tags/_quick_search.html.erb deleted file mode 100644 index a588ad1b1..000000000 --- a/app/views/tags/_quick_search.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= form_tag(tags_path, :method => :get) do %> - <%= text_field "search", "name_matches", :id => "quick_search_name_matches", :placeholder => "Search tags", :data => { :autocomplete => "tag" } %> -<% end %> diff --git a/app/views/tags/_secondary_links.html.erb b/app/views/tags/_secondary_links.html.erb index 9ebdddb9d..88b59f1c0 100644 --- a/app/views/tags/_secondary_links.html.erb +++ b/app/views/tags/_secondary_links.html.erb @@ -1,6 +1,6 @@ <% content_for(:secondary_links) do %> -
  • <%= render "tags/quick_search" %>
  • + <%= quick_search_form_for(:name_matches, tags_path, "tags", autocomplete: "tag") %> <%= subnav_link_to "Listing", tags_path %> <%= subnav_link_to "MetaSearch", meta_searches_tags_path %> <%= subnav_link_to "Related tags", related_tag_path %> diff --git a/app/views/users/_quick_search.html.erb b/app/views/users/_quick_search.html.erb deleted file mode 100644 index 03c223bfb..000000000 --- a/app/views/users/_quick_search.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= form_tag(users_path, :method => :get) do %> - <%= text_field "search", "name_matches", :id => "quick_search_name_matches", :placeholder => "Search users", :data => { autocomplete: "user" } %> -<% end %> diff --git a/app/views/users/_secondary_links.html.erb b/app/views/users/_secondary_links.html.erb index 272717e75..52d93c233 100644 --- a/app/views/users/_secondary_links.html.erb +++ b/app/views/users/_secondary_links.html.erb @@ -1,6 +1,6 @@ <% content_for(:secondary_links) do %> -
  • <%= render "users/quick_search" %>
  • + <%= quick_search_form_for(:name_matches, users_path, "users", autocomplete: "user") %> <%= subnav_link_to "Listing", users_path %> <%= subnav_link_to "Search", search_users_path %> diff --git a/app/views/wiki_pages/_quick_search.html.erb b/app/views/wiki_pages/_quick_search.html.erb deleted file mode 100644 index dad203ab9..000000000 --- a/app/views/wiki_pages/_quick_search.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= form_tag(wiki_pages_path, :method => :get) do %> - <%= text_field "search", "title", id: "quick_search_title", placeholder: "Search wiki pages", data: { autocomplete: "wiki-page" } %> -<% end %> diff --git a/app/views/wiki_pages/_secondary_links.html.erb b/app/views/wiki_pages/_secondary_links.html.erb index c4470fe24..421aadc1b 100644 --- a/app/views/wiki_pages/_secondary_links.html.erb +++ b/app/views/wiki_pages/_secondary_links.html.erb @@ -1,6 +1,6 @@ <% content_for(:secondary_links) do %> -
  • <%= render "wiki_pages/quick_search" %>
  • + <%= quick_search_form_for(:title, wiki_pages_path, "wiki pages", autocomplete: "wiki-page") %> <%= subnav_link_to "Listing", wiki_pages_path %>