Class: SolidQueueMonitor::BasePresenter
- Inherits:
-
Object
- Object
- SolidQueueMonitor::BasePresenter
- Includes:
- ActionView::Helpers::DateHelper, ActionView::Helpers::TextHelper
- Defined in:
- app/presenters/solid_queue_monitor/base_presenter.rb
Direct Known Subclasses
FailedJobsPresenter, InProgressJobsPresenter, JobsPresenter, QueuesPresenter, ReadyJobsPresenter, RecurringJobsPresenter, ScheduledJobsPresenter, StatsPresenter
Instance Method Summary collapse
- #calculate_visible_pages(current_page, total_pages) ⇒ Object
- #default_url_options ⇒ Object
-
#engine_mount_point ⇒ Object
Helper method to get the mount point of the engine.
- #format_arguments(arguments) ⇒ Object
- #format_datetime(datetime) ⇒ Object
- #format_hash(hash) ⇒ Object
- #generate_pagination(current_page, total_pages) ⇒ Object
-
#request_path ⇒ Object
Helper method to get the current request path.
- #section_wrapper(title, content) ⇒ Object
Instance Method Details
#calculate_visible_pages(current_page, total_pages) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 58 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_options ⇒ Object
8 9 10 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 8 def { only_path: true } end |
#engine_mount_point ⇒ Object
Helper method to get the mount point of the engine
114 115 116 117 118 119 120 121 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 114 def engine_mount_point path_parts = request_path.split('/') if path_parts.length >= 3 "/#{path_parts[1]}/#{path_parts[2]}" else "/solid_queue" end end |
#format_arguments(arguments) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 78 def format_arguments(arguments) return '-' unless arguments.present? # For ActiveJob format if arguments.is_a?(Hash) && arguments['arguments'].present? return "<code>#{arguments['arguments'].inspect}</code>" elsif arguments.is_a?(Array) && arguments.length == 1 && arguments[0].is_a?(Hash) && arguments[0]['arguments'].present? return "<code>#{arguments[0]['arguments'].inspect}</code>" end # For regular arguments format "<code>#{arguments.inspect}</code>" end |
#format_datetime(datetime) ⇒ Object
73 74 75 76 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 73 def format_datetime(datetime) return '-' unless datetime datetime.strftime('%Y-%m-%d %H:%M:%S') end |
#format_hash(hash) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 92 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 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 22 def generate_pagination(current_page, total_pages) return '' if total_pages <= 1 html = '<div class="pagination">' # Previous page link if current_page > 1 html += "<a href=\"?page=#{current_page - 1}#{query_params}\" class=\"pagination-link pagination-nav\">Previous</a>" else html += '<span class="pagination-link pagination-nav disabled">Previous</span>' end # Page links visible_pages = calculate_visible_pages(current_page, total_pages) visible_pages.each do |page| if page == :gap html += "<span class=\"pagination-gap\">...</span>" elsif page == current_page html += "<span class=\"pagination-current\">#{page}</span>" else html += "<a href=\"?page=#{page}#{query_params}\" class=\"pagination-link\">#{page}</a>" end end # Next page link if current_page < total_pages html += "<a href=\"?page=#{current_page + 1}#{query_params}\" class=\"pagination-link pagination-nav\">Next</a>" else html += '<span class="pagination-link pagination-nav disabled">Next</span>' end html += '</div>' html end |
#request_path ⇒ Object
Helper method to get the current request path
103 104 105 106 107 108 109 110 111 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 103 def request_path # Try to get the current path from the controller's request if defined?(controller) && controller.respond_to?(:request) controller.request.path else # Fallback to a default path if we can't get the current path "/solid_queue" end 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 |