debian-mirror-gitlab/app/controllers/concerns/cycle_analytics_params.rb

47 lines
1.2 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module CycleAnalyticsParams
extend ActiveSupport::Concern
2019-12-21 20:55:43 +05:30
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-03-13 15:44:24 +05:30
return {} unless params.present?
2019-12-21 20:55:43 +05:30
2020-03-13 15:44:24 +05:30
params.permit(:group_id, :start_date, :created_after, :created_before, project_ids: [])
2019-12-21 20:55:43 +05:30
end
2017-08-17 22:00:37 +05:30
def options(params)
2019-12-21 20:55:43 +05:30
@options ||= { from: start_date(params), current_user: current_user }.merge(date_range(params))
2017-08-17 22:00:37 +05:30
end
def start_date(params)
2018-03-17 18:26:18 +05:30
case params[:start_date]
when '7'
7.days.ago
when '30'
30.days.ago
else
90.days.ago
end
2017-08-17 22:00:37 +05:30
end
2019-12-21 20:55:43 +05:30
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-04-08 14:13:33 +05:30
date = field.is_a?(Date) || field.is_a?(Time) ? field : Date.parse(field)
2020-01-01 13:55:28 +05:30
date.to_time.utc
2019-12-21 20:55:43 +05:30
end
2017-08-17 22:00:37 +05:30
end
2019-12-04 20:38:33 +05:30
CycleAnalyticsParams.prepend_if_ee('EE::CycleAnalyticsParams')