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

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?("***")
    (:span, ERB::Util.html_escape(value), class: "masked")
  elsif value.nil?
    (:span, "null", class: "muted")
  elsif [true, false].include?(value)
    (:span, value.to_s, class: "bool")
  elsif value.is_a?(Numeric)
    (: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 (:div, "{}".html_safe, class: "json-empty")
  end

  rows = hash.map do |key, value|
    (:tr) do
      (:td, ERB::Util.html_escape(key), class: "kv-key") +
        (:td, format_kv_value(value), class: "kv-val")
    end
  end

  (:table, (: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