Class: Blacklight::ConstraintsComponent
- Defined in:
- app/components/blacklight/constraints_component.rb
Class Method Summary collapse
-
.for_search_history ⇒ Object
Constraints are stored and used to display search history - with this method, we initialize the ConstraintsComponent in a way that displays well in a table (and without a start-over button).
Instance Method Summary collapse
-
#facet_constraints ⇒ String
HTML representation of facet constraints.
-
#initialize(search_state:, tag: :div, render_headers: true, heading_classes: 'constraints-label h6 mb-0', id: 'appliedParams', classes: 'clearfix constraints-container mb-2 align-items-center', query_constraint_component: Blacklight::ConstraintLayoutComponent, query_constraint_component_options: {}, facet_constraint_component: Blacklight::ConstraintComponent, facet_constraint_component_options: {}, start_over_component: Blacklight::StartOverButtonComponent) ⇒ ConstraintsComponent
constructor
rubocop:disable Metrics/ParameterLists.
-
#query_constraints ⇒ String
HTML representation of query constraints.
-
#remove_path ⇒ String
URL path to remove the current query.
-
#render? ⇒ Boolean
True if search state has constraints.
Methods inherited from Component
reset_compiler!, sidecar_files, upstream_sidecar_files
Constructor Details
#initialize(search_state:, tag: :div, render_headers: true, heading_classes: 'constraints-label h6 mb-0', id: 'appliedParams', classes: 'clearfix constraints-container mb-2 align-items-center', 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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/components/blacklight/constraints_component.rb', line 21 def initialize(search_state:, tag: :div, render_headers: true, heading_classes: 'constraints-label h6 mb-0', id: 'appliedParams', classes: 'clearfix constraints-container mb-2 align-items-center', 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 = @facet_constraint_component = facet_constraint_component = @start_over_component = start_over_component @render_headers = render_headers @heading_classes = heading_classes @tag = tag @id = id @classes = classes end |
Class Method Details
.for_search_history ⇒ Object
Constraints are stored and used to display search history - with this method, we initialize the ConstraintsComponent in a way that displays well in a table (and without a start-over button)
11 12 13 14 15 16 17 18 |
# File 'app/components/blacklight/constraints_component.rb', line 11 def self.for_search_history(**) new(tag: :span, render_headers: false, id: nil, query_constraint_component: Blacklight::SearchHistoryConstraintLayoutComponent, facet_constraint_component_options: { layout: Blacklight::SearchHistoryConstraintLayoutComponent }, start_over_component: nil, **) end |
Instance Method Details
#facet_constraints ⇒ String
Returns HTML representation of facet constraints.
69 70 71 |
# File 'app/components/blacklight/constraints_component.rb', line 69 def facet_constraints render(@facet_constraint_component.with_collection(constraint_presenters.to_a, **)) end |
#query_constraints ⇒ String
Returns HTML representation of query constraints.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/components/blacklight/constraints_component.rb', line 46 def query_constraints if @search_state.query_param.present? render( @query_constraint_component.new( search_state: @search_state, value: @search_state.query_param, label: label, remove_path: remove_path, classes: 'query', ** ) ) else ''.html_safe end + render(@facet_constraint_component.with_collection(clause_presenters.to_a, **)) end |
#remove_path ⇒ String
Returns URL path to remove the current query.
64 65 66 |
# File 'app/components/blacklight/constraints_component.rb', line 64 def remove_path helpers.search_action_path(@search_state.remove_query_params) end |
#render? ⇒ Boolean
Returns true if search state has constraints.
74 75 76 |
# File 'app/components/blacklight/constraints_component.rb', line 74 def render? @search_state.has_constraints? end |