Module: SolidQueueWeb::ApplicationHelper

Defined in:
app/helpers/solid_queue_web/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#format_duration(seconds) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/solid_queue_web/application_helper.rb', line 30

def format_duration(seconds)
  s = seconds.to_i
  return "< 1s" if s < 1

  if s < 60
    "#{s}s"
  elsif s < 3600
    "#{s / 60}m #{s % 60}s"
  else
    "#{s / 3600}h #{(s % 3600) / 60}m"
  end
end

#format_timestamp(time, format: "%Y-%m-%d %H:%M:%S") ⇒ Object



22
23
24
25
26
27
28
# File 'app/helpers/solid_queue_web/application_helper.rb', line 22

def format_timestamp(time, format: "%Y-%m-%d %H:%M:%S")
  return "" unless time

  tz = SolidQueueWeb.time_zone
  displayed = tz ? time.in_time_zone(tz) : time.utc
  displayed.strftime(format)
end

#inline_stylesObject



16
17
18
19
20
# File 'app/helpers/solid_queue_web/application_helper.rb', line 16

def inline_styles
  dir = SolidQueueWeb::Engine.root.join("app/assets/stylesheets/solid_queue_web")
  css = dir.glob("_*.css").sort.map(&:read).join("\n")
  (:style, css.html_safe)
end

#sort_header_th(label, col, url_proc, current_sort:, current_dir:) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/solid_queue_web/application_helper.rb', line 3

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 ? (:span, current_dir == "desc" ? "" : "", class: "sqd-sort-indicator") : nil
  tag_opts  = { scope: "col" }
  tag_opts[:"aria-sort"] = current_dir == "asc" ? "ascending" : "descending" if is_active
  (:th, **tag_opts) do
    link_to(url_proc.call(sort: col, direction: next_dir)) do
      safe_join([label, indicator].compact)
    end
  end
end