Module: Blacklight::ConfigurationHelperBehavior
- Extended by:
- Deprecation
- Included in:
- BlacklightConfigurationHelper
- Defined in:
- app/helpers/blacklight/configuration_helper_behavior.rb
Instance Method Summary collapse
- #active_sort_fields ⇒ Object
-
#constraint_query_label(localized_params = params) ⇒ String
Return a label for the currently selected search field.
-
#default_document_index_view_type ⇒ Object
Get the default index view type.
-
#default_per_page ⇒ Object
The default value for search results per page.
-
#default_search_field?(selected_search_field) ⇒ Boolean
Is the search form using the default search field (“all_fields” by default)?.
-
#default_sort_field ⇒ Object
Default sort field.
-
#document_index_view_controls ⇒ Object
filter #document_index_views to just views that should display in the view type control.
- #document_index_views ⇒ Object
-
#document_show_field_label(document, field) ⇒ Object
Look up the label for the show field.
-
#document_show_fields(document = nil) ⇒ Object
used in the catalog/_show/_default partial.
-
#document_show_link_field(document = nil) ⇒ Object
Used in the document list partial (search view) for creating a link to the document show action.
-
#facet_field_label(field) ⇒ Object
Look up the label for the facet field.
-
#field_label(*i18n_keys) ⇒ Object
Look up the label for a solr field.
-
#has_alternative_views? ⇒ Boolean
Check if there are alternative views configuration.
-
#index_field_label(document, field) ⇒ Object
Look up the label for the index field.
-
#index_fields(document = nil) ⇒ Array<Blacklight::Configuration::Field>
Index fields to display for a type of document.
-
#label_for_search_field(key) ⇒ Object
Shortcut for commonly needed operation, look up display label for the key specified.
-
#per_page_options_for_select ⇒ Object
The available options for results per page, in the style of #options_for_select.
-
#search_field_options_for_select ⇒ Object
Returns suitable argument to options_for_select method, to create an html select based on #search_field_list.
-
#search_fields ⇒ Object
Used in the search form partial for building a select tag.
-
#should_render_field?(field_config, *args) ⇒ Boolean
Determine whether to render a field by evaluating :if and :unless conditions.
- #sort_field_label(key) ⇒ Object
-
#sort_fields ⇒ Object
Used in the document_list partial (search view) for building a select element.
-
#spell_check_max ⇒ Object
Maximum number of results for spell checking.
- #view_label(view) ⇒ Object
Instance Method Details
#active_sort_fields ⇒ Object
21 22 23 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 21 def active_sort_fields blacklight_config.sort_fields.select { |sort_key, field_config| should_render_field?(field_config) } end |
#constraint_query_label(localized_params = params) ⇒ String
Return a label for the currently selected search field. If no “search_field” or the default (e.g. “all_fields”) is selected, then return nil Otherwise grab the label of the selected search field.
50 51 52 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 50 def constraint_query_label(localized_params = params) label_for_search_field(localized_params[:search_field]) unless default_search_field?(localized_params[:search_field]) end |
#default_document_index_view_type ⇒ Object
Get the default index view type
169 170 171 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 169 def default_document_index_view_type document_index_views.select { |k,config| config.respond_to? :default and config.default }.keys.first || document_index_views.keys.first end |
#default_per_page ⇒ Object
The default value for search results per page
205 206 207 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 205 def default_per_page blacklight_config.default_per_page || blacklight_config.per_page.first end |
#default_search_field?(selected_search_field) ⇒ Boolean
Is the search form using the default search field (“all_fields” by default)?
58 59 60 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 58 def default_search_field?(selected_search_field) selected_search_field.blank? || (default_search_field && selected_search_field == default_search_field[:key]) end |
#default_sort_field ⇒ Object
Default sort field
199 200 201 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 199 def default_sort_field (active_sort_fields.find { |k,config| config.respond_to? :default and config.default } || active_sort_fields.first).try(:last) end |
#document_index_view_controls ⇒ Object
filter #document_index_views to just views that should display in the view type control
161 162 163 164 165 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 161 def document_index_view_controls document_index_views.select do |_k, config| config.display_control.nil? || blacklight_configuration_context.evaluate_configuration_conditional(config.display_control) end end |
#document_index_views ⇒ Object
154 155 156 157 158 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 154 def document_index_views blacklight_config.view.select do |k, config| should_render_field? config end end |
#document_show_field_label(document, field) ⇒ Object
Look up the label for the show field
77 78 79 80 81 82 83 84 85 86 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 77 def document_show_field_label document, field field_config = document_show_fields(document)[field] field_label( :"blacklight.search.fields.show.#{field}", :"blacklight.search.fields.#{field}", (field_config.label if field_config), field.to_s.humanize ) end |
#document_show_fields(document = nil) ⇒ Object
used in the catalog/_show/_default partial
40 41 42 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 40 def document_show_fields document=nil blacklight_config.show_fields end |
#document_show_link_field(document = nil) ⇒ Object
Used in the document list partial (search view) for creating a link to the document show action
186 187 188 189 190 191 192 193 194 195 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 186 def document_show_link_field document=nil fields = Array(blacklight_config.view_config(document_index_view_type).title_field) field = fields.first if document.nil? field ||= fields.find { |f| document.has? f } field &&= field.try(:to_sym) field ||= document.id field end |
#facet_field_label(field) ⇒ Object
Look up the label for the facet field
90 91 92 93 94 95 96 97 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 90 def facet_field_label field field_config = blacklight_config.facet_fields[field] defaults = [:"blacklight.search.fields.facet.#{field}", :"blacklight.search.fields.#{field}"] defaults << field_config.label if field_config defaults << field.to_s.humanize field_label(*defaults) end |
#label ⇒ Object #label ⇒ Object
Look up the label for a solr field.
148 149 150 151 152 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 148 def field_label *i18n_keys first, *rest = i18n_keys.compact t(first, default: rest) end |
#has_alternative_views? ⇒ Boolean
Check if there are alternative views configuration
175 176 177 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 175 def has_alternative_views? document_index_views.keys.length > 1 end |
#index_field_label(document, field) ⇒ Object
Look up the label for the index field
64 65 66 67 68 69 70 71 72 73 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 64 def index_field_label document, field field_config = index_fields(document)[field] field_label( :"blacklight.search.fields.index.#{field}", :"blacklight.search.fields.#{field}", (field_config.label if field_config), field.to_s.humanize ) end |
#index_fields(document = nil) ⇒ Array<Blacklight::Configuration::Field>
Index fields to display for a type of document
11 12 13 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 11 def index_fields document=nil blacklight_config.index_fields end |
#label_for_search_field(key) ⇒ Object
Shortcut for commonly needed operation, look up display label for the key specified. Returns “Keyword” if a label can't be found.
113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 113 def label_for_search_field(key) field_config = blacklight_config.search_fields[key] field_config ||= Blacklight::Configuration::NullField.new(key: key) field_label( :"blacklight.search.fields.search.#{field_config.key}", :"blacklight.search.fields.#{field_config.key}", (field_config.label if field_config), key.to_s.humanize ) end |
#per_page_options_for_select ⇒ Object
The available options for results per page, in the style of #options_for_select
211 212 213 214 215 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 211 def blacklight_config.per_page.map do |count| [t(:'blacklight.search.per_page.label', :count => count).html_safe, count] end end |
#search_field_options_for_select ⇒ Object
Returns suitable argument to options_for_select method, to create an html select based on #search_field_list. Skips search_fields marked :include_in_simple_select => false
33 34 35 36 37 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 33 def blacklight_config.search_fields.collect do |_key, field_def| [label_for_search_field(field_def.key), field_def.key] if should_render_field?(field_def) end.compact end |
#search_fields ⇒ Object
Used in the search form partial for building a select tag
26 27 28 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 26 def search_fields end |
#should_render_field?(field_config, *args) ⇒ Boolean
Determine whether to render a field by evaluating :if and :unless conditions
222 223 224 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 222 def should_render_field?(field_config, *args) blacklight_configuration_context.evaluate_if_unless_configuration field_config, *args end |
#sort_field_label(key) ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 125 def sort_field_label(key) field_config = blacklight_config.sort_fields[key] field_config ||= Blacklight::Configuration::NullField.new(key: key) field_label( :"blacklight.search.fields.sort.#{key}", (field_config.label if field_config), key.to_s.humanize ) end |
#sort_fields ⇒ Object
Used in the document_list partial (search view) for building a select element
16 17 18 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 16 def sort_fields active_sort_fields.map { |_sort_key, field_config| [sort_field_label(field_config.key), field_config.key] } end |
#spell_check_max ⇒ Object
Maximum number of results for spell checking
181 182 183 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 181 def spell_check_max blacklight_config.spell_max end |
#view_label(view) ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 99 def view_label view view_config = blacklight_config.view[view] field_label( :"blacklight.search.view_title.#{view}", :"blacklight.search.view.#{view}", view_config.label, view_config.title, view.to_s.humanize ) end |