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
- #format_arguments(arguments) ⇒ Object
- #format_datetime(datetime) ⇒ Object
- #format_hash(hash) ⇒ Object
- #generate_pagination(current_page, total_pages) ⇒ Object
- #request_path ⇒ Object
- #section_wrapper(_title, content) ⇒ Object
Instance Method Details
#calculate_visible_pages(current_page, total_pages) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 60 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
10 11 12 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 10 def { only_path: true } end |
#engine_mount_point ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 122 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
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 81 def format_arguments(arguments) return '-' if arguments.blank? # Extract and format the arguments more cleanly formatted_args = if arguments.is_a?(Hash) && arguments['arguments'].present? format_job_arguments(arguments) elsif arguments.is_a?(Array) && arguments.length == 1 && arguments[0].is_a?(Hash) && arguments[0]['arguments'].present? format_job_arguments(arguments[0]) else arguments.inspect end if formatted_args.length <= 50 "<code class='args-single-line'>#{formatted_args}</code>" else " <div class=\"args-container\">\n <code class=\"args-content\">\#{formatted_args}</code>\n </div>\n HTML\n end\nend\n" |
#format_datetime(datetime) ⇒ Object
75 76 77 78 79 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 75 def format_datetime(datetime) return '-' unless datetime datetime.strftime('%Y-%m-%d %H:%M:%S') end |
#format_hash(hash) ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 104 def format_hash(hash) return '-' if hash.blank? 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
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 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 24 def generate_pagination(current_page, total_pages) return '' if total_pages <= 1 html = '<div class="pagination">' # Previous page link html += if current_page > 1 "<a href=\"?page=#{current_page - 1}#{query_params}\" class=\"pagination-link pagination-nav\">Previous</a>" else '<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| html += if page == :gap '<span class="pagination-gap">...</span>' elsif page == current_page "<span class=\"pagination-current\">#{page}</span>" else "<a href=\"?page=#{page}#{query_params}\" class=\"pagination-link\">#{page}</a>" end end # Next page link html += if current_page < total_pages "<a href=\"?page=#{current_page + 1}#{query_params}\" class=\"pagination-link pagination-nav\">Next</a>" else '<span class="pagination-link pagination-nav disabled">Next</span>' end html += '</div>' html end |
#request_path ⇒ Object
114 115 116 117 118 119 120 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 114 def request_path if defined?(controller) && controller.respond_to?(:request) controller.request.path else '/solid_queue' end end |
#section_wrapper(_title, content) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'app/presenters/solid_queue_monitor/base_presenter.rb', line 14 def section_wrapper(_title, content) " <div class=\"section-wrapper\">\n <div class=\"section\">\n \#{content}\n </div>\n </div>\n HTML\nend\n" |