Class: SolidQueueTui::Views::InProgressView
- Inherits:
-
Object
- Object
- SolidQueueTui::Views::InProgressView
- Defined in:
- lib/solid_queue_tui/views/in_progress_view.rb
Instance Method Summary collapse
- #bindings ⇒ Object
- #breadcrumb ⇒ Object
- #handle_input(event) ⇒ Object
-
#initialize(tui) ⇒ InProgressView
constructor
A new instance of InProgressView.
- #render(frame, area) ⇒ Object
- #selected_item ⇒ Object
- #update(jobs:) ⇒ Object
Constructor Details
#initialize(tui) ⇒ InProgressView
Returns a new instance of InProgressView.
6 7 8 9 10 11 12 |
# File 'lib/solid_queue_tui/views/in_progress_view.rb', line 6 def initialize(tui) @tui = tui @table_state = RatatuiRuby::TableState.new(nil) @table_state.select(0) @selected_row = 0 @jobs = [] end |
Instance Method Details
#bindings ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/solid_queue_tui/views/in_progress_view.rb', line 73 def bindings [ { key: "j/k", action: "Navigate" }, { key: "Enter", action: "Detail" }, { key: "G/g", action: "Bottom/Top" } ] end |
#breadcrumb ⇒ Object
81 |
# File 'lib/solid_queue_tui/views/in_progress_view.rb', line 81 def = "in-progress" |
#handle_input(event) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/solid_queue_tui/views/in_progress_view.rb', line 53 def handle_input(event) case event in { type: :key, code: "j" } | { type: :key, code: "up" } move_selection(-1) in { type: :key, code: "k" } | { type: :key, code: "down" } move_selection(1) in { type: :key, code: "g" } jump_to_top in { type: :key, code: "G" } jump_to_bottom else nil end end |
#render(frame, area) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/solid_queue_tui/views/in_progress_view.rb', line 20 def render(frame, area) columns = [ { key: :id, label: "ID", width: 8 }, { key: :queue_name, label: "QUEUE", width: 14 }, { key: :class_name, label: "CLASS", width: :fill }, { key: :priority, label: "PRI", width: 5 }, { key: :worker_id, label: "WORKER", width: 8 }, { key: :started_at, label: "STARTED", width: 12 } ] rows = @jobs.map do |job| { id: job.id, queue_name: job.queue_name, class_name: job.class_name, priority: job.priority, worker_id: job.worker_id || "n/a", started_at: time_ago(job.started_at) } end table = Components::JobTable.new( @tui, title: "In Progress", columns: columns, rows: rows, selected_row: @selected_row, empty_message: "No jobs currently in progress" ) table.render(frame, area, @table_state) end |
#selected_item ⇒ Object
68 69 70 71 |
# File 'lib/solid_queue_tui/views/in_progress_view.rb', line 68 def selected_item return nil if @jobs.empty? || @selected_row >= @jobs.size @jobs[@selected_row] end |
#update(jobs:) ⇒ Object
14 15 16 17 18 |
# File 'lib/solid_queue_tui/views/in_progress_view.rb', line 14 def update(jobs:) @jobs = jobs @selected_row = @selected_row.clamp(0, [@jobs.size - 1, 0].max) @table_state.select(@selected_row) end |