Skip to content

Commit

Permalink
add rtl functionality to search results
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotjordan committed Oct 20, 2016
1 parent f8c58f3 commit 84cba4f
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def search_across_settings

blacklight_config.add_facet_field 'readonly_language_ssim', label: 'Language'
blacklight_config.add_facet_field 'readonly_format_ssim', label: 'Format'
blacklight_config.show.document_presenter_class = RTLShowPresenter
unique_custom_fields.each do |field|
blacklight_config.add_show_field field.field, label: field.configuration["label"]
end
Expand Down Expand Up @@ -48,6 +47,7 @@ def unique_custom_fields

# solr field configuration for search results/index views
config.index.title_field = 'full_title_ssim'
config.index.preferred_title_field = 'readonly_title_tesim'
config.add_show_field 'creator_ssim', label: 'Creator'

config.add_search_field 'all_fields', label: 'Everything'
Expand All @@ -60,5 +60,7 @@ def unique_custom_fields
config.add_facet_fields_to_solr_request!
config.add_field_configuration_to_solr_request!
config.response_model = AdjustedGroupedResponse
config.show.document_presenter_class = RTLShowPresenter
config.index.document_presenter_class = RTLIndexPresenter
end
end
37 changes: 37 additions & 0 deletions app/presenters/rtl_index_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class RTLIndexPresenter < ::Blacklight::IndexPresenter
def label(field_or_string_or_proc, opts = {})
config = Blacklight::Configuration::NullField.new
value = case field_or_string_or_proc
when Symbol
config = field_config(field_or_string_or_proc)
value_from_symbol(field_or_string_or_proc)
when Proc
field_or_string_or_proc.call(@document, opts)
when String
field_or_string_or_proc
end
value ||= @document.id
label_value(value, config)
end

private

def value_from_symbol(field)
default_title_field = @configuration.index.title_field
preferred_title_field = @configuration.index.preferred_title_field

if field.to_s == default_title_field && @document.key?(preferred_title_field)
@document[preferred_title_field]
else
@document[field]
end
end

def label_value(value, config)
if value.is_a?(Array) && value.count > 1
value.collect { |v| field_values(config, value: v) }
else
field_values(config, value: value)
end
end
end
46 changes: 46 additions & 0 deletions app/views/catalog/_index_header_default.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<%# header bar for doc items in index view -%>
<div class="documentHeader row">
<%# main title container for doc partial view
How many bootstrap columns need to be reserved
for bookmarks control depends on size.
-%>
<% document_actions = capture do %>
<% # bookmark functions for items/docs -%>
<%= render_index_doc_actions document, wrapping_class: "index-document-functions col-sm-3 col-lg-2" %>
<% end %>
<h3 class="index_title document-title-heading <%= document_actions.present? ? "col-sm-9 col-lg-10" : "col-md-12" %>">
<div class="row">
</div>
<% if counter = document_counter_with_offset(document_counter) %>
<span style="" class="document-counter col-sm-1">
<%= t('blacklight.search.documents.counter', counter: counter) %>
</span>
<% end %>
<div class="col-sm-11">
<% field = index_presenter(document).label(document_show_link_field(document)) %>
<% if field.length == 1 || !field.is_a?(Array) %>
<% valdir = Array(field).first.dir %>
<span style="display: block;" dir="<%= valdir %>">
<%= link_to_document document, document_show_link_field(document), counter: counter %>
</span>
<% else %>
<% valdirs = [] %>
<% field.each do |value| %>
<% valdirs << value.dir %>
<% end %>
<% field.each do |value| %>
<span style="display: block;" dir="<%= valdirs[field.index(value)] %>">
<%= link_to value, '/' %>
</span>
<% end %>
<% end %>
</div>
</h3>
<%= document_actions %>
</div>

0 comments on commit 84cba4f

Please sign in to comment.