Class: Blacklight::FacetFieldPresenter
- Inherits:
 - 
      Object
      
        
- Object
 - Blacklight::FacetFieldPresenter
 
 
- Defined in:
 - app/presenters/blacklight/facet_field_presenter.rb
 
Constant Summary collapse
- DEFAULT_FACET_LIMIT =
 10
Instance Attribute Summary collapse
- 
  
    
      #display_facet  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute display_facet.
 - 
  
    
      #facet_field  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute facet_field.
 - 
  
    
      #search_state  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute search_state.
 - 
  
    
      #view_context  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute view_context.
 
Instance Method Summary collapse
- #active? ⇒ Boolean
 - #collapsed? ⇒ Boolean
 - 
  
    
      #each_value(&block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Appease rubocop rules by implementing #each_value.
 - 
  
    
      #facet_limit  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Look up facet limit for given facet_field.
 - #in_advanced_search? ⇒ Boolean
 - #in_modal? ⇒ Boolean
 - 
  
    
      #initialize(facet_field, display_facet, view_context, search_state = view_context.search_state)  ⇒ FacetFieldPresenter 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of FacetFieldPresenter.
 - #label ⇒ Object
 - #modal_path ⇒ Object
 - #paginator ⇒ Object
 - #values ⇒ Object
 
Constructor Details
#initialize(facet_field, display_facet, view_context, search_state = view_context.search_state) ⇒ FacetFieldPresenter
Returns a new instance of FacetFieldPresenter.
      10 11 12 13 14 15  | 
    
      # File 'app/presenters/blacklight/facet_field_presenter.rb', line 10 def initialize(facet_field, display_facet, view_context, search_state = view_context.search_state) @facet_field = facet_field @display_facet = display_facet @view_context = view_context @search_state = search_state end  | 
  
Instance Attribute Details
#display_facet ⇒ Object (readonly)
Returns the value of attribute display_facet.
      5 6 7  | 
    
      # File 'app/presenters/blacklight/facet_field_presenter.rb', line 5 def display_facet @display_facet end  | 
  
#facet_field ⇒ Object (readonly)
Returns the value of attribute facet_field.
      5 6 7  | 
    
      # File 'app/presenters/blacklight/facet_field_presenter.rb', line 5 def facet_field @facet_field end  | 
  
#search_state ⇒ Object (readonly)
Returns the value of attribute search_state.
      5 6 7  | 
    
      # File 'app/presenters/blacklight/facet_field_presenter.rb', line 5 def search_state @search_state end  | 
  
#view_context ⇒ Object (readonly)
Returns the value of attribute view_context.
      5 6 7  | 
    
      # File 'app/presenters/blacklight/facet_field_presenter.rb', line 5 def view_context @view_context end  | 
  
Instance Method Details
#active? ⇒ Boolean
      21 22 23 24 25 26 27  | 
    
      # File 'app/presenters/blacklight/facet_field_presenter.rb', line 21 def active? if in_advanced_search? search_state.filter(facet_field).values(except: [:filters, :missing]).any? else search_state.filter(facet_field).any? end end  | 
  
#collapsed? ⇒ Boolean
      17 18 19  | 
    
      # File 'app/presenters/blacklight/facet_field_presenter.rb', line 17 def collapsed? !active? && facet_field.collapse end  | 
  
#each_value(&block) ⇒ Object
Appease rubocop rules by implementing #each_value
      52 53 54  | 
    
      # File 'app/presenters/blacklight/facet_field_presenter.rb', line 52 def each_value(&block) values.each(&block) end  | 
  
#facet_limit ⇒ Object
Look up facet limit for given facet_field. Will look at config, and if config is ‘true’ will look up from Solr @response if available. If no limit is available, returns nil. Used from #add_facetting_to_solr to supply f.fieldname.facet.limit values in solr request (no @response available), and used in display (with @response available) to create a facet paginator with the right limit.
      76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92  | 
    
      # File 'app/presenters/blacklight/facet_field_presenter.rb', line 76 def facet_limit return unless facet_field.limit if @display_facet limit = @display_facet.limit if limit.nil? # we didn't get or a set a limit, so infer one. facet_field.limit if facet_field.limit != true elsif limit == -1 # limit -1 is solr-speak for unlimited nil else limit.to_i - 1 # we added 1 to find out if we needed to paginate end else facet_field.limit == true ? DEFAULT_FACET_LIMIT : facet.limit end end  | 
  
#in_advanced_search? ⇒ Boolean
      29 30 31  | 
    
      # File 'app/presenters/blacklight/facet_field_presenter.rb', line 29 def in_advanced_search? search_state.params[:action] == "advanced_search" end  | 
  
#in_modal? ⇒ Boolean
      33 34 35  | 
    
      # File 'app/presenters/blacklight/facet_field_presenter.rb', line 33 def in_modal? search_state.params[:action] == "facet" end  | 
  
#label ⇒ Object
      43 44 45  | 
    
      # File 'app/presenters/blacklight/facet_field_presenter.rb', line 43 def label view_context.facet_field_label(key) end  | 
  
#modal_path ⇒ Object
      37 38 39 40 41  | 
    
      # File 'app/presenters/blacklight/facet_field_presenter.rb', line 37 def modal_path return unless paginator view_context.search_facet_path(id: key) unless paginator&.last_page? end  | 
  
#paginator ⇒ Object
      56 57 58 59 60 61 62 63 64 65 66  | 
    
      # File 'app/presenters/blacklight/facet_field_presenter.rb', line 56 def paginator return unless display_facet @paginator ||= blacklight_config.facet_paginator_class.new( display_facet.items, sort: display_facet.sort, offset: display_facet.offset, prefix: display_facet.prefix, limit: facet_limit ) end  | 
  
#values ⇒ Object
      47 48 49  | 
    
      # File 'app/presenters/blacklight/facet_field_presenter.rb', line 47 def values search_state&.filter(facet_field)&.values || [] end  |