Skip to content

Commit

Permalink
refactor search results sir-trevor widget to use a custom view type w…
Browse files Browse the repository at this point in the history
…idget
  • Loading branch information
cbeer committed Apr 10, 2014
1 parent cbf6674 commit 522bc42
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
18 changes: 12 additions & 6 deletions app/helpers/spotlight/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,20 @@ def presenter_class
# Return a copy of the blacklight configuration
# that only includes views conifgured by our block
def blacklight_view_config_for_search_block sir_tervor_json
# Clone the blacklight_config so we can send our
# local copy into the the view_type_group parital
config = blacklight_config.clone
# Reject any views that aren't conifgured to display for this block
config.view.select! do |view,_|
# Reject any views that aren't configured to display for this block
blacklight_config.view.select do |view,_|
selected_search_block_views(sir_tervor_json).include? view.to_s
end
config
end

def block_document_index_view_type block
views = blacklight_view_config_for_search_block(block)

if views.has_key? document_index_view_type
document_index_view_type
else
views.keys.first
end
end

# Return the list of views that are configured to display for a block
Expand Down
4 changes: 2 additions & 2 deletions app/views/sir-trevor/blocks/_search_results_block.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<%- else %>
<% @response, @document_list = [response, document_list] %>
<%= render 'sort_and_per_page', block: block %>
<%= render_document_index %>
<%= render_document_index_with_view(block_document_index_view_type(block), document_list) %>
<%= render 'results_pagination' %>
</div>
<%- end %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/spotlight/pages/_sort_and_per_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<div class="search-widgets pull-right">
<%= render :partial => 'sort_widget' %>
<%= render :partial => 'per_page_widget' %>
<%= render :partial => 'view_type_group', locals: { blacklight_config: blacklight_view_config_for_search_block(block) } %>
<%= render :partial => 'view_type_group', locals: { block: block } %>
</div>
</div>
14 changes: 14 additions & 0 deletions app/views/spotlight/pages/_view_type_group.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<% views = blacklight_view_config_for_search_block(block) %>
<% if views.length > 1 -%>
<div class="view-type">
<span class="sr-only"><%= t('blacklight.search.view_title') %></span>
<div class="view-type-group btn-group">
<% views.each do |view, config| %>
<%= link_to url_for(params.merge(:view => view)), :title => t("blacklight.search.view_title.#{view}", default: t("blacklight.search.view.#{view}", default: blacklight_config.view[view].title)), :class => "btn btn-default view-type-#{ view.to_s.parameterize } #{"active" if block_document_index_view_type(block) == view}" do %>
<%= render_view_type_group_icon view %>
<span class="caption"><%= t("blacklight.search.view.#{view}") %></span>
<% end %>
<% end %>
</div>
</div>
<% end -%>

0 comments on commit 522bc42

Please sign in to comment.