Skip to content

Commit

Permalink
Full text search should respect filters
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen committed Jul 17, 2020
1 parent 0e13d2f commit 1d53507
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
11 changes: 6 additions & 5 deletions app/views/alchemy/admin/partials/_remote_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<%= search_form_for @query, url: url_for(
action: 'index',
size: @size
<%= search_form_for @query, url: url_for({
action: 'index',
size: @size,
}.merge(search_filter_params.except(:q))
), remote: true, html: {class: 'search_form', id: nil} do |f| %>
<%= hidden_field_tag("element_id", @element.blank? ? "" : @element.id) %>
<%= hidden_field_tag("content_id", @content.blank? ? "" : @content.id) %>
Expand All @@ -12,13 +13,13 @@
placeholder: Alchemy.t(:search),
class: 'search_input_field',
id: nil %>
<%= link_to render_icon(:times, size: 'xs'), url_for(
<%= link_to render_icon(:times, size: 'xs'), url_for({
action: 'index',
element_id: @element.blank? ? '' : @element.id,
content_id: @content.blank? ? '' : @content.id,
size: @size,
overlay: true
),
}.merge(search_filter_params.except(:q))),
remote: true,
class: 'search_field_clear',
title: Alchemy.t(:click_to_show_all),
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/partials/_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%- url ||= resource_url_proxy.url_for(action: 'index') -%>
<%- url ||= resource_url_proxy.url_for({ action: 'index' }.merge(search_filter_params.except(:q))) -%>

<%= search_form_for @query, url: url, class: 'search_form' do |f| %>
<div class="search_field">
Expand Down
5 changes: 4 additions & 1 deletion app/views/alchemy/admin/resources/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
dialog: false,
if_permitted_to: [:index, resource_model]
) %>
<%= render 'alchemy/admin/partials/search_form' %>
<%= render 'alchemy/admin/partials/search_form', additional_params: [
resource_has_filters ? :filter : nil,
resource_has_tags ? :tagged_with : nil
].compact %>
<% end %>

<div id="archive_all" class="resources-table-wrapper<%= ' with_tag_filter' if resource_has_tags || resource_has_filters %>">
Expand Down
17 changes: 17 additions & 0 deletions spec/features/admin/resources_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,22 @@
expect(page).to have_content("Hovercar Expo")
expect(page).to have_content("Horse Expo")
end

context "full text search" do
it "should respect filters" do
visit "/admin/events?filter=future"

expect(page).to have_content("Hovercar Expo")
expect(page).to_not have_content("Car Expo")
expect(page).to_not have_content("Horse Expo")

page.find(".search_input_field").set("Horse")
page.find(".search_field button").click

expect(page).to_not have_content("Hovercar Expo")
expect(page).to_not have_content("Car Expo")
expect(page).to_not have_content("Horse Expo")
end
end
end
end

0 comments on commit 1d53507

Please sign in to comment.