Class: SolidQueueMonitor::BasePresenter

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::DateHelper, ActionView::Helpers::TextHelper
Defined in:
app/presenters/solid_queue_monitor/base_presenter.rb

Instance Method Summary collapse

Instance Method Details

#calculate_visible_pages(current_page, total_pages) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 76

def calculate_visible_pages(current_page, total_pages)
  if total_pages <= 7
    (1..total_pages).to_a
  else
    case current_page
    when 1..3
      [1, 2, 3, 4, :gap, total_pages]
    when (total_pages - 2)..total_pages
      [1, :gap, total_pages - 3, total_pages - 2, total_pages - 1, total_pages]
    else
      [1, :gap, current_page - 1, current_page, current_page + 1, :gap, total_pages]
    end
  end
end

#default_url_optionsObject



8
9
10
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 8

def default_url_options
  { only_path: true }
end

#format_arguments(arguments) ⇒ Object



96
97
98
99
100
101
102
103
104
105
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 96

def format_arguments(arguments)
  return '-' unless arguments.present?
  
  if arguments.is_a?(Array) && arguments.length == 1 && arguments[0].is_a?(Hash)
    # Handle ActiveJob-style arguments
    format_hash(arguments[0])
  else
    "<code>#{arguments.to_json}</code>"
  end
end

#format_datetime(datetime) ⇒ Object



91
92
93
94
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 91

def format_datetime(datetime)
  return '-' unless datetime
  datetime.strftime('%Y-%m-%d %H:%M:%S')
end

#format_hash(hash) ⇒ Object



107
108
109
110
111
112
113
114
115
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 107

def format_hash(hash)
  return '-' unless hash.present?
  
  formatted = hash.map do |key, value|
    "<strong>#{key}:</strong> #{value.to_s.truncate(50)}"
  end.join(', ')
  
  "<code>#{formatted}</code>"
end

#generate_pagination(current_page, total_pages) ⇒ Object



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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 22

def generate_pagination(current_page, total_pages)
  return '' if total_pages <= 1
  
  links = []
  
  # Previous page link
  if current_page > 1
    links << "<a href='?page=#{current_page - 1}#{query_params}' class='pagination-link'>&laquo; Previous</a>"
  else
    links << "<span class='pagination-link disabled'>&laquo; Previous</span>"
  end
  
  # Page number links
  if total_pages <= 7
    # Show all pages if there are 7 or fewer
    (1..total_pages).each do |page|
      links << page_link(page, current_page)
    end
  else
    # Show first page, last page, and pages around current
    links << page_link(1, current_page)
    
    if current_page > 3
      links << "<span class='pagination-gap'>...</span>"
    end
    
    start_page = [current_page - 1, 2].max
    end_page = [current_page + 1, total_pages - 1].min
    
    (start_page..end_page).each do |page|
      links << page_link(page, current_page)
    end
    
    if current_page < total_pages - 2
      links << "<span class='pagination-gap'>...</span>"
    end
    
    links << page_link(total_pages, current_page)
  end
  
  # Next page link
  if current_page < total_pages
    links << "<a href='?page=#{current_page + 1}#{query_params}' class='pagination-link'>Next &raquo;</a>"
  else
    links << "<span class='pagination-link disabled'>Next &raquo;</span>"
  end
  
  <<-HTML
    <div class="pagination">
      #{links.join}
    </div>
  HTML
end

#section_wrapper(title, content) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 12

def section_wrapper(title, content)
  <<-HTML
    <div class="section-wrapper">
      <div class="section">
        #{content}
      </div>
    </div>
  HTML
end