Skip to content

Commit

Permalink
AR-1742 add ability to start a new search or refine an existing search
Browse files Browse the repository at this point in the history
  • Loading branch information
payten authored and marktriggs committed Jun 19, 2017
1 parent 96cb079 commit d541276
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
19 changes: 19 additions & 0 deletions public-new/app/assets/javascripts/search.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,22 @@ $(function() {
'.recordrow .classification-subgroups button.subgroup-toggle',
toggle_subgroups);
});


$(function() {
$('#toggleRefineSearch').on('click', function(event) {
event.preventDefault();

var $btn = $(this);
var $refine = $btn.closest('.searchstatement').find('.refinesearch');
if ($refine.is(':visible')) {
$refine.css('display', 'none');
$refine.attr('aria-hidden', 'true');
$btn.removeClass('active');
} else {
$refine.css('display', 'block');
$refine.attr('aria-hidden', 'false');
$btn.addClass('active');
}
});
});
5 changes: 3 additions & 2 deletions public-new/app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def search
@repo_id = params.fetch(:rid, nil)
repo_url = "/repositories/#{@repo_id}"
@base_search = @repo_id ? "#{repo_url}/search?" : '/search?'
fallback_location = @repo_id ? repo_url : '/';
fallback_location = @repo_id ? repo_url : root_path;
@new_search = fallback_location

search_opts = default_search_opts(DEFAULT_SEARCH_OPTS)
search_opts['fq'] = ["repository:\"#{repo_url}\" OR used_within_published_repository::\"#{repo_url}\""] if @repo_id
Expand All @@ -22,7 +23,7 @@ def search
#NOTE the redirect back here on error!
rescue Exception => error
flash[:error] = error
redirect_back(fallback_location: '/' ) and return
redirect_back(fallback_location: root_path ) and return
end
page = Integer(params.fetch(:page, "1"))
Rails.logger.debug("base search: #{@base_search}")
Expand Down
22 changes: 21 additions & 1 deletion public-new/app/views/search/search_results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,27 @@
<% end %>
<% unless defined?(@no_statement) %>
<div class="searchstatement"><%= @search[:search_statement].html_safe %></div>
<div class="searchstatement">
<div class="btn btn-group pull-right">
<%= link_to I18n.t('actions.new_search'), (defined?(@new_search) ? @new_search : root_path), :class => "btn btn-sm btn-default" %>
<button class="btn btn-sm btn-default" id="toggleRefineSearch"><%= I18n.t('actions.refine_search') %></button>
</div>

<%= @search[:search_statement].html_safe %>

<div class="container refinesearch" aria-hidden="true" style="display:none;">
<%= render partial: 'shared/search', locals: {:search_url => @base_search,
:title => t('archive._plural'),
:limit_options => [["#{t('actions.search')} #{t('search-limits.all')}",''],
[t('search-limit', :limit => t('search-limits.resources')),'resource'],
[t('search-limit', :limit => t('search-limits.digital')),'digital_object']],
:field_options => [["#{t('search_results.filter.fullrecord')}",''],
["#{t('search_results.filter.title')}",'title'],
["#{t('search_results.filter.creators')}",'creators_text'],
["#{t('search_results.filter.notes')}", 'notes'] ],
:show_header => false } %>
</div>
</div>
<% end %>

<h2><%= t('search_results.results_head', {:type => results_type, :start => @results['offset_first'],
Expand Down
5 changes: 5 additions & 0 deletions public-new/app/views/shared/_search.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<%
show_header = true if show_header.nil?
%>
<div class="search" role="search">
<% if show_header %>
<h3><%= t('actions.search') %> <%= title %> </h3>
<% end %>
<% @search = Search.new unless defined?(@search) %>
<%= form_tag("#{search_url}", method: 'get', :id => 'advanced_search') do %>
<% (0...[1, @search.q.length].max).each do |i| %>
Expand Down
2 changes: 2 additions & 0 deletions public-new/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ en:
search: Search
search_within: Search within results
search_in: "Search %{type}"
new_search: New Search
refine_search: Refine Search
browse: Browse
show_advanced_search: Show Advanced Search
hide_advanced_search: Hide Advanced Search
Expand Down
2 changes: 2 additions & 0 deletions public-new/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

root to: "welcome#show"

get '/', to: 'welcome#show' #'index#index'
get '/welcome', to: 'welcome#show'
post '/cite', to: 'cite#show'
Expand Down

0 comments on commit d541276

Please sign in to comment.