Class: Hyrax::Admin::Analytics::AnalyticsController

Inherits:
ApplicationController
  • Object
show all
Includes:
SingularSubresourceController
Defined in:
app/controllers/hyrax/admin/analytics/analytics_controller.rb

Instance Method Summary collapse

Methods included from SingularSubresourceController

#find_work

Methods included from DenyAccessOverrideBehavior

#deny_access

Instance Method Details

#date_rangeObject


25
26
27
# File 'app/controllers/hyrax/admin/analytics/analytics_controller.rb', line 25

def date_range
  "#{@start_date},#{@end_date}"
end

#paginate(results_array, rows: 10) ⇒ Object


29
30
31
32
33
34
35
36
# File 'app/controllers/hyrax/admin/analytics/analytics_controller.rb', line 29

def paginate(results_array, rows: 10)
  return if results_array.nil?

  total_pages = (results_array.size.to_f / rows.to_f).ceil
  page = request.params[:page].nil? ? 1 : request.params[:page].to_i
  current_page = page > total_pages ? total_pages : page
  Kaminari.paginate_array(results_array, total_count: results_array.size).page(current_page).per(rows)
end

#set_date_rangeObject


20
21
22
23
# File 'app/controllers/hyrax/admin/analytics/analytics_controller.rb', line 20

def set_date_range
  @start_date = params[:start_date] || Hyrax.config.analytics_start_date
  @end_date = params[:end_date] || Time.zone.today + 1.day
end

#set_documentObject


12
13
14
# File 'app/controllers/hyrax/admin/analytics/analytics_controller.rb', line 12

def set_document
  @document = ::SolrDocument.find(params[:id])
end

#set_monthsObject


16
17
18
# File 'app/controllers/hyrax/admin/analytics/analytics_controller.rb', line 16

def set_months
  @month_names = 12.downto(1).map { |n| DateTime::ABBR_MONTHNAMES.drop(1)[(Time.zone.today.month - n) % 12] }.reverse
end