Sha256: be1d0d938156c026bbac94133fd70e5e5b48fc6abfe65e8fc0a8feba3407cc5d

Contents?: true

Size: 1.58 KB

Versions: 21

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

module Blacklight
  class FacetItemPivotPresenter < FacetItemPresenter
    ##
    # Check if the query parameters have the given facet field with the
    # given value.
    def selected?
      search_state.filter(facet_config).include?(facet_item)
    end

    def shown?
      selected? || facet_item_presenters.any? { |x| x.try(:shown?) }
    end

    def field_label
      facet_field_presenter.label
    end

    def facet_item_presenters
      return to_enum(:facet_item_presenters) unless block_given?
      return [] unless items

      items.each { |i| yield facet_item_presenter(i) }
    end

    def facet_item_presenter(facet_item)
      facet_config.item_presenter.new(facet_item, facet_config, view_context, facet_field, search_state)
    end

    ##
    # Get the displayable version of a facet's value
    #
    # @return [String]
    def label
      label_source = facet_item.respond_to?(:label) ? facet_item.label : facet_item
      if facet_config.helper_method
        view_context.public_send(facet_config.helper_method, label_source)
      else
        item_fq = label_source.respond_to?(:fq) ? label_source.fq : {}
        item_fq = item_fq.symbolize_keys
        label_value = facet_config.pivot.map(&:to_sym).map { |k| item_fq[k] }
        if label_source.respond_to?(:field)
          label_value << value
        else
          label_value.unshift value
        end
        label_value.compact.join(" ยป ")
      end
    end

    def value
      if facet_item.respond_to? :value
        facet_item.value
      else
        facet_item
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
blacklight-8.6.1 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.6.0 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.5.1 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.5.0 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.4.0 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.3.0 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.2.2 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.2.1 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.2.0 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.1.0 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.0.1 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.0.0 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.0.0.beta8 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.0.0.beta7 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.0.0.beta6 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.0.0.beta5 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.0.0.beta4 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.0.0.beta3 app/presenters/blacklight/facet_item_pivot_presenter.rb
blacklight-8.0.0.beta2 app/presenters/blacklight/facet_item_pivot_presenter.rb