Class: SolidQueueTui::Views::JobDetailView

Inherits:
Object
  • Object
show all
Includes:
FormattingHelpers, Confirmable
Defined in:
lib/solid_queue_tui/views/job_detail_view.rb

Instance Method Summary collapse

Methods included from FormattingHelpers

#format_duration, #format_number, #humanize_duration, #time_ago, #time_until, #truncate

Methods included from Confirmable

#confirm_bindings, #confirm_mode?, #handle_confirm_input, #init_confirm, #render_confirm_popup

Constructor Details

#initialize(tui) ⇒ JobDetailView

Returns a new instance of JobDetailView.



9
10
11
12
13
14
15
16
17
# File 'lib/solid_queue_tui/views/job_detail_view.rb', line 9

def initialize(tui)
  @tui = tui
  @job = nil
  @failed_job = nil
  @process = nil
  @running_jobs = []
  @scroll_offset = 0
  init_confirm
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


37
# File 'lib/solid_queue_tui/views/job_detail_view.rb', line 37

def active? = @active

#bindingsObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/solid_queue_tui/views/job_detail_view.rb', line 66

def bindings
  if confirm_mode?
    confirm_bindings
  else
    bindings = [
      { key: "Esc", action: "Close" },
      { key: "j/k", action: "Scroll" }
    ]
    if @failed_job
      bindings += [
        { key: "R", action: "Retry" },
        { key: "D", action: "Discard" }
      ]
    end
    bindings
  end
end


88
89
90
91
92
93
94
95
96
97
98
# File 'lib/solid_queue_tui/views/job_detail_view.rb', line 88

def breadcrumb
  if @failed_job
    "failed:#{@failed_job.job_id}"
  elsif @process
    "process:#{@process.id}"
  elsif @job
    "jobs:#{@job.id}"
  else
    "detail"
  end
end

#capturing_input?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/solid_queue_tui/views/job_detail_view.rb', line 84

def capturing_input?
  confirm_mode?
end

#handle_input(event) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/solid_queue_tui/views/job_detail_view.rb', line 58

def handle_input(event)
  if confirm_mode?
    handle_confirm_input(event)
  else
    handle_normal_input(event)
  end
end

#hideObject



28
29
30
31
32
33
34
35
# File 'lib/solid_queue_tui/views/job_detail_view.rb', line 28

def hide
  @active = false
  @job = nil
  @failed_job = nil
  @process = nil
  @running_jobs = []
  @confirm_action = nil
end

#render(frame, area) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/solid_queue_tui/views/job_detail_view.rb', line 39

def render(frame, area)
  return unless @active

  # Render an overlay with padding
  inner = shrink_area(area, 4, 2)

  frame.render_widget(@tui.paragraph(text: ""), inner) # clear background

  if @failed_job
    render_failed_detail(frame, inner)
  elsif @process
    render_process_detail(frame, inner)
  elsif @job
    render_job_detail(frame, inner)
  end

  render_confirm_popup(frame, area) if confirm_mode?
end

#show(job: nil, failed_job: nil, process: nil, running_jobs: []) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/solid_queue_tui/views/job_detail_view.rb', line 19

def show(job: nil, failed_job: nil, process: nil, running_jobs: [])
  @job = job
  @failed_job = failed_job
  @process = process
  @running_jobs = running_jobs
  @scroll_offset = 0
  @active = true
end