Skip to content

Commit

Permalink
Dashboard fix preservation of limit and queue_name filter params;…
Browse files Browse the repository at this point in the history
… add pager to jobs (#434)
  • Loading branch information
bensheldon authored Oct 25, 2021
1 parent c2bade7 commit c8828e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 6 additions & 2 deletions engine/app/filters/good_job/base_filter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true
module GoodJob
class BaseFilter
DEFAULT_LIMIT = 25

attr_accessor :params

def initialize(params)
Expand All @@ -13,7 +15,7 @@ def records
filtered_query.display_all(
after_scheduled_at: after_scheduled_at,
after_id: params[:after_id]
).limit(params.fetch(:limit, 25))
).limit(params.fetch(:limit, DEFAULT_LIMIT))
end

def last
Expand All @@ -38,8 +40,10 @@ def states

def to_params(override)
{
state: params[:state],
job_class: params[:job_class],
limit: params[:limit],
queue_name: params[:queue_name],
state: params[:state],
}.merge(override).delete_if { |_, v| v.nil? }
end

Expand Down
15 changes: 14 additions & 1 deletion engine/app/views/good_job/jobs/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,17 @@

<%= render 'good_job/shared/filter', filter: @filter %>

<%= render 'good_job/shared/jobs_table', jobs: @filter.records %>
<% if @filter.records.present? %>
<%= render 'good_job/shared/jobs_table', jobs: @filter.records %>
<nav aria-label="Job pagination" class="mt-3">
<ul class="pagination">
<li class="page-item">
<%= link_to(@filter.to_params(after_scheduled_at: (@filter.last.scheduled_at || @filter.last.created_at), after_id: @filter.last.id), class: "page-link") do %>
Older jobs <span aria-hidden="true">&raquo;</span>
<% end %>
</li>
</ul>
</nav>
<% else %>
<em>No jobs present.</em>
<% end %>

0 comments on commit c8828e5

Please sign in to comment.