Module: CycleAnalyticsParams

Extended by:
ActiveSupport::Concern
Included in:
Projects::CycleAnalytics::EventsController, Projects::CycleAnalyticsController
Defined in:
app/controllers/concerns/cycle_analytics_params.rb

Instance Method Summary collapse

Instance Method Details

#cycle_analytics_group_paramsObject


12
13
14
15
16
# File 'app/controllers/concerns/cycle_analytics_params.rb', line 12

def cycle_analytics_group_params
  return {} unless params.present?

  params.permit(:group_id, :start_date, :created_after, :created_before, project_ids: [])
end

#cycle_analytics_project_paramsObject


6
7
8
9
10
# File 'app/controllers/concerns/cycle_analytics_params.rb', line 6

def cycle_analytics_project_params
  return {} unless params[:cycle_analytics].present?

  params[:cycle_analytics].permit(:start_date, :created_after, :created_before, :branch_name)
end

#date_range(params) ⇒ Object


33
34
35
36
37
38
# File 'app/controllers/concerns/cycle_analytics_params.rb', line 33

def date_range(params)
  {}.tap do |date_range_params|
    date_range_params[:from] = to_utc_time(params[:created_after]).beginning_of_day if params[:created_after]
    date_range_params[:to] = to_utc_time(params[:created_before]).end_of_day if params[:created_before]
  end.compact
end

#options(params) ⇒ Object


18
19
20
# File 'app/controllers/concerns/cycle_analytics_params.rb', line 18

def options(params)
  @options ||= { from: start_date(params), current_user: current_user }.merge(date_range(params))
end

#start_date(params) ⇒ Object


22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/concerns/cycle_analytics_params.rb', line 22

def start_date(params)
  case params[:start_date]
  when '7'
    7.days.ago
  when '30'
    30.days.ago
  else
    90.days.ago
  end
end

#to_utc_time(field) ⇒ Object


40
41
42
43
# File 'app/controllers/concerns/cycle_analytics_params.rb', line 40

def to_utc_time(field)
  date = field.is_a?(Date) || field.is_a?(Time) ? field : Date.parse(field)
  date.to_time.utc
end