Module: Blacklight::ConfigurationHelperBehavior
- Extended by:
- Deprecation
- Included in:
- CatalogHelperBehavior
- Defined in:
- app/helpers/blacklight/configuration_helper_behavior.rb
Instance Method Summary collapse
-
#active_sort_fields ⇒ Array<Blacklight::Configuration::Field>
Return the available sort fields.
-
#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 ⇒ Hash<Symbol => Blacklight::Configuration::ViewConfig>
- #document_show_field_label(document, field) ⇒ String deprecated Deprecated.
-
#document_show_fields(_document = nil) ⇒ Array<Blacklight::Configuration::Field>
used in the catalog/_show partial.
- #document_show_link_field(document = nil) ⇒ Object deprecated Deprecated.
-
#facet_field_label(field) ⇒ String
Look up the label for the facet field.
-
#field_label(*i18n_keys) ⇒ String
Look up the label for a solr field.
-
#has_alternative_views? ⇒ Boolean
Check if there are alternative views configuration.
- #index_field_label(document, field) ⇒ String deprecated Deprecated.
-
#index_fields(_document = nil) ⇒ Array<Blacklight::Configuration::Field>
Index fields to display for a type of document.
-
#label_for_search_field(key) ⇒ String
Shortcut for commonly needed operation, look up display label for the key specified.
- #per_page_options_for_select ⇒ Object deprecated Deprecated.
-
#search_field_options_for_select ⇒ Array<Array>
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) ⇒ String
-
#spell_check_max ⇒ Number
Maximum number of results for spell checking.
-
#view_label(view) ⇒ String
Return the label for a search view.
Instance Method Details
#active_sort_fields ⇒ Array<Blacklight::Configuration::Field>
Return the available sort fields
18 19 20 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 18 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.
53 54 55 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 53 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
165 166 167 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 165 def default_document_index_view_type document_index_views.select { |_k, config| config.respond_to?(:default) && config.default }.keys.first || document_index_views.keys.first end |
#default_per_page ⇒ Object
The default value for search results per page
206 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 206 delegate :default_per_page, to: :blacklight_config |
#default_search_field?(selected_search_field) ⇒ Boolean
Is the search form using the default search field (“all_fields” by default)?
62 63 64 65 66 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 62 def default_search_field?(selected_search_field) Deprecation.silence(Blacklight::SearchFields) do selected_search_field.blank? || (default_search_field && selected_search_field == default_search_field[:key]) end end |
#default_sort_field ⇒ Object
Default sort field
200 201 202 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 200 def default_sort_field (active_sort_fields.find { |_k, config| config.respond_to?(:default) && config.default } || active_sort_fields.first)&.last end |
#document_index_view_controls ⇒ Object
filter #document_index_views to just views that should display in the view type control
157 158 159 160 161 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 157 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 ⇒ Hash<Symbol => Blacklight::Configuration::ViewConfig>
150 151 152 153 154 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 150 def document_index_views blacklight_config.view.select do |_k, config| should_render_field? config end end |
#document_show_field_label(document, field) ⇒ String
Look up the label for the show field
84 85 86 87 88 89 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 84 def document_show_field_label document, field field_config = blacklight_config.show_fields_for(document_presenter(document).display_type)[field] field_config ||= Blacklight::Configuration::NullField.new(key: field) field_config.display_label('show') end |
#document_show_fields(_document = nil) ⇒ Array<Blacklight::Configuration::Field>
used in the catalog/_show partial
42 43 44 45 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 42 def document_show_fields _document = nil Deprecation.warn(self, "document_show_fields is deprecated and will be removed in Blacklight 8. Use ShowPresenter#fields instead") 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
187 188 189 190 191 192 193 194 195 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 187 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&.to_sym field end |
#facet_field_label(field) ⇒ String
Look up the label for the facet field
95 96 97 98 99 100 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 95 def facet_field_label field field_config = blacklight_config.facet_fields[field] field_config ||= Blacklight::Configuration::NullField.new(key: field) field_config.display_label('facet') end |
#label ⇒ String #label ⇒ String
Look up the label for a solr field.
143 144 145 146 147 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 143 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
172 173 174 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 172 def has_alternative_views? document_index_views.keys.length > 1 end |
#index_field_label(document, field) ⇒ String
Look up the label for the index field
72 73 74 75 76 77 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 72 def index_field_label document, field field_config = blacklight_config.index_fields_for(document_presenter(document).display_type)[field] field_config ||= Blacklight::Configuration::NullField.new(key: field) field_config.display_label('index') end |
#index_fields(_document = nil) ⇒ Array<Blacklight::Configuration::Field>
Index fields to display for a type of document
10 11 12 13 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 10 def index_fields _document = nil Deprecation.warn(self, "index_fields is deprecated and will be removed in Blacklight 8. Use IndexPresenter#fields instead") blacklight_config.index_fields end |
#label_for_search_field(key) ⇒ String
Shortcut for commonly needed operation, look up display label for the key specified.
113 114 115 116 117 118 119 120 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 113 def label_for_search_field(key) field_config = blacklight_config.search_fields[key] return if key.nil? && field_config.nil? field_config ||= Blacklight::Configuration::NullField.new(key: key) field_config.display_label('search') end |
#per_page_options_for_select ⇒ Object
The available options for results per page, in the style of #options_for_select
212 213 214 215 216 217 218 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 212 def return [] if blacklight_config.per_page.blank? 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 ⇒ Array<Array>
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
24 25 26 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 24 def search_fields end |
#should_render_field?(field_config, *args) ⇒ Boolean
Determine whether to render a field by evaluating :if and :unless conditions
226 227 228 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 226 def should_render_field?(field_config, *args) blacklight_configuration_context.evaluate_if_unless_configuration field_config, *args end |
#sort_field_label(key) ⇒ String
123 124 125 126 127 128 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 123 def sort_field_label(key) field_config = blacklight_config.sort_fields[key] field_config ||= Blacklight::Configuration::NullField.new(key: key) field_config.display_label('sort') end |
#spell_check_max ⇒ Number
Maximum number of results for spell checking
180 181 182 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 180 def spell_check_max blacklight_config.spell_max end |
#view_label(view) ⇒ String
Return the label for a search view
104 105 106 107 |
# File 'app/helpers/blacklight/configuration_helper_behavior.rb', line 104 def view_label(view) view_config = blacklight_config.view[view] view_config.display_label end |