28 lines
795 B
Ruby
28 lines
795 B
Ruby
class Admin::JobsController < ApplicationController
|
|
include Pagy::Backend
|
|
|
|
before_action :authorize!
|
|
def index
|
|
@q = Job.ransack(params[:q])
|
|
@q.sorts = "id asc" if @q.sorts.empty?
|
|
# @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
|