Sha256: c1852f17bd8866372154b9d09e0f70bc2f2729c801056ef09292a577e433193d

Contents?: true

Size: 1.19 KB

Versions: 22

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Blacklight
  class FacetGroupedItemPresenter < Blacklight::FacetItemPresenter
    attr_reader :group

    delegate :key, to: :facet_config

    def initialize(group, facet_item, facet_config, view_context, facet_field, search_state = view_context.search_state)
      super(facet_item, facet_config, view_context, facet_field, search_state)
      @group = group
    end

    ##
    # Check if the query parameters have the given facet field with the
    # given value.
    def selected?
      group.include?(facet_item)
    end

    # @private
    def remove_href(path = search_state)
      new_state = path.filter(facet_config).remove(group)
      new_state = new_state.filter(facet_config).add(group - [facet_item])

      view_context.search_action_path(new_state)
    end

    # @private
    def add_href(_path_options = {})
      if facet_config.url_method
        return view_context.public_send(facet_config.url_method, facet_config.key, facet_item)
      end

      new_state = search_state.filter(facet_config).remove(@group)
      new_state = new_state.filter(facet_config).add(@group + [facet_item])

      view_context.search_action_path(new_state)
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
blacklight-8.0.0.beta2 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.0.0.beta1 app/presenters/blacklight/facet_grouped_item_presenter.rb