Class: BlacklightRangeLimit::RangeFacetComponent

Inherits:
Blacklight::Component
  • Object
show all
Defined in:
app/components/blacklight_range_limit/range_facet_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(facet_field:, layout: nil, classes: BlacklightRangeLimit.classes) ⇒ RangeFacetComponent

Returns a new instance of RangeFacetComponent.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/components/blacklight_range_limit/range_facet_component.rb', line 7

def initialize(facet_field:, layout: nil, classes: BlacklightRangeLimit.classes)
  @facet_field = facet_field
  @layout = if layout == false
              Blacklight::FacetFieldNoLayoutComponent
            elsif layout
              layout
            elsif defined?(Blacklight::Facets::FacetFieldComponent)
              Blacklight::Facets::FacetFieldComponent # Blacklight 9
            else
              Blacklight::FacetFieldComponent # Blacklight < 9
            end

  @classes = classes
end

Instance Method Details

URL that will return the distribution list of range seguments



45
46
47
48
49
50
51
52
53
54
# File 'app/components/blacklight_range_limit/range_facet_component.rb', line 45

def load_distribution_link
  # For open-ended ranges, the selected range should take priority for the boundary
  # over actual response min/max. Matters for multi-valued fields.
  min = @facet_field.selected_range_facet_item&.value&.begin || @facet_field.min
  max = @facet_field.selected_range_facet_item&.value&.end || @facet_field.max

  return nil unless min && max

  range_limit_url(range_start: min, range_end: max)
end

#range_configObject



31
32
33
# File 'app/components/blacklight_range_limit/range_facet_component.rb', line 31

def range_config
  @facet_field.range_config
end

#range_limit_url(options = {}) ⇒ Object



35
36
37
38
# File 'app/components/blacklight_range_limit/range_facet_component.rb', line 35

def range_limit_url(options = {})
  helpers.main_app.url_for(@facet_field.search_state.to_h.merge(range_field: @facet_field.key,
                                                                action: 'range_limit').merge(options))
end

#render?Boolean

Don’t render if we have no values at all – most commonly on a zero results page. Normally we’ll have at least a min and a max (of values in result set, solr returns), OR a count of objects missing a value – if we don’t have ANY of that, there is literally nothing we can display, and we’re probably in a zero results situation.

Returns:

  • (Boolean)


26
27
28
29
# File 'app/components/blacklight_range_limit/range_facet_component.rb', line 26

def render?
  (@facet_field.min.present? && @facet_field.max.present?) ||
    @facet_field.missing_facet_item.present?
end

#uses_distribution?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/components/blacklight_range_limit/range_facet_component.rb', line 40

def uses_distribution?
  range_config[:chart_js] || range_config[:textual_facets]
end