Module: SolidStackWeb::ApplicationHelper
- Defined in:
- app/helpers/solid_stack_web/application_helper.rb
Instance Method Summary collapse
- #audit_action_badge_class(action) ⇒ Object
- #cable_messages_timeline_svg(timeline) ⇒ Object
- #cache_bytes_timeline_svg(timeline) ⇒ Object
- #cache_entries_timeline_svg(timeline) ⇒ Object
- #failed_job_sparkline_svg(sparkline) ⇒ Object
- #format_cache_value(raw) ⇒ Object
- #format_duration(seconds) ⇒ Object
- #inline_styles ⇒ Object
- #local_time(time, format: :short, placeholder: "—") ⇒ Object
- #queue_depth_sparkline_svg(sparkline) ⇒ Object
- #sort_header_th(label, col, url_proc, current_sort:, current_dir:) ⇒ Object
- #throughput_sparkline_svg(sparkline) ⇒ Object
Instance Method Details
#audit_action_badge_class(action) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 103 def audit_action_badge_class(action) case action when /discard/ then "sqw-badge--failed" when /retry/ then "sqw-badge--scheduled" when "queue_paused" then "sqw-badge--blocked" when "queue_resumed" then "sqw-badge--ready" end end |
#cable_messages_timeline_svg(timeline) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 65 def (timeline) build_sparkline_svg( Struct.new(:buckets, :max).new(timeline., timeline.), css_class: "sqw-sparkline sqw-sparkline--lg", aria_label: t("solid_stack_web.cable.messages_timeline") ) do |count, i| hours_ago = CableTimeline::HOURS - 1 - i if hours_ago.zero? t("solid_stack_web.helpers.cable_message_this_hour", count: count) else t("solid_stack_web.helpers.cable_message_hours_ago", count: count, hours: hours_ago) end end end |
#cache_bytes_timeline_svg(timeline) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 49 def cache_bytes_timeline_svg(timeline) build_sparkline_svg( Struct.new(:buckets, :max).new(timeline.byte_buckets, timeline.byte_max), css_class: "sqw-sparkline sqw-sparkline--lg", aria_label: t("solid_stack_web.cache.bytes_written") ) do |bytes, i| hours_ago = CacheTimeline::HOURS - 1 - i size = number_to_human_size(bytes) if hours_ago.zero? t("solid_stack_web.helpers.cache_size_this_hour", size: size) else t("solid_stack_web.helpers.cache_size_hours_ago", size: size, hours: hours_ago) end end end |
#cache_entries_timeline_svg(timeline) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 34 def cache_entries_timeline_svg(timeline) build_sparkline_svg( Struct.new(:buckets, :max).new(timeline.entry_buckets, timeline.entry_max), css_class: "sqw-sparkline sqw-sparkline--lg", aria_label: t("solid_stack_web.helpers.cache_entry_this_hour", count: 0).gsub(/\d+/, "…") ) do |count, i| hours_ago = CacheTimeline::HOURS - 1 - i if hours_ago.zero? t("solid_stack_web.helpers.cache_entry_this_hour", count: count) else t("solid_stack_web.helpers.cache_entry_hours_ago", count: count, hours: hours_ago) end end end |
#failed_job_sparkline_svg(sparkline) ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 125 def failed_job_sparkline_svg(sparkline) build_sparkline_svg(sparkline, aria_label: t("solid_stack_web.dashboard.failures_label")) do |count, i| hours_ago = SolidStackWeb::FailedJobSparkline::HOURS - i if hours_ago == 1 t("solid_stack_web.helpers.failure_last_hour", count: count) else t("solid_stack_web.helpers.failure_hours_ago", count: count, from: hours_ago, to: hours_ago - 1) end end end |
#format_cache_value(raw) ⇒ Object
16 17 18 19 20 21 22 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 16 def format_cache_value(raw) str = raw.to_s.encode("UTF-8", invalid: :replace, undef: :replace, replace: "?") parsed = JSON.parse(str) { label: "JSON", content: JSON.pretty_generate(parsed) } rescue JSON::ParserError, JSON::GeneratorError { label: "Text", content: str } end |
#format_duration(seconds) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 24 def format_duration(seconds) return "—" if seconds.nil? return "#{(seconds * 1000).round}ms" if seconds < 1 s = seconds.to_i return "#{sprintf("%g", seconds.round(1))}s" if s < 60 return "#{s / 60}m #{s % 60}s" if s < 3600 "#{s / 3600}h #{(s % 3600) / 60}m" end |
#inline_styles ⇒ Object
170 171 172 173 174 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 170 def inline_styles dir = SolidStackWeb::Engine.root.join("app/assets/stylesheets/solid_stack_web") css = dir.glob("_*.css").sort.map(&:read).join("\n") content_tag(:style, css.html_safe) end |
#local_time(time, format: :short, placeholder: "—") ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 3 def local_time(time, format: :short, placeholder: "—") return placeholder if time.nil? iso = time.utc.iso8601 fallback = case format when :long then time.utc.strftime("%Y-%m-%d %H:%M:%S UTC") when :relative then "#{time_ago_in_words(time)} ago" else time.utc.strftime("%b %-d %H:%M UTC") end tag.time(fallback, datetime: iso, data: { controller: "timestamp", timestamp_format_value: format }) end |
#queue_depth_sparkline_svg(sparkline) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 91 def queue_depth_sparkline_svg(sparkline) build_sparkline_svg(sparkline, css_class: "sqw-sparkline sqw-sparkline--sm", aria_label: t("solid_stack_web.queues.col_depth")) do |count, i| hours_ago = SolidStackWeb::QueueDepthSparkline::HOURS - 1 - i if hours_ago.zero? t("solid_stack_web.helpers.queue_depth_now", count: count) else t("solid_stack_web.helpers.queue_depth_hours_ago", count: count, hours: hours_ago) end end end |
#sort_header_th(label, col, url_proc, current_sort:, current_dir:) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 112 def sort_header_th(label, col, url_proc, current_sort:, current_dir:) is_active = current_sort == col next_dir = (is_active && current_dir == "desc") ? "asc" : "desc" indicator = is_active ? content_tag(:span, current_dir == "desc" ? "↓" : "↑", class: "sqw-sort-indicator") : nil tag_opts = { scope: "col" } tag_opts[:"aria-sort"] = is_active ? (current_dir == "asc" ? "ascending" : "descending") : nil if is_active content_tag(:th, **tag_opts) do link_to(url_proc.call(sort: col, direction: next_dir)) do safe_join([label, indicator].compact) end end end |
#throughput_sparkline_svg(sparkline) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 80 def throughput_sparkline_svg(sparkline) build_sparkline_svg(sparkline, aria_label: t("solid_stack_web.dashboard.throughput_label")) do |count, i| hours_ago = SolidStackWeb::ThroughputSparkline::HOURS - i if hours_ago == 1 t("solid_stack_web.helpers.throughput_last_hour", count: count) else t("solid_stack_web.helpers.throughput_hours_ago", count: count, from: hours_ago, to: hours_ago - 1) end end end |