Sha256: ab2a79bdbc052413966d6f1fcc2228353add58c3f90294d932fedc404ca36b5d

Contents?: true

Size: 1.28 KB

Versions: 48

Compression:

Stored size: 1.28 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)
      @group = group
      @facet_item = facet_item
      @facet_config = facet_config
      @view_context = view_context
      @facet_field = facet_field
      @search_state = search_state
    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

48 entries across 48 versions & 2 rubygems

Version Path
blacklight-7.40.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.39.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.38.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.37.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.36.2 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.36.1 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.36.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.35.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.34.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.33.1 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.33.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.32.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.31.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.30.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.29.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.28.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.27.1 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.27.0 app/presenters/blacklight/facet_grouped_item_presenter.rb
blacklight-7.26.1 app/presenters/blacklight/facet_grouped_item_presenter.rb