Module: Pbx::Views::QueueTable

Defined in:
lib/pbx/views/queue_table.rb

Constant Summary collapse

COLUMNS =
[
  {title: "Queue", width: 16},
  {title: "Strategy", width: 12},
  {title: "Waiting", width: 9},
  {title: "Agents", width: 8},
  {title: "Completed", width: 11},
  {title: "Abandoned", width: 11},
  {title: "Hold", width: 10}
].freeze
HEADER_STYLE =
Lipgloss::Style.new.bold(true).foreground("#34d399")
SELECTED_STYLE =
Lipgloss::Style.new.bold(true).foreground("#ffffff").background("#059669")
TITLE_STYLE =
Lipgloss::Style.new.bold(true).foreground("#34d399").padding(0, 1)
SEP_STYLE =
Lipgloss::Style.new.foreground("#4b5563")
EMPTY_STYLE =
Lipgloss::Style.new.foreground("#6b7280").italic(true).padding(2, 4)

Class Method Summary collapse

Class Method Details

.build(queues, table_height) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pbx/views/queue_table.rb', line 34

def self.build(queues, table_height)
  rows = queues.values.sort_by(&:name).map { |q|
    avail = q.members.values.count(&:available?)
    total = q.members.size
    [
      q.name,
      q.strategy,
      q.calls_waiting.to_s,
      "#{avail}/#{total}",
      q.completed.to_s,
      q.abandoned.to_s,
      format_holdtime(q.last_holdtime || q.holdtime)
    ]
  }

  Bubbles::Table.new(columns: COLUMNS, rows: rows, height: table_height).tap do |t|
    t.header_style = HEADER_STYLE
    t.selected_style = SELECTED_STYLE
  end
end

.format_holdtime(secs) ⇒ Object



55
56
57
58
59
# File 'lib/pbx/views/queue_table.rb', line 55

def self.format_holdtime(secs)
  return "" if secs.nil? || secs == 0

  "#{secs / 60}m #{(secs % 60).to_s.rjust(2, "0")}s"
end

.render(queues, width, table_height = 1, table: nil) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/pbx/views/queue_table.rb', line 25

def self.render(queues, width, table_height = 1, table: nil)
  return EMPTY_STYLE.render("No queues discovered yet…") if queues.empty?

  sep = SEP_STYLE.render("" * [width, 1].max)
  title = TITLE_STYLE.render("Queues (#{queues.size})")
  t = table || build(queues, table_height)
  Lipgloss.join_vertical(:left, sep, title, t.view)
end