Module: Acta::Web::ApplicationHelper
- Defined in:
- app/helpers/acta/web/application_helper.rb
Constant Summary collapse
- ACTA_MASK =
Replace any AR::Encryption-recognized ciphertext leaf in ‘obj` with “********”. Walks hashes and arrays; non-encrypted scalars pass through unchanged. Used by the admin UI so encrypted payload values aren’t displayed as raw ciphertext envelopes.
"********"
Instance Method Summary collapse
- #acta_chip_hue(event_type) ⇒ Object
- #acta_dot_color(event_type) ⇒ Object
- #acta_encrypted_value?(value) ⇒ Boolean
-
#acta_filter_url(overrides = {}) ⇒ Object
Build a URL for the events index, merging
overridesinto current params. - #acta_fmt_abs(time) ⇒ Object
- #acta_fmt_time(time) ⇒ Object
- #acta_mask_encrypted(obj) ⇒ Object
- #acta_pretty_json(obj) ⇒ Object
- #acta_preview_payload(payload) ⇒ Object
Instance Method Details
#acta_chip_hue(event_type) ⇒ Object
9 10 11 12 |
# File 'app/helpers/acta/web/application_helper.rb', line 9 def acta_chip_hue(event_type) h = event_type.to_s.chars.reduce(0) { |acc, c| ((acc * 31 + c.ord) & 0xFFFFFFFF) } h.abs % 360 end |
#acta_dot_color(event_type) ⇒ Object
14 15 16 |
# File 'app/helpers/acta/web/application_helper.rb', line 14 def acta_dot_color(event_type) "oklch(0.70 0.14 #{acta_chip_hue(event_type)})" end |
#acta_encrypted_value?(value) ⇒ Boolean
61 62 63 64 65 66 67 |
# File 'app/helpers/acta/web/application_helper.rb', line 61 def acta_encrypted_value?(value) return false unless defined?(ActiveRecord::Encryption) ActiveRecord::Encryption.encryptor.encrypted?(value) rescue StandardError false end |
#acta_filter_url(overrides = {}) ⇒ Object
Build a URL for the events index, merging overrides into current params. Pass nil for a key to remove it. Resets page when filters change.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/helpers/acta/web/application_helper.rb', line 71 def acta_filter_url(overrides = {}) current = { event_type: params[:event_type], stream_type: params[:stream_type], actor_id: params[:actor_id], stream_key: params[:stream_key], q: params[:q], selected: params[:selected], page: params[:page] }.compact_blank overrides = overrides.transform_keys(&:to_sym) filter_keys = %i[event_type stream_type actor_id stream_key q] current.delete(:page) if (overrides.keys & filter_keys).any? current.delete(:selected) if (overrides.keys & filter_keys).any? merged = current.merge(overrides) merged.compact_blank! merged.delete(:page) if merged[:page].to_s == "0" encode_params(merged) end |
#acta_fmt_abs(time) ⇒ Object
25 26 27 28 29 30 |
# File 'app/helpers/acta/web/application_helper.rb', line 25 def acta_fmt_abs(time) return "-" unless time t = time.respond_to?(:utc) ? time.utc : Time.parse(time.to_s).utc ms = t.strftime("%3N") t.strftime("%Y-%m-%d %H:%M:%S") + ".#{ms}Z" end |
#acta_fmt_time(time) ⇒ Object
18 19 20 21 22 23 |
# File 'app/helpers/acta/web/application_helper.rb', line 18 def acta_fmt_time(time) return "-" unless time t = time.respond_to?(:utc) ? time.utc : Time.parse(time.to_s).utc ms = t.strftime("%3N") t.strftime("%H:%M:%S") + ".#{ms}" end |
#acta_mask_encrypted(obj) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'app/helpers/acta/web/application_helper.rb', line 52 def acta_mask_encrypted(obj) case obj when Hash then obj.each_with_object({}) { |(k, v), acc| acc[k] = acta_mask_encrypted(v) } when Array then obj.map { |v| acta_mask_encrypted(v) } when String then acta_encrypted_value?(obj) ? ACTA_MASK : obj else obj end end |
#acta_pretty_json(obj) ⇒ Object
40 41 42 43 44 |
# File 'app/helpers/acta/web/application_helper.rb', line 40 def acta_pretty_json(obj) JSON.pretty_generate(acta_mask_encrypted(obj)) rescue StandardError obj.to_s end |
#acta_preview_payload(payload) ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/helpers/acta/web/application_helper.rb', line 32 def acta_preview_payload(payload) return "{}" unless payload.is_a?(Hash) && payload.any? masked = acta_mask_encrypted(payload) masked.keys.first(3).map { |k| "#{k}=#{masked[k].inspect}" }.join(" ") rescue StandardError "{}" end |