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, 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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 54 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
110 111 112 113 114 115 116 117 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 110 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
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 74 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
69 70 71 72 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 69 def format_datetime(datetime) return '-' unless datetime datetime.strftime('%Y-%m-%d %H:%M:%S') end |
#format_hash(hash) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 88 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 |
# 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 (1..total_pages).each do |page| if 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
99 100 101 102 103 104 105 106 107 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 99 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 |