Sha256: 0d430eefb3613582bc0522fab5ae2234e017f411d3224aa9695d6ff8f9e491e5

Contents?: true

Size: 1.76 KB

Versions: 14

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

module Arclight
  # Display a single document in the collection hierarchy
  class DocumentCollectionHierarchyComponent < Arclight::SearchResultComponent
    # @param [Blacklight::DocumentPresenter] document
    # @param [String] nest_path determines which element to highlight
    def initialize(document: nil, nest_path: nil, blacklight_config: nil, **kwargs)
      super(document: document, **kwargs)
      @nest_path = nest_path
      @blacklight_config = blacklight_config
    end

    attr_reader :blacklight_config

    def classes
      super - ['row']
    end

    # we want to eager-load this document's children if we're in the
    # target document's component hierarchy
    def show_expanded?
      within_original_tree?
    end

    # Solr nest paths are constructed using the path name and an index, e.g.
    # `/components#5/components#3`.
    #
    # @return [String] the targeted index for this level of the hierarchy
    def target_index
      return -1 unless within_original_tree?

      remaining_path = nest_path.sub("#{@document.nest_path}/", '')
      current_component, _rest = remaining_path.split('/', 2)
      _name, index = current_component.split('#', 2)

      index&.to_i
    end

    private

    # We're in the targeted document's original tree if the target nest path
    # includes this document's path.
    def within_original_tree?
      nest_path&.start_with? "#{@document.nest_path}/"
    end

    def current_target?
      nest_path == @document.nest_path
    end

    def online_status
      render online_status_component.new(document: @document)
    end

    def online_status_component
      blacklight_config.show.online_status_component || Arclight::OnlineStatusIndicatorComponent
    end

    attr_reader :nest_path
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
arclight-1.4.0 app/components/arclight/document_collection_hierarchy_component.rb
arclight-1.3.0 app/components/arclight/document_collection_hierarchy_component.rb
arclight-1.2.0 app/components/arclight/document_collection_hierarchy_component.rb
arclight-1.1.3 app/components/arclight/document_collection_hierarchy_component.rb
arclight-1.1.2 app/components/arclight/document_collection_hierarchy_component.rb
arclight-1.1.1 app/components/arclight/document_collection_hierarchy_component.rb
arclight-1.1.0 app/components/arclight/document_collection_hierarchy_component.rb
arclight-1.0.1 app/components/arclight/document_collection_hierarchy_component.rb
arclight-1.0.0 app/components/arclight/document_collection_hierarchy_component.rb
arclight-1.0.0.beta6 app/components/arclight/document_collection_hierarchy_component.rb
arclight-1.0.0.beta4 app/components/arclight/document_collection_hierarchy_component.rb
arclight-1.0.0.beta3 app/components/arclight/document_collection_hierarchy_component.rb
arclight-1.0.0.beta2 app/components/arclight/document_collection_hierarchy_component.rb
arclight-1.0.0.beta1 app/components/arclight/document_collection_hierarchy_component.rb