Module: SolidStackWeb::ApplicationHelper
- Defined in:
- app/helpers/solid_stack_web/application_helper.rb
Instance Method Summary collapse
- #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
- #throughput_sparkline_svg(sparkline) ⇒ Object
Instance Method Details
#cable_messages_timeline_svg(timeline) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 58 def (timeline) build_sparkline_svg( Struct.new(:buckets, :max).new(timeline., timeline.), css_class: "sqw-sparkline sqw-sparkline--lg", aria_label: "Cable messages over the last 24 hours" ) do |count, i| hours_ago = CableTimeline::HOURS - 1 - i label = count == 1 ? "message" : "messages" hours_ago.zero? ? "#{count} #{label} this hour" : "#{count} #{label} #{hours_ago}h ago" end end |
#cache_bytes_timeline_svg(timeline) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 46 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: "Cache bytes written over the last 24 hours" ) do |bytes, i| hours_ago = CacheTimeline::HOURS - 1 - i size = number_to_human_size(bytes) hours_ago.zero? ? "#{size} written this hour" : "#{size} written #{hours_ago}h ago" end end |
#cache_entries_timeline_svg(timeline) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# 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: "Cache entries written over the last 24 hours" ) do |count, i| hours_ago = CacheTimeline::HOURS - 1 - i hours_ago.zero? ? "#{count} #{"entry".then { |w| count == 1 ? w : "entries" }} this hour" \ : "#{count} #{"entry".then { |w| count == 1 ? w : "entries" }} #{hours_ago}h ago" end end |
#failed_job_sparkline_svg(sparkline) ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 90 def failed_job_sparkline_svg(sparkline) build_sparkline_svg(sparkline, aria_label: "Failed jobs over the last 12 hours") do |count, i| hours_ago = SolidStackWeb::FailedJobSparkline::HOURS - i if hours_ago == 1 "#{count} #{count == 1 ? "failure" : "failures"} in the last hour" else "#{count} #{count == 1 ? "failure" : "failures"} (#{hours_ago}h–#{hours_ago - 1}h ago)" 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
135 136 137 138 139 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 135 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
81 82 83 84 85 86 87 88 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 81 def queue_depth_sparkline_svg(sparkline) build_sparkline_svg(sparkline, css_class: "sqw-sparkline sqw-sparkline--sm", aria_label: "Queue depth over the last 12 hours") do |count, i| hours_ago = SolidStackWeb::QueueDepthSparkline::HOURS - 1 - i jobs_word = count == 1 ? "job" : "jobs" hours_ago.zero? ? "#{count} ready #{jobs_word} now" : "#{count} ready #{jobs_word} #{hours_ago}h ago" end end |
#throughput_sparkline_svg(sparkline) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 70 def throughput_sparkline_svg(sparkline) build_sparkline_svg(sparkline, aria_label: "Throughput over the last 12 hours") do |count, i| hours_ago = SolidStackWeb::ThroughputSparkline::HOURS - i if hours_ago == 1 "#{count} #{count == 1 ? "job" : "jobs"} in the last hour" else "#{count} #{count == 1 ? "job" : "jobs"} (#{hours_ago}h–#{hours_ago - 1}h ago)" end end end |