2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-07 04:08:18 -05:00
|
|
|
module CycleAnalyticsParams
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2019-10-07 17:07:54 -04:00
|
|
|
def cycle_analytics_project_params
|
|
|
|
return {} unless params[:cycle_analytics].present?
|
|
|
|
|
|
|
|
params[:cycle_analytics].permit(:start_date, :created_after, :created_before, :branch_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def cycle_analytics_group_params
|
2020-02-05 13:09:06 -05:00
|
|
|
return {} unless params.present?
|
2019-10-07 17:07:54 -04:00
|
|
|
|
2020-02-05 13:09:06 -05:00
|
|
|
params.permit(:group_id, :start_date, :created_after, :created_before, project_ids: [])
|
2019-10-07 17:07:54 -04:00
|
|
|
end
|
|
|
|
|
2016-11-23 05:28:28 -05:00
|
|
|
def options(params)
|
2019-10-07 17:07:54 -04:00
|
|
|
@options ||= { from: start_date(params), current_user: current_user }.merge(date_range(params))
|
2016-11-22 08:29:25 -05:00
|
|
|
end
|
|
|
|
|
2016-11-07 04:08:18 -05:00
|
|
|
def start_date(params)
|
2017-08-10 02:42:28 -04:00
|
|
|
case params[:start_date]
|
|
|
|
when '7'
|
|
|
|
7.days.ago
|
|
|
|
when '30'
|
|
|
|
30.days.ago
|
|
|
|
else
|
|
|
|
90.days.ago
|
|
|
|
end
|
2016-11-07 04:08:18 -05:00
|
|
|
end
|
2019-10-07 17:07:54 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def to_utc_time(field)
|
2020-03-02 16:08:01 -05:00
|
|
|
date = field.is_a?(Date) || field.is_a?(Time) ? field : Date.parse(field)
|
2019-11-22 13:06:00 -05:00
|
|
|
date.to_time.utc
|
2019-10-07 17:07:54 -04:00
|
|
|
end
|
2016-11-07 04:08:18 -05:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
CycleAnalyticsParams.prepend_if_ee('EE::CycleAnalyticsParams')
|