Module: RangeLimitHelper

Extended by:
Deprecation
Defined in:
app/helpers/range_limit_helper.rb

Instance Method Summary collapse

Instance Method Details

#add_range(solr_field, from, to, my_params = params) ⇒ Object



83
84
85
# File 'app/helpers/range_limit_helper.rb', line 83

def add_range(solr_field, from, to, my_params = params)
  Blacklight::SearchState.new(my_params.except(:page), blacklight_config).filter(solr_field).add(from..to)
end

#add_range_missing(solr_field, my_params = params) ⇒ Object



78
79
80
# File 'app/helpers/range_limit_helper.rb', line 78

def add_range_missing(solr_field, my_params = params)
  Blacklight::SearchState.new(my_params.except(:page), blacklight_config).filter(solr_field).add(Blacklight::SearchState::FilterField::MISSING)
end

#format_range_display_value(value, solr_field) ⇒ Object

A method that is meant to be overridden downstream to format how a range label might be displayed to a user. By default it just returns the value as rendered by the presenter



50
51
52
53
# File 'app/helpers/range_limit_helper.rb', line 50

def format_range_display_value(value, solr_field)
  Deprecation.warn(RangeLimitHelper, 'Helper #format_range_display_value is deprecated without replacement')
  facet_item_presenter(facet_configuration_for_field(solr_field), value, solr_field).label
end

#has_selected_range_limit?(solr_field) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
# File 'app/helpers/range_limit_helper.rb', line 88

def has_selected_range_limit?(solr_field)
  range_facet_field_presenter(solr_field).selected_range.present?
end

#range_config(solr_field) ⇒ Object



113
114
115
# File 'app/helpers/range_limit_helper.rb', line 113

def range_config(solr_field)
  BlacklightRangeLimit.range_config(blacklight_config, solr_field)
end

#range_display(solr_field, my_params = params) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'app/helpers/range_limit_helper.rb', line 35

def range_display(solr_field, my_params = params)
  facet_config = blacklight_config.facet_fields[solr_field]
  presenter = range_facet_field_presenter(solr_field)
  return unless presenter.selected_range

  facet_item = Blacklight::Solr::Response::Facets::FacetItem.new(value: presenter.selected_range, hits: presenter.response.total)

  facet_config.item_presenter.new(facet_item, facet_config, self, solr_field).label
end

#range_limit_panel_url(options = {}) ⇒ Object



9
10
11
# File 'app/helpers/range_limit_helper.rb', line 9

def range_limit_panel_url(options = {})
  search_facet_path(id: options[:id])
end

#range_limit_url(options = {}) ⇒ Object



4
5
6
# File 'app/helpers/range_limit_helper.rb', line 4

def range_limit_url(options = {})
  main_app.url_for(search_state.to_h.merge(action: 'range_limit').merge(options))
end

#range_results_endpoint(solr_field, type) ⇒ Object

type is ‘min’ or ‘max’ Returns smallest and largest value in current result set, if available from stats component response.



23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/range_limit_helper.rb', line 23

def range_results_endpoint(solr_field, type)
  presenter = range_facet_field_presenter(solr_field)

  case type.to_s
  when 'min'
    presenter.min
  when 'max'
    presenter.max
  end
end

#remove_range_param(solr_field, my_params = params) ⇒ Object



98
99
100
# File 'app/helpers/range_limit_helper.rb', line 98

def remove_range_param(solr_field, my_params = params)
  Blacklight::SearchState.new(my_params.except(:page), blacklight_config).filter(solr_field).remove(0..0)
end

#render_range_input(solr_field, type, input_label = nil, maxlength = 4) ⇒ Object

type is ‘begin’ or ‘end’



15
16
17
# File 'app/helpers/range_limit_helper.rb', line 15

def render_range_input(solr_field, type, input_label = nil, maxlength=4)
  range_form_component(solr_field).render_range_input(type, input_label, maxlength)
end

#selected_missing_for_range_limit?(solr_field) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
# File 'app/helpers/range_limit_helper.rb', line 93

def selected_missing_for_range_limit?(solr_field)
  search_state.filter(solr_field).values.first == Blacklight::SearchState::FilterField::MISSING
end

#should_show_limit(solr_field) ⇒ Object

Show the limit area if: 1) we have a limit already set OR 2) stats show max > min, OR 3) count > 0 if no stats available.



60
61
62
63
64
65
66
# File 'app/helpers/range_limit_helper.rb', line 60

def should_show_limit(solr_field)
  presenter = range_facet_field_presenter(solr_field)

  presenter.selected_range ||
    (presenter.max && presenter.min && presenter.max > presenter.min) ||
    @response.total.positive?
end

#solr_range_queries_to_a(solr_field) ⇒ Object

Looks in the solr @response for [“facet_counts“][solr_field], for elements expressed as ”solr_field:[X to Y]“, turns them into a list of hashes with [:from, :to, :count], sorted by :from. Assumes integers for sorting purposes.



106
107
108
109
110
# File 'app/helpers/range_limit_helper.rb', line 106

def solr_range_queries_to_a(solr_field)
  range_facet_field_presenter(solr_field).range_queries.map do |item|
    { from: item.value.first, to: item.value.last, count: item.hits }
  end
end

#stats_for_field(solr_field) ⇒ Object



68
69
70
# File 'app/helpers/range_limit_helper.rb', line 68

def stats_for_field(solr_field)
  range_facet_field_presenter(solr_field).send(:stats_for_field)
end

#stats_for_field?(solr_field) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'app/helpers/range_limit_helper.rb', line 73

def stats_for_field?(solr_field)
  stats_for_field(solr_field).present?
end