Sha256: aed2a42a7b3b6aaa0fba450030eaeed7947144aa72a3c4fecd407a97bcb97d3a

Contents?: true

Size: 1.28 KB

Versions: 25

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true
module Blacklight
  # These are methods that are used at both the view helper and controller layers
  # They are only dependent on `blacklight_config` and `@response`
  #
  module Facet
    delegate :facet_configuration_for_field, to: :blacklight_config

    def facet_paginator(field_config, response_data)
      blacklight_config.facet_paginator_class.new(
        response_data.items,
        sort: response_data.sort,
        offset: response_data.offset,
        prefix: response_data.prefix,
        limit: facet_limit_for(field_config.key)
      )
    end

    def facets_from_request(fields = facet_field_names)
      fields.map { |field| facet_by_field_name(field) }.compact
    end

    def facet_field_names
      blacklight_config.facet_fields.values.map(&:field)
    end

    # Get a FacetField object from the @response
    def facet_by_field_name(field_or_field_name)
      case field_or_field_name
      when String, Symbol
        facet_field = facet_configuration_for_field(field_or_field_name)
        @response.aggregations[facet_field.field]
      when Blacklight::Configuration::FacetField
        @response.aggregations[field_or_field_name.field]
      else
        # is this really a useful case?
        field_or_field_name
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
blacklight-6.25.0 app/controllers/concerns/blacklight/facet.rb
blacklight-6.24.0 app/controllers/concerns/blacklight/facet.rb
blacklight-6.23.0 app/controllers/concerns/blacklight/facet.rb
blacklight-6.22.0 app/controllers/concerns/blacklight/facet.rb
blacklight-6.21.0 app/controllers/concerns/blacklight/facet.rb
blacklight-6.20.0 app/controllers/concerns/blacklight/facet.rb
blacklight-6.19.2 app/controllers/concerns/blacklight/facet.rb
blacklight-6.19.1 app/controllers/concerns/blacklight/facet.rb
blacklight-6.19.0 app/controllers/concerns/blacklight/facet.rb
blacklight-6.18.0 app/controllers/concerns/blacklight/facet.rb
blacklight-6.17.0 app/controllers/concerns/blacklight/facet.rb
blacklight-6.16.0 app/controllers/concerns/blacklight/facet.rb
blacklight-6.15.0 app/controllers/concerns/blacklight/facet.rb
blacklight-7.0.0.rc1 app/controllers/concerns/blacklight/facet.rb
blacklight-6.14.1 app/controllers/concerns/blacklight/facet.rb
blacklight-6.14.0 app/controllers/concerns/blacklight/facet.rb
blacklight-6.13.0 app/controllers/concerns/blacklight/facet.rb
blacklight-6.12.0 app/controllers/concerns/blacklight/facet.rb
blacklight-6.11.2 app/controllers/concerns/blacklight/facet.rb
blacklight-6.11.1 app/controllers/concerns/blacklight/facet.rb