Class: Blacklight::ConstraintsComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/blacklight/constraints_component.rb

Constant Summary

Constants inherited from Component

Blacklight::Component::EXCLUDE_VARIABLES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Component

compiler, config, #inspect

Constructor Details

#initialize(search_state:, tag: :div, render_headers: true, id: 'appliedParams', classes: 'clearfix constraints-container', query_constraint_component: Blacklight::ConstraintLayoutComponent, query_constraint_component_options: {}, facet_constraint_component: Blacklight::ConstraintComponent, facet_constraint_component_options: {}, start_over_component: Blacklight::StartOverButtonComponent) ⇒ ConstraintsComponent

rubocop:disable Metrics/ParameterLists



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/components/blacklight/constraints_component.rb', line 20

def initialize(search_state:,
               tag: :div,
               render_headers: true,
               id: 'appliedParams', classes: 'clearfix constraints-container',
               query_constraint_component: Blacklight::ConstraintLayoutComponent,
               query_constraint_component_options: {},
               facet_constraint_component: Blacklight::ConstraintComponent,
               facet_constraint_component_options: {},
               start_over_component: Blacklight::StartOverButtonComponent)
  @search_state = search_state
  @query_constraint_component = query_constraint_component
  @query_constraint_component_options = query_constraint_component_options
  @facet_constraint_component = facet_constraint_component
  @facet_constraint_component_options = facet_constraint_component_options
  @start_over_component = start_over_component
  @render_headers = render_headers
  @tag = tag
  @id = id
  @classes = classes
end

Class Method Details

.for_search_history(**kwargs) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'app/components/blacklight/constraints_component.rb', line 9

def self.for_search_history(**kwargs)
  new(tag: :span,
      render_headers: false,
      id: nil,
      query_constraint_component: Blacklight::SearchHistoryConstraintLayoutComponent,
      facet_constraint_component_options: { layout: Blacklight::SearchHistoryConstraintLayoutComponent },
      start_over_component: nil,
      **kwargs)
end

Instance Method Details

#facet_constraintsObject



63
64
65
# File 'app/components/blacklight/constraints_component.rb', line 63

def facet_constraints
  helpers.render(@facet_constraint_component.with_collection(facet_item_presenters.to_a, **@facet_constraint_component_options))
end

#query_constraintsObject

rubocop:enable Metrics/ParameterLists



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/components/blacklight/constraints_component.rb', line 42

def query_constraints
  if @search_state.query_param.present?
    helpers.render(
      @query_constraint_component.new(
        search_state: @search_state,
        value: @search_state.query_param,
        label: label,
        remove_path: remove_path,
        classes: 'query',
        **@query_constraint_component_options
      )
    )
  else
    ''.html_safe
  end + helpers.render(@facet_constraint_component.with_collection(clause_presenters.to_a, **@facet_constraint_component_options))
end

#remove_pathObject



59
60
61
# File 'app/components/blacklight/constraints_component.rb', line 59

def remove_path
  helpers.search_action_path(@search_state.remove_query_params)
end

#render?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/components/blacklight/constraints_component.rb', line 67

def render?
  @search_state.has_constraints?
end