Module: RDBr::Web::FilterPresentationHelpers
- Included in:
- Helpers
- Defined in:
- lib/rdbr/web/filter_presentation_helpers.rb
Constant Summary collapse
- TEMPORAL_TYPES =
%i[date time timestamp timestamptz timetz].freeze
Instance Method Summary collapse
- #filter_chip_parts(entry) ⇒ Object
- #filter_description(entry) ⇒ Object
- #filter_related_value(entry) ⇒ Object
- #render_temporal_filter(column, value) ⇒ Object
- #temporal_column?(column) ⇒ Boolean
Instance Method Details
#filter_chip_parts(entry) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rdbr/web/filter_presentation_helpers.rb', line 11 def filter_chip_parts(entry) operator = entry.fetch(:operator).to_s.tr('_', ' ') value = entry.fetch(:value) return [ truthy?(value) ? 'NULL' : 'NOT NULL', entry.fetch(:column) ] if operator == 'is null' = @relation&.column(entry.fetch(:column)) = (entry) column_name = ? display_column_name() : entry.fetch(:column) column = operator == 'eq' ? column_name : "#{column_name} #{operator}" [ display_text( ? .label : value, limit: 80), column ] end |
#filter_description(entry) ⇒ Object
6 7 8 9 |
# File 'lib/rdbr/web/filter_presentation_helpers.rb', line 6 def filter_description(entry) value, column = filter_chip_parts(entry) "#{column}: #{value}" end |
#filter_related_value(entry) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/rdbr/web/filter_presentation_helpers.rb', line 23 def (entry) return unless entry.fetch(:operator).to_s == 'eq' = @relation&.column(entry.fetch(:column)) (, entry.fetch(:value)) if end |
#render_temporal_filter(column, value) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/rdbr/web/filter_presentation_helpers.rb', line 34 def render_temporal_filter(column, value) rendered = render_column_value(column, value, compact: true) name = Rack::Utils.escape_html(column.name) raw_value = Rack::Utils.escape_html(value.to_s) '<button class="temporal-value-filter" type="button" ' \ "data-date-filter-column=\"#{name}\" data-date-filter-value=\"#{raw_value}\" " \ "title=\"Filter #{name} by date range\">#{rendered}</button>" end |
#temporal_column?(column) ⇒ Boolean
30 31 32 |
# File 'lib/rdbr/web/filter_presentation_helpers.rb', line 30 def temporal_column?(column) TEMPORAL_TYPES.include?(column.logical_type.to_s.to_sym) end |