jobs: add ability to order jobs in /jobs listing.
This commit is contained in:
@@ -42,7 +42,20 @@ class BackgroundJob < GoodJob::ActiveJobJob
|
||||
q = q.status_matches(params[:status])
|
||||
end
|
||||
|
||||
q.apply_default_order(params)
|
||||
case params[:order]
|
||||
when "created_at"
|
||||
q = q.order(created_at: :desc)
|
||||
when "updated_at"
|
||||
q = q.order(updated_at: :desc)
|
||||
when "scheduled_at"
|
||||
q = q.order(scheduled_at: :desc)
|
||||
when "performed_at"
|
||||
q = q.order(performed_at: :desc)
|
||||
when "finished_at"
|
||||
q = q.order(finished_at: :desc)
|
||||
else
|
||||
q = q.apply_default_order(params)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<%= search_form_for(jobs_path) do |f| %>
|
||||
<%= f.input :name, collection: ApplicationJob.job_classes.map { |klass| klass.name.titleize.delete_suffix(" Job") }, include_blank: true, selected: params[:search][:name] %>
|
||||
<%= f.input :status, collection: %w[Running Queued Finished Discarded], include_blank: true, selected: params[:search][:status] %>
|
||||
<%= f.input :order, collection: [%w[Created created_at], %w[Updated updated_at], %w[Scheduled scheduled_at], %w[Performed performed_at], %w[Finished finished_at]], include_blank: true, selected: params[:search][:order] %>
|
||||
<%= f.submit "Search" %>
|
||||
<% end %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user