Skip to content

Commit

Permalink
Search on the same URL by default
Browse files Browse the repository at this point in the history
  • Loading branch information
javierm committed Dec 7, 2020
1 parent e33794e commit cf51004
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 33 deletions.
10 changes: 7 additions & 3 deletions app/components/admin/search_component.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
class Admin::SearchComponent < ApplicationComponent
attr_reader :url, :label, :form_options
attr_reader :label, :form_options

def initialize(url:, label:, **form_options)
@url = url
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
Expand Down
5 changes: 1 addition & 4 deletions app/views/admin/debates/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
<h2><%= t("admin.debates.index.title") %></h2>

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

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

Expand Down
1 change: 0 additions & 1 deletion app/views/admin/local_census_records/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
class: "button float-right hollow" %>
<%= render Admin::SearchComponent.new(
url: admin_local_census_records_path,
label: t("admin.local_census_records.index.search.placeholder"),
remote: true
) %>
Expand Down
5 changes: 1 addition & 4 deletions app/views/admin/organizations/search.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<h2><%= t("admin.organizations.search.title") %></h2>

<%= render Admin::SearchComponent.new(
url: search_admin_organizations_path,
label: t("admin.organizations.index.search_placeholder")
) %>
<%= render Admin::SearchComponent.new(label: t("admin.organizations.index.search_placeholder")) %>

<div id="search-results">
<% if @organizations.any? %>
Expand Down
5 changes: 1 addition & 4 deletions app/views/admin/poll/booths/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
<%= link_to t("admin.booths.index.add_booth"), new_admin_booth_path, class: "button float-right" %>
<% end %>
<%= render Admin::SearchComponent.new(
url: admin_booths_path,
label: t("admin.shared.booths_search.placeholder")
) %>
<%= render Admin::SearchComponent.new(label: t("admin.shared.booths_search.placeholder")) %>
<% if @booths.empty? %>
<div class="callout primary">
Expand Down
5 changes: 1 addition & 4 deletions app/views/admin/poll/questions/_search.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
<%= render Admin::SearchComponent.new(
url: admin_questions_path,
label: t("admin.shared.poll_questions_search.placeholder")
) %>
<%= render Admin::SearchComponent.new(label: t("admin.shared.poll_questions_search.placeholder")) %>
5 changes: 1 addition & 4 deletions app/views/admin/proposals/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
<h2><%= t("admin.proposals.index.title") %></h2>

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

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

Expand Down
1 change: 0 additions & 1 deletion app/views/admin/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<h2><%= t("admin.users.index.title") %></h2>

<%= render Admin::SearchComponent.new(
url: admin_users_path,
label: t("admin.users.search.placeholder"),
remote: true
) %>
Expand Down
5 changes: 1 addition & 4 deletions app/views/management/proposals/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<main>
<h2><%= t("management.proposals.index.title") %></h2>

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

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

<%= render Admin::SearchComponent.new(
url: moderation_users_path,
label: t("moderation.users.index.search_placeholder")
) %>
<%= render Admin::SearchComponent.new(label: t("moderation.users.index.search_placeholder")) %>
<% if @users.present? %>
<h3><%= page_entries_info @users %></h3>
Expand Down

0 comments on commit cf51004

Please sign in to comment.