Class: FoxTail::FilterSummaryComponent

Inherits:
BaseComponent show all
Defined in:
app/components/fox_tail/filter_summary_component.rb

Instance Attribute Summary

Attributes inherited from BaseComponent

#html_attributes

Instance Method Summary collapse

Methods inherited from BaseComponent

classname_merger, #initialize, stimulus_merger, use_stimulus?, #with_html_attributes, #with_html_class

Methods inherited from Base

fox_tail_config

Constructor Details

This class inherits a constructor from FoxTail::BaseComponent

Instance Method Details

#before_renderObject



54
55
56
57
58
# File 'app/components/fox_tail/filter_summary_component.rb', line 54

def before_render
  super

  html_attributes[:class] = classnames theme.apply(:root, self), html_class
end

#callObject



60
61
62
63
64
65
# File 'app/components/fox_tail/filter_summary_component.rb', line 60

def call
   :div, html_attributes do
    filters.each { |filter| concat filter }
    concat clear_button if clear_button?
  end
end

#clear_urlObject



67
68
69
70
71
72
73
# File 'app/components/fox_tail/filter_summary_component.rb', line 67

def clear_url
  uri = URI(url)
  params = Rack::Utils.parse_nested_query uri.query
  param_names.each { |name| params.delete name.to_s }
  uri.query = Rack::Utils.build_nested_query params
  uri.to_s
end

#remove_filter(params, name, options = {}) ⇒ Object



83
84
85
86
87
# File 'app/components/fox_tail/filter_summary_component.rb', line 83

def remove_filter(params, name, options = {})
  return params.delete(name.to_s) unless options.key? :value

  params[name.to_s]&.delete options[:value].to_s
end

#remove_filter_url(name, options = {}) ⇒ Object



75
76
77
78
79
80
81
# File 'app/components/fox_tail/filter_summary_component.rb', line 75

def remove_filter_url(name, options = {})
  uri = URI(url)
  params = Rack::Utils.parse_nested_query uri.query
  remove_filter params, name, options
  uri.query = Rack::Utils.build_nested_query params
  uri.to_s
end

#render?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/components/fox_tail/filter_summary_component.rb', line 50

def render?
  filters?
end

#urlObject



46
47
48
# File 'app/components/fox_tail/filter_summary_component.rb', line 46

def url
  options[:url] ||= request.original_fullpath
end