Module: SolidOps::ApplicationHelper
- Defined in:
- app/helpers/solid_ops/application_helper.rb
Instance Method Summary collapse
- #duration_since(time) ⇒ Object
- #event_pill_class(event_type) ⇒ Object
- #format_bytes(bytes) ⇒ Object
- #format_datetime(t) ⇒ Object
- #format_duration(ms) ⇒ Object
- #format_time(t) ⇒ Object
-
#pages_to_show(current, total) ⇒ Object
Pagination page-number list with ellipsis gaps.
- #solid_component_available?(component) ⇒ Boolean
- #status_pill(status) ⇒ Object
- #time_ago_short(time) ⇒ Object
Instance Method Details
#duration_since(time) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/helpers/solid_ops/application_helper.rb', line 85 def duration_since(time) return "—" unless time seconds = (Time.current - time).to_i if seconds < 60 "#{seconds}s" elsif seconds < 3600 "#{seconds / 60}m #{seconds % 60}s" elsif seconds < 86_400 "#{seconds / 3600}h #{(seconds % 3600) / 60}m" else "#{seconds / 86_400}d #{(seconds % 86_400) / 3600}h" end end |
#event_pill_class(event_type) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/solid_ops/application_helper.rb', line 5 def event_pill_class(event_type) base = "inline-flex items-center px-2.5 py-0.5 rounded-full text-[11px] font-semibold ring-1 ring-inset" case event_type.to_s when /^cable\./ then "#{base} bg-purple-50 text-purple-700 ring-purple-600/20" when /^job\./ then "#{base} bg-blue-50 text-blue-700 ring-blue-700/10" when /^cache\./ then "#{base} bg-emerald-50 text-emerald-700 ring-emerald-600/20" else "#{base} bg-gray-50 text-gray-600 ring-gray-500/10" end end |
#format_bytes(bytes) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/helpers/solid_ops/application_helper.rb', line 49 def format_bytes(bytes) return "—" unless bytes if bytes < 1024 "#{bytes} B" elsif bytes < 1024 * 1024 format("%.1f KB", bytes / 1024.0) elsif bytes < 1024 * 1024 * 1024 format("%.1f MB", bytes / (1024.0 * 1024)) else format("%.2f GB", bytes / (1024.0 * 1024 * 1024)) end end |
#format_datetime(t) ⇒ Object
45 46 47 |
# File 'app/helpers/solid_ops/application_helper.rb', line 45 def format_datetime(t) t&.strftime("%Y-%m-%d %H:%M:%S") end |
#format_duration(ms) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/solid_ops/application_helper.rb', line 29 def format_duration(ms) return "—" unless ms if ms < 1 format("%.3fms", ms) elsif ms < 1000 format("%.1fms", ms) else format("%.2fs", ms / 1000.0) end end |
#format_time(t) ⇒ Object
41 42 43 |
# File 'app/helpers/solid_ops/application_helper.rb', line 41 def format_time(t) t&.strftime("%H:%M:%S.%L") end |
#pages_to_show(current, total) ⇒ Object
Pagination page-number list with ellipsis gaps
101 102 103 104 105 106 107 108 109 110 |
# File 'app/helpers/solid_ops/application_helper.rb', line 101 def pages_to_show(current, total) return (1..total).to_a if total <= 7 pages = [1] pages << :gap if current > 3 ((current - 1)..(current + 1)).each { |p| pages << p if p > 1 && p < total } pages << :gap if current < total - 2 pages << total pages.uniq end |
#solid_component_available?(component) ⇒ Boolean
63 64 65 66 67 68 69 70 |
# File 'app/helpers/solid_ops/application_helper.rb', line 63 def solid_component_available?(component) case component when :queue then defined?(SolidQueue) when :cache then defined?(SolidCache) when :cable then defined?(SolidCable) else false end end |
#status_pill(status) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/solid_ops/application_helper.rb', line 15 def status_pill(status) base = "inline-flex items-center px-2.5 py-0.5 rounded-full text-[11px] font-semibold ring-1 ring-inset" colors = { "ready" => "bg-yellow-50 text-yellow-800 ring-yellow-600/20", "claimed" => "bg-blue-50 text-blue-700 ring-blue-700/10", "failed" => "bg-red-50 text-red-700 ring-red-600/10", "blocked" => "bg-orange-50 text-orange-700 ring-orange-600/20", "scheduled" => "bg-indigo-50 text-indigo-700 ring-indigo-700/10", "finished" => "bg-emerald-50 text-emerald-700 ring-emerald-600/20", "paused" => "bg-gray-50 text-gray-600 ring-gray-500/10" } "#{base} #{colors.fetch(status.to_s, "bg-gray-50 text-gray-600 ring-gray-500/10")}" end |
#time_ago_short(time) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/helpers/solid_ops/application_helper.rb', line 72 def time_ago_short(time) return "—" unless time time = Time.zone.parse(time) if time.is_a?(String) seconds = (Time.current - time).to_i case seconds when 0..59 then "#{seconds}s ago" when 60..3599 then "#{seconds / 60}m ago" when 3600..86_399 then "#{seconds / 3600}h ago" else "#{seconds / 86_400}d ago" end end |