Module: SolidStackWeb::ApplicationHelper
- Defined in:
- app/helpers/solid_stack_web/application_helper.rb
Instance Method Summary collapse
- #cache_bytes_timeline_svg(timeline) ⇒ Object
- #cache_entries_timeline_svg(timeline) ⇒ Object
- #format_cache_value(raw) ⇒ Object
- #format_duration(seconds) ⇒ Object
- #inline_styles ⇒ Object
- #queue_depth_sparkline_svg(sparkline) ⇒ Object
- #throughput_sparkline_svg(sparkline) ⇒ Object
Instance Method Details
#cache_bytes_timeline_svg(timeline) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 33 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
21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 21 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 |
#format_cache_value(raw) ⇒ Object
3 4 5 6 7 8 9 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 3 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
11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 11 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
99 100 101 102 103 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 99 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 |
#queue_depth_sparkline_svg(sparkline) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 56 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
45 46 47 48 49 50 51 52 53 54 |
# File 'app/helpers/solid_stack_web/application_helper.rb', line 45 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 |