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

Full text search respects filters #1901

Merged
merged 2 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions app/assets/stylesheets/alchemy/search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@
top: 9px;
}

label {
display: block;
button {
position: absolute;
top: 0;
left: 0;
width: 30px;
height: inherit;
appearance: none;
background-color: transparent;
border: 0 none;
border-radius: 0;
box-shadow: none;
margin: 0;
padding: 0;
}
}

Expand Down
23 changes: 12 additions & 11 deletions app/views/alchemy/admin/partials/_remote_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<%= 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) %>
<div class="search_field">
<label>
<button type="submit">
<%= render_icon('search') %>
<%= f.search_field resource_handler.search_field_name,
placeholder: Alchemy.t(:search),
class: 'search_input_field',
id: nil %>
</label>
<%= link_to render_icon(:times, size: 'xs'), url_for(
</button>
<%= f.search_field resource_handler.search_field_name,
placeholder: Alchemy.t(:search),
class: 'search_input_field',
id: nil %>
<%= 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
12 changes: 6 additions & 6 deletions app/views/alchemy/admin/partials/_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<%- 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">
<label>
<button type="submit">
<%= render_icon('search') %>
<%= f.search_field resource_handler.search_field_name,
class: 'search_input_field',
placeholder: Alchemy.t(:search) %>
</label>
</button>
<%= f.search_field resource_handler.search_field_name,
class: 'search_input_field',
placeholder: Alchemy.t(:search) %>
<% local_assigns.fetch(:additional_query_fields, []).each do |field| %>
<%= f.hidden_field field %>
<% end %>
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