Added sort function and pagy calendar to admin/jobs index
This commit is contained in:
@@ -5,6 +5,23 @@ class Admin::JobsController < ApplicationController
|
||||
def index
|
||||
@q = Job.ransack(params[:q])
|
||||
@q.sorts = "id asc" if @q.sorts.empty?
|
||||
@pagy, @records = pagy(@q.result(distinct: true), limit: 20)
|
||||
# @pagy, @records = pagy(@q.result(distinct: true), limit: 20)
|
||||
@calendar, @pagy, @records = pagy_calendar(@q, year: {}, month: {}, pagy: {})
|
||||
end
|
||||
|
||||
def pagy_calendar_period(collection)
|
||||
if collection.is_a? Ransack::Search
|
||||
collection.result.minmax.map(&:created_at) if collection.result
|
||||
else
|
||||
collection.minmax.map(&:created_at) if collection
|
||||
end
|
||||
end
|
||||
|
||||
def pagy_calendar_filter(collection, from, to)
|
||||
if collection.is_a? Ransack::Search
|
||||
collection.result.where(created_at: from...to)
|
||||
else
|
||||
collection.where(created_at: from...to)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user