Class: Practical::Views::Datatable::SortLinkComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Practical::Views::Datatable::SortLinkComponent
- Defined in:
- app/components/practical/views/datatable/sort_link_component.rb
Instance Attribute Summary collapse
-
#datatable_form ⇒ Object
Returns the value of attribute datatable_form.
-
#options ⇒ Object
Returns the value of attribute options.
-
#sort_key ⇒ Object
Returns the value of attribute sort_key.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .inverted_sort_direction(datatable_form:, sort_key:) ⇒ Object
- .merged_payload(datatable_form:, sort_key:) ⇒ Object
Instance Method Summary collapse
- #call ⇒ Object
- #icon ⇒ Object
-
#initialize(url:, datatable_form:, sort_key:, options: {}) ⇒ SortLinkComponent
constructor
A new instance of SortLinkComponent.
- #sort_direction ⇒ Object
Methods included from ElementHelper
Constructor Details
#initialize(url:, datatable_form:, sort_key:, options: {}) ⇒ SortLinkComponent
Returns a new instance of SortLinkComponent.
6 7 8 9 10 11 |
# File 'app/components/practical/views/datatable/sort_link_component.rb', line 6 def initialize(url:, datatable_form:, sort_key:, options: {}) self.url = url self.datatable_form = datatable_form self.sort_key = sort_key self. = end |
Instance Attribute Details
#datatable_form ⇒ Object
Returns the value of attribute datatable_form.
4 5 6 |
# File 'app/components/practical/views/datatable/sort_link_component.rb', line 4 def datatable_form @datatable_form end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'app/components/practical/views/datatable/sort_link_component.rb', line 4 def @options end |
#sort_key ⇒ Object
Returns the value of attribute sort_key.
4 5 6 |
# File 'app/components/practical/views/datatable/sort_link_component.rb', line 4 def sort_key @sort_key end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'app/components/practical/views/datatable/sort_link_component.rb', line 4 def url @url end |
Class Method Details
.inverted_sort_direction(datatable_form:, sort_key:) ⇒ Object
37 38 39 |
# File 'app/components/practical/views/datatable/sort_link_component.rb', line 37 def self.inverted_sort_direction(datatable_form:, sort_key:) datatable_form.inverted_sort_direction_for(key: sort_key) end |
.merged_payload(datatable_form:, sort_key:) ⇒ Object
41 42 43 44 45 46 47 |
# File 'app/components/practical/views/datatable/sort_link_component.rb', line 41 def self.merged_payload(datatable_form:, sort_key:) datatable_form.merged_payload(sort_key: sort_key, sort_direction: inverted_sort_direction(datatable_form: datatable_form, sort_key: sort_key ) ) end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'app/components/practical/views/datatable/sort_link_component.rb', line 13 def call tag.a(**mix({href: url}, )) { safe_join([ render(icon), content ]) } end |
#icon ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'app/components/practical/views/datatable/sort_link_component.rb', line 22 def icon case sort_direction when "desc" return icon_set.descending_icon when "asc" return icon_set.ascending_icon else return icon_set.sort_icon end end |
#sort_direction ⇒ Object
33 34 35 |
# File 'app/components/practical/views/datatable/sort_link_component.rb', line 33 def sort_direction datatable_form.sort_direction_for(key: sort_key) end |