Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor admin search forms #4277

Merged
merged 11 commits into from
Dec 7, 2020
17 changes: 17 additions & 0 deletions app/assets/stylesheets/admin/search.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.admin [role=search] {
display: flex;

[type="submit"] {
@include button($background: $link);
border-radius: 0;
font-size: 1rem;

&[disabled] {
@include button-disabled;
}
}

@include breakpoint(medium) {
width: 50%;
}
}
4 changes: 4 additions & 0 deletions app/components/admin/search_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= form_tag(url, options) do |f| %>
<%= text_field_tag :search, search_terms.to_s, placeholder: label, "aria-label": label %>
<%= submit_tag t("admin.shared.search.search") %>
<% end %>
23 changes: 23 additions & 0 deletions app/components/admin/search_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Admin::SearchComponent < ApplicationComponent
attr_reader :label, :form_options

def initialize(label:, url: nil, **form_options)
@label = label
@url = url
@form_options = form_options
end

def url
@url || request.path
end

private

def search_terms
params[:search]
end

def options
{ method: :get, role: "search" }.merge(form_options)
end
end
2 changes: 1 addition & 1 deletion app/controllers/admin/administrators_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def index
end

def search
@users = User.search(params[:name_or_email])
@users = User.search(params[:search])
.includes(:administrator)
.page(params[:page])
.for_render
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/managers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def index
end

def search
@users = User.search(params[:name_or_email])
@users = User.search(params[:search])
.includes(:manager)
.page(params[:page])
.for_render
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/moderators_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def index
end

def search
@users = User.search(params[:name_or_email])
@users = User.search(params[:search])
.includes(:moderator)
.page(params[:page])
.for_render
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/officials_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def index
end

def search
@users = User.search(params[:name_or_email]).page(params[:page]).for_render
@users = User.search(params[:search]).page(params[:page]).for_render
end

def edit
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def index

def search
@organizations = Organization.includes(:user)
.search(params[:term])
.search(params[:search])
.order("users.created_at", :name, "users.email")
.page(params[:page])
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/poll/officers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def index
end

def search
@user = User.find_by(email: params[:email])
@user = User.find_by(email: params[:search])

respond_to do |format|
if @user
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/admin/poll/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController

def index
@polls = Poll.not_budget
@search = search_params[:search]

@questions = @questions.search(search_params).page(params[:page]).order("created_at DESC")

@proposals = Proposal.successful.sort_by_confidence_score
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/valuators_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def index
end

def search
@users = User.search(params[:name_or_email])
@users = User.search(params[:search])
.includes(:valuator)
.page(params[:page])
.for_render
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/verifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def index
end

def search
@users = User.incomplete_verification.search(params[:name_or_email])
@users = User.incomplete_verification.search(params[:search])
.page(params[:page])
.for_render
render :index
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/moderation/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def hide
private

def load_users
@users = User.with_hidden.search(params[:name_or_email]).page(params[:page]).for_render
@users = User.with_hidden.search(params[:search]).page(params[:page]).for_render
end

def block_user
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/debates/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<h2><%= t("admin.debates.index.title") %></h2>

<% if @debates.any? %>
<%= render "/admin/shared/debate_search", url: admin_debates_path %>
<%= render Admin::SearchComponent.new(label: t("admin.shared.debate_search.placeholder")) %>

<h3 class="inline-block"><%= page_entries_info @debates %></h3>

Expand Down
14 changes: 4 additions & 10 deletions app/views/admin/local_census_records/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@
new_admin_local_census_records_import_path,
class: "button float-right hollow" %>

<div class="small-12 medium-6">
<%= form_tag admin_local_census_records_path, method: :get, remote: true do %>
<div class="input-group">
<%= text_field_tag :search, "", placeholder: t("admin.local_census_records.index.search.placeholder") %>
<div class="input-group-button">
<%= submit_tag t("admin.local_census_records.index.search.search"), class: "button" %>
</div>
</div>
<% end %>
</div>
<%= render Admin::SearchComponent.new(
label: t("admin.local_census_records.index.search.placeholder"),
remote: true
) %>

<div id="local_census_records">
<%= render "local_census_records" %>
Expand Down
15 changes: 4 additions & 11 deletions app/views/admin/organizations/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<h2><%= t("admin.organizations.index.title") %></h2>

<div class="small-12 medium-6">
<%= form_for(Organization.new, url: search_admin_organizations_path, method: :get) do |f| %>
<div class="input-group">
<%= text_field_tag :term, "", placeholder: t("admin.organizations.index.search_placeholder") %>

<div class="input-group-button">
<%= f.submit t("admin.organizations.index.search"), class: "button" %>
</div>
</div>
<% end %>
</div>
<%= render Admin::SearchComponent.new(
url: search_admin_organizations_path,
label: t("admin.organizations.index.search_placeholder")
) %>

<%= render "shared/filter_subnav", i18n_namespace: "admin.organizations.index" %>

Expand Down
11 changes: 1 addition & 10 deletions app/views/admin/organizations/search.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
<h2><%= t("admin.organizations.search.title") %></h2>

<div class="small-12 medium-6">
<%= form_for(Organization.new, url: search_admin_organizations_path, method: :get) do |f| %>
<div class="input-group">
<%= text_field_tag :term, "", placeholder: t("admin.organizations.index.search_placeholder") %>
<div class="input-group-button">
<%= f.submit t("admin.organizations.index.search"), class: "button" %>
</div>
</div>
<% end %>
</div>
<%= render Admin::SearchComponent.new(label: t("admin.organizations.index.search_placeholder")) %>

<div id="search-results">
<% if @organizations.any? %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@search,
placeholder: t("admin.shared.booths_search.placeholder"), id: "search-booths" %>
<div class="input-group-button">
<%= submit_tag t("admin.shared.booths_search.button"), class: "button" %>
<%= submit_tag t("admin.shared.search.search"), class: "button" %>
</div>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/poll/booths/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<%= link_to t("admin.booths.index.add_booth"), new_admin_booth_path, class: "button float-right" %>
<% end %>

<%= render "/admin/shared/booth_search", url: admin_booths_path %>
<%= render Admin::SearchComponent.new(label: t("admin.shared.booths_search.placeholder")) %>

<% if @booths.empty? %>
<div class="callout primary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@search,
placeholder: t("admin.shared.poll_officers_search.placeholder"), id: "search-officers" %>
<div class="input-group-button">
<%= submit_tag t("admin.shared.poll_officers_search.button"), class: "button" %>
<%= submit_tag t("admin.shared.search.search"), class: "button" %>
</div>
</div>
<% end %>
Expand Down
14 changes: 5 additions & 9 deletions app/views/admin/poll/officers/_search.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<p><%= t("admin.poll_officers.search.help") %></p>

<%= form_tag search_admin_officers_path, method: :get, remote: true do %>
<div class="input-group">
<%= text_field_tag :email, "",
placeholder: t("admin.poll_officers.search.email_placeholder") %>
<div class="input-group-button">
<%= submit_tag t("admin.poll_officers.search.search"), class: "button" %>
</div>
</div>
<% end %>
<%= render Admin::SearchComponent.new(
url: search_admin_officers_path,
label: t("admin.poll_officers.search.email_placeholder"),
remote: true
) %>
4 changes: 1 addition & 3 deletions app/views/admin/poll/officers/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<h2><%= t("admin.poll_officers.index.title") %></h2>

<div class="small-12 medium-6">
<%= render "search" %>
</div>
<%= render "search" %>

<div id="search-result"></div>

Expand Down
11 changes: 1 addition & 10 deletions app/views/admin/poll/questions/_search.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
<%= form_tag(admin_questions_path, method: :get) do |f| %>
<div class="input-group">
<%= text_field_tag :search,
@search,
placeholder: t("admin.shared.poll_questions_search.placeholder") %>
<div class="input-group-button">
<%= submit_tag t("admin.shared.poll_questions_search.button"), class: "button" %>
</div>
</div>
<% end %>
<%= render Admin::SearchComponent.new(label: t("admin.shared.poll_questions_search.placeholder")) %>
4 changes: 1 addition & 3 deletions app/views/admin/poll/questions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
<%= link_to t("admin.questions.index.create"), new_admin_question_path,
class: "button float-right" %>

<div class="small-12 medium-6">
<%= render "search" %>
</div>
<%= render "search" %>

<div class="tabs-content" data-tabs-content="questions-tabs">
<%= render "filter_subnav" %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/proposals/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<h2><%= t("admin.proposals.index.title") %></h2>

<% if @proposals.any? %>
<%= render "/admin/shared/proposal_search", url: admin_proposals_path %>
<%= render Admin::SearchComponent.new(label: t("admin.shared.proposal_search.placeholder")) %>

<h3><%= page_entries_info @proposals %></h3>

Expand Down
10 changes: 0 additions & 10 deletions app/views/admin/shared/_booth_search.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions app/views/admin/shared/_debate_search.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions app/views/admin/shared/_proposal_search.html.erb

This file was deleted.

11 changes: 1 addition & 10 deletions app/views/admin/shared/_user_search.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
<div class="small-12 medium-6">
<%= form_for(User.new, url: url, as: :user, method: :get) do |f| %>
<div class="input-group">
<%= text_field_tag :name_or_email, "", placeholder: t("admin.shared.user_search.placeholder") %>
<div class="input-group-button">
<%= f.submit t("admin.shared.user_search.button"), class: "button" %>
</div>
</div>
<% end %>
</div>
<%= render Admin::SearchComponent.new(url: url, label: t("admin.shared.user_search.placeholder")) %>
14 changes: 4 additions & 10 deletions app/views/admin/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
<h2><%= t("admin.users.index.title") %></h2>

<div class="small-12 medium-6">
<%= form_tag admin_users_path, method: :get, remote: true do %>
<div class="input-group">
<%= text_field_tag :search, "", placeholder: t("admin.users.search.placeholder") %>
<div class="input-group-button">
<%= submit_tag t("admin.users.search.search"), class: "button" %>
</div>
</div>
<% end %>
</div>
<%= render Admin::SearchComponent.new(
label: t("admin.users.search.placeholder"),
remote: true
) %>

<div id="users">
<%= render "users" %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/management/proposals/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<main>
<h2><%= t("management.proposals.index.title") %></h2>

<%= render "admin/shared/proposal_search", url: management_proposals_path %>
<%= render Admin::SearchComponent.new(label: t("admin.shared.proposal_search.placeholder")) %>

<div class="management-list">
<div class="proposals-list">
Expand Down
11 changes: 1 addition & 10 deletions app/views/moderation/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
<h2><%= t("moderation.users.index.title") %></h2>

<%= form_for(User.new, url: moderation_users_path, as: :user, method: :get) do |f| %>
<div class="row">
<div class="small-12 medium-6 column">
<%= text_field_tag :name_or_email, "", placeholder: t("moderation.users.index.search_placeholder") %>
</div>
<div class="small-12 medium-6 column">
<%= f.submit t("moderation.users.index.search"), class: "button success" %>
</div>
</div>
<% end %>
<%= render Admin::SearchComponent.new(label: t("moderation.users.index.search_placeholder")) %>

<% if @users.present? %>
<h3><%= page_entries_info @users %></h3>
Expand Down
Loading