Module: Blacklight::ConfigurationHelperBehavior

Extended by:
Deprecation
Included in:
BlacklightConfigurationHelper
Defined in:
app/helpers/blacklight/configuration_helper_behavior.rb

Instance Method Summary collapse

Instance Method Details

#active_sort_fieldsObject



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.

Parameters:

  • localized_params (Hash) (defaults to: params)

    query parameters

Returns:

  • (String)


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_typeObject

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_pageObject

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)?

Parameters:

  • selected_search_field (String)

    the currently selected search_field

Returns:

  • (Boolean)


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_fieldObject

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_controlsObject

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_viewsObject



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

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

#labelObject #labelObject

Look up the label for a solr field.

Overloads:

  • #labelObject

    Parameters:

    • an (Symbol)

      i18n key

  • #labelObject

    Parameters:

    • default (String)

      label to display if the i18n look up fails

    • i18n (Symbol)

      keys to attempt to look up before falling back to the label

    • any (Symbol)

      number of additional keys

    • ... (Symbol)


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

Returns:

  • (Boolean)


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

Parameters:

Returns:



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_selectObject

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 per_page_options_for_select
  blacklight_config.per_page.map do |count|
    [t(:'blacklight.search.per_page.label', :count => count).html_safe, count]
  end
end

#search_field_options_for_selectObject

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 search_field_options_for_select
  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_fieldsObject

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
  search_field_options_for_select
end

#should_render_field?(field_config, *args) ⇒ Boolean

Determine whether to render a field by evaluating :if and :unless conditions

Parameters:

  • field_config (Blacklight::Solr::Configuration::Field)

Returns:

  • (Boolean)


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_fieldsObject

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_maxObject

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