Module: Athar::Dashboard::DetailHelper
- Included in:
- Athar::DashboardHelper
- Defined in:
- app/helpers/athar/dashboard/detail_helper.rb
Overview
Rendering helpers for the expanded-row detail: JSON-style key-value tables for record_data and metadata, and the row-hash → AR-record upgrade used when a row is opened inline.
Instance Method Summary collapse
-
#deletion_for(row) ⇒ Object
Upgrade a feed-row hash to its AR record so the detail partials can call ‘.actor` (via ActorLookup), associations, etc.
-
#format_kv_value(value) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #render_json_kv(hash) ⇒ Object
- #table_event_for(row) ⇒ Object
Instance Method Details
#deletion_for(row) ⇒ Object
Upgrade a feed-row hash to its AR record so the detail partials can call ‘.actor` (via ActorLookup), associations, etc. At most one row is expanded at a time, so the cost is one extra query per render.
41 42 43 |
# File 'app/helpers/athar/dashboard/detail_helper.rb', line 41 def deletion_for(row) Athar::Deletion.find(row[:id]) end |
#format_kv_value(value) ⇒ Object
rubocop:disable Metrics/MethodLength
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/helpers/athar/dashboard/detail_helper.rb', line 24 def format_kv_value(value) # rubocop:disable Metrics/MethodLength if value.is_a?(String) && value.include?("***") content_tag(:span, ERB::Util.html_escape(value), class: "masked") elsif value.nil? content_tag(:span, "null", class: "muted") elsif [true, false].include?(value) content_tag(:span, value.to_s, class: "bool") elsif value.is_a?(Numeric) content_tag(:span, value.to_s, class: "num") else ERB::Util.html_escape(value.to_s) end end |
#render_json_kv(hash) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/athar/dashboard/detail_helper.rb', line 9 def render_json_kv(hash) if hash.blank? || (hash.is_a?(Hash) && hash.empty?) return content_tag(:div, "{}".html_safe, class: "json-empty") end rows = hash.map do |key, value| content_tag(:tr) do content_tag(:td, ERB::Util.html_escape(key), class: "kv-key") + content_tag(:td, format_kv_value(value), class: "kv-val") end end content_tag(:table, content_tag(:tbody, safe_join(rows)), class: "kv-table") end |
#table_event_for(row) ⇒ Object
45 46 47 |
# File 'app/helpers/athar/dashboard/detail_helper.rb', line 45 def table_event_for(row) Athar::TableEvent.find(row[:id]) end |