lib/trk_datatables/base.rb in trk_datatables-0.2.7 vs lib/trk_datatables/base.rb in trk_datatables-0.2.8
- old
+ new
@@ -5,11 +5,11 @@
# maximum page length = 100 (we should not believe params)
class Error < StandardError
end
- class Base
+ class Base # rubocop:todo Metrics/ClassLength
extend TrkDatatables::BaseHelpers
attr_accessor :column_key_options
# In tests you can use `spy(:view, default_proc: false)` when you want to initialize without
@@ -95,12 +95,10 @@
def order_and_paginate_items(_filtered_items)
raise 'order_and_paginate_items_is_defined_in_specific_orm'
end
- # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
-
# Returns dt_orders or default as array of index and direction
# https://datatables.net/reference/option/order
# @return
# [
# [0, :desc],
@@ -112,16 +110,15 @@
@dt_orders_or_default = []
elsif @dt_params.dt_orders.present?
@dt_orders_or_default = @dt_params.dt_orders
@preferences.set :order, @dt_params.dt_orders
else
- check_value = ->(r) { r.is_a?(Array) && r[0].is_a?(Array) && r[0][0].is_a?(Integer) }
+ check_value = ->(r) { r.is_a?(Array) && r[0].is_a?(Array) && r[0][0].is_a?(Integer) && r[0][0] < @column_key_options.size }
@dt_orders_or_default = @preferences.get(:order, check_value) || default_order
end
@dt_orders_or_default
end
- # rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
def default_order
[[0, :desc]].freeze
end
@@ -224,25 +221,26 @@
date: predefined_date_ranges,
datetime: predefined_datetime_ranges,
}
end
- def predefined_date_ranges
+ def predefined_date_ranges # rubocop:todo Metrics/AbcSize
{
'Today': Time.zone.today..Time.zone.today,
'Yesterday': [Time.zone.today - 1.day, Time.zone.today - 1.day],
'This Month': Time.zone.today.beginning_of_month...Time.zone.today,
'Last Month': Time.zone.today.prev_month.beginning_of_month...Time.zone.today.prev_month.end_of_month,
'This Year': Time.zone.today.beginning_of_year...Time.zone.today,
}
end
- def predefined_datetime_ranges
+ def predefined_datetime_ranges # rubocop:todo Metrics/AbcSize
{
'Today': Time.zone.now.beginning_of_day..Time.zone.now.end_of_day,
'Yesterday': [Time.zone.now.beginning_of_day - 1.day, Time.zone.now.end_of_day - 1.day],
'This Month': Time.zone.today.beginning_of_month.beginning_of_day...Time.zone.now.end_of_day,
- 'Last Month': Time.zone.today.prev_month.beginning_of_month.beginning_of_day...Time.zone.today.prev_month.end_of_month.end_of_day,
+ 'Last Month':
+ Time.zone.today.prev_month.beginning_of_month.beginning_of_day...Time.zone.today.prev_month.end_of_month.end_of_day,
'This Year': Time.zone.today.beginning_of_year.beginning_of_day...Time.zone.today.end_of_day,
}.transform_values do |range|
# datepicker expects format 2020-11-29 11:59:59
range.first.strftime('%F %T')..range.last.strftime('%F %T')
end