Module: StimulusTableFilter::ViewHelper
- Defined in:
- lib/stimulus_table_filter/view_helper.rb,
lib/stimulus_table_filter/view_helper/rows.rb,
lib/stimulus_table_filter/view_helper/sort.rb,
lib/stimulus_table_filter/view_helper/stats.rb,
lib/stimulus_table_filter/view_helper/controls.rb,
lib/stimulus_table_filter/view_helper/container.rb
Instance Method Summary collapse
- #table_filter_active_filter_tag(dimension: nil, **opts) ⇒ Object
- #table_filter_column_tag(col:, label:, type: nil, sortable: true) ⇒ Object
- #table_filter_container_tag(sort: 'name', dir: 'asc', page: nil, page_size: nil, url_key: nil, debounce_ms: nil, tag: :div, **opts) ⇒ Object
- #table_filter_count_tag(dimension:, value:, **opts) ⇒ Object
- #table_filter_empty_row_tag(**opts) ⇒ Object
- #table_filter_filter_btn_tag(value, label, dimension: nil, **opts) ⇒ Object
- #table_filter_footer_tag(colspan: nil, tag: :tfoot, **opts) ⇒ Object
- #table_filter_group_header_tag(group, tag: :tr, **opts) ⇒ Object
- #table_filter_match_count_tag ⇒ Object
- #table_filter_match_pct_tag ⇒ Object
- #table_filter_next_btn_tag(label = '→', **opts) ⇒ Object
- #table_filter_page_info_tag(**opts) ⇒ Object
- #table_filter_prev_btn_tag(label = '←', **opts) ⇒ Object
- #table_filter_row_attrs(name:, filters: {}, sort: {}, searchable: nil, group: nil) ⇒ Object
- #table_filter_row_tag(name:, filters: {}, sort: {}, searchable: nil, group: nil, tag: :tr, **html_options) ⇒ Object
- #table_filter_search_tag(**opts) ⇒ Object
- #table_filter_select_tag(options, dimension: nil, **opts) ⇒ Object
- #table_filter_sort_btn_tag(col, label, type: nil) ⇒ Object
- #table_filter_sort_th_tag(col, label, type: nil) ⇒ Object
- #table_filter_total_count_tag ⇒ Object
Instance Method Details
#table_filter_active_filter_tag(dimension: nil, **opts) ⇒ Object
19 20 21 22 23 |
# File 'lib/stimulus_table_filter/view_helper/controls.rb', line 19 def table_filter_active_filter_tag(dimension: nil, **opts, &) data = target_data('filterDisplay', opts) data[:filter_dimension] = dimension if dimension content_tag(:span, data: data, hidden: true, **opts, &) end |
#table_filter_column_tag(col:, label:, type: nil, sortable: true) ⇒ Object
13 14 15 16 17 |
# File 'lib/stimulus_table_filter/view_helper/sort.rb', line 13 def table_filter_column_tag(col:, label:, type: nil, sortable: true, **) return content_tag(:th, label, scope: 'col', **) unless sortable table_filter_sort_th_tag(col, label, type: type, **) end |
#table_filter_container_tag(sort: 'name', dir: 'asc', page: nil, page_size: nil, url_key: nil, debounce_ms: nil, tag: :div, **opts) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/stimulus_table_filter/view_helper/container.rb', line 5 def table_filter_container_tag(sort: 'name', dir: 'asc', page: nil, page_size: nil, url_key: nil, debounce_ms: nil, tag: :div, **opts, &) data = container_data(sort:, dir:, page:, page_size:, url_key:, debounce_ms:).merge(opts.delete(:data) || {}) content_tag(tag, data: data, **opts, &) end |
#table_filter_count_tag(dimension:, value:, **opts) ⇒ Object
19 20 21 22 |
# File 'lib/stimulus_table_filter/view_helper/stats.rb', line 19 def table_filter_count_tag(dimension:, value:, **opts) data = with_data({ count_dimension: dimension, count_value: value }, opts) content_tag(:span, '', data: data, **opts) end |
#table_filter_empty_row_tag(**opts) ⇒ Object
13 14 15 16 17 |
# File 'lib/stimulus_table_filter/view_helper/controls.rb', line 13 def table_filter_empty_row_tag(**opts, &) data = target_data('emptyRow', opts) klass = ['hidden', *Array(opts.delete(:class))].join(' ') content_tag(:tr, data: data, class: klass, **opts, &) end |
#table_filter_filter_btn_tag(value, label, dimension: nil, **opts) ⇒ Object
7 8 9 10 11 |
# File 'lib/stimulus_table_filter/view_helper/controls.rb', line 7 def table_filter_filter_btn_tag(value, label, dimension: nil, **opts) data = with_data({ filter_btn: value }, opts) data[:filter_dimension] = dimension if dimension content_tag(:button, label, data: data, **opts) end |
#table_filter_footer_tag(colspan: nil, tag: :tfoot, **opts) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/stimulus_table_filter/view_helper/stats.rb', line 24 def (colspan: nil, tag: :tfoot, **opts, &) content_tag(tag) do content_tag(:tr) do td_opts = colspan ? { colspan: colspan } : {} content_tag(:td, **td_opts, **opts) { (&) } end end end |
#table_filter_group_header_tag(group, tag: :tr, **opts) ⇒ Object
20 21 22 23 |
# File 'lib/stimulus_table_filter/view_helper/rows.rb', line 20 def table_filter_group_header_tag(group, tag: :tr, **opts, &) data = with_data({ table_filter_target: 'groupHeader', group: group.to_s }, opts) content_tag(tag, data: data, **opts, &) end |
#table_filter_match_count_tag ⇒ Object
15 |
# File 'lib/stimulus_table_filter/view_helper/stats.rb', line 15 def table_filter_match_count_tag(**) = table_filter_stat_span('matchCount', **) |
#table_filter_match_pct_tag ⇒ Object
17 |
# File 'lib/stimulus_table_filter/view_helper/stats.rb', line 17 def table_filter_match_pct_tag(**) = table_filter_stat_span('matchPct', **) |
#table_filter_next_btn_tag(label = '→', **opts) ⇒ Object
9 10 11 |
# File 'lib/stimulus_table_filter/view_helper/stats.rb', line 9 def table_filter_next_btn_tag(label = '→', **opts) content_tag(:button, label, data: with_data({ next_page: '', table_filter_target: 'nextPage' }, opts), **opts) end |
#table_filter_page_info_tag(**opts) ⇒ Object
13 |
# File 'lib/stimulus_table_filter/view_helper/stats.rb', line 13 def table_filter_page_info_tag(**opts) = content_tag(:span, '', data: target_data('pageInfo', opts), **opts) |
#table_filter_prev_btn_tag(label = '←', **opts) ⇒ Object
5 6 7 |
# File 'lib/stimulus_table_filter/view_helper/stats.rb', line 5 def table_filter_prev_btn_tag(label = '←', **opts) content_tag(:button, label, data: with_data({ prev_page: '', table_filter_target: 'prevPage' }, opts), **opts) end |
#table_filter_row_attrs(name:, filters: {}, sort: {}, searchable: nil, group: nil) ⇒ Object
5 6 7 8 9 |
# File 'lib/stimulus_table_filter/view_helper/rows.rb', line 5 def table_filter_row_attrs(name:, filters: {}, sort: {}, searchable: nil, group: nil) data = { table_filter_target: 'row', name: name.to_s.downcase, **filter_data(filters), **sort_data(sort) } extras = { searchable: searchable&.to_s&.downcase, group: group&.to_s }.compact { data: data.merge(extras) } end |
#table_filter_row_tag(name:, filters: {}, sort: {}, searchable: nil, group: nil, tag: :tr, **html_options) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/stimulus_table_filter/view_helper/rows.rb', line 11 def table_filter_row_tag(name:, filters: {}, sort: {}, searchable: nil, group: nil, tag: :tr, **, &) data = with_data( table_filter_row_attrs(name: name, filters: filters, sort: sort, searchable: searchable, group: group)[:data], ) content_tag(tag, data: data, **, &) end |
#table_filter_search_tag(**opts) ⇒ Object
5 |
# File 'lib/stimulus_table_filter/view_helper/controls.rb', line 5 def table_filter_search_tag(**opts) = tag.input(type: 'search', data: target_data('search', opts), **opts) |
#table_filter_select_tag(options, dimension: nil, **opts) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/stimulus_table_filter/view_helper/controls.rb', line 25 def table_filter_select_tag(, dimension: nil, **opts) data = with_data({ table_filter_target: 'filterSelect' }, opts) data[:filter_dimension] = dimension if dimension pairs = () content_tag(:select, data: data, **opts) { (pairs) } end |
#table_filter_sort_btn_tag(col, label, type: nil) ⇒ Object
5 6 7 |
# File 'lib/stimulus_table_filter/view_helper/sort.rb', line 5 def table_filter_sort_btn_tag(col, label, type: nil, **) table_filter_build_sort_trigger(:button, col, label, type: type, **) end |
#table_filter_sort_th_tag(col, label, type: nil) ⇒ Object
9 10 11 |
# File 'lib/stimulus_table_filter/view_helper/sort.rb', line 9 def table_filter_sort_th_tag(col, label, type: nil, **) table_filter_build_sort_trigger(:th, col, label, type: type, **) end |
#table_filter_total_count_tag ⇒ Object
16 |
# File 'lib/stimulus_table_filter/view_helper/stats.rb', line 16 def table_filter_total_count_tag(**) = table_filter_stat_span('totalCount', **) |