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.7.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.6.1 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.6.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.5.1 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.5.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.4.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.3.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.2.2 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.2.1 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.2.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.1.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.0.1 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.0.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.0.0.beta8 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.0.0.beta7 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.0.0.beta6 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.0.0.beta5 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.0.0.beta4 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-8.0.0.beta3 app/presenters/blacklight/facet_grouped_item_presenter.rb