Class: Gitlab::Analytics::CycleAnalytics::RequestParams

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Attributes, ActiveModel::Model, ActiveModel::Validations, Utils::StrongMemoize
Defined in:
lib/gitlab/analytics/cycle_analytics/request_params.rb

Constant Summary collapse

MAX_RANGE_DAYS =
180.days.freeze
DEFAULT_DATE_RANGE =

30 including Date.today

29.days
STRONG_PARAMS_DEFINITION =
[
  :created_before,
  :created_after,
  :author_username,
  :milestone_title,
  :sort,
  :direction,
  :page,
  :stage_id,
  :end_event_filter,
  label_name: [].freeze,
  assignee_username: [].freeze,
  project_ids: [].freeze
].freeze
FINDER_PARAM_NAMES =
[
  :assignee_username,
  :author_username,
  :milestone_title,
  :label_name
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ RequestParams

Returns a new instance of RequestParams.



60
61
62
63
64
65
66
# File 'lib/gitlab/analytics/cycle_analytics/request_params.rb', line 60

def initialize(params = {})
  super(params)

  self.created_before = (self.created_before || Time.current).at_end_of_day
  self.created_after = (created_after || default_created_after).at_beginning_of_day
  self.end_event_filter ||= Gitlab::Analytics::CycleAnalytics::BaseQueryBuilder::DEFAULT_END_EVENT_FILTER
end

Instance Attribute Details

#project_idsObject



106
107
108
# File 'lib/gitlab/analytics/cycle_analytics/request_params.rb', line 106

def project_ids
  Array(@project_ids)
end

Instance Method Details

#to_data_attributesObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/gitlab/analytics/cycle_analytics/request_params.rb', line 82

def to_data_attributes
  {}.tap do |attrs|
    attrs[:value_stream] = value_stream_data_attributes.to_json if value_stream
    attrs[:created_after] = created_after.to_date.iso8601
    attrs[:created_before] = created_before.to_date.iso8601
    attrs[:labels] = label_name.to_json if label_name.present?
    attrs[:assignees] = assignee_username.to_json if assignee_username.present?
    attrs[:author] = author_username if author_username.present?
    attrs[:milestone] = milestone_title if milestone_title.present?
    attrs[:sort] = sort if sort.present?
    attrs[:direction] = direction if direction.present?
    attrs[:stage] = stage_data_attributes.to_json if stage_id.present?
    attrs[:namespace] = namespace_attributes
    attrs[:enable_tasks_by_type_chart] = 'false'
    attrs[:enable_customizable_stages] = 'false'
    attrs[:enable_projects_filter] = 'false'
    attrs[:default_stages] = Gitlab::Analytics::CycleAnalytics::DefaultStages.all.map do |stage_params|
      ::Analytics::CycleAnalytics::StagePresenter.new(stage_params)
    end.to_json

    attrs.merge!(foss_project_level_params, resource_paths)
  end
end

#to_data_collector_paramsObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/gitlab/analytics/cycle_analytics/request_params.rb', line 68

def to_data_collector_params
  {
    current_user: current_user,
    from: created_after,
    to: created_before,
    project_ids: project_ids,
    sort: sort&.to_sym,
    direction: direction&.to_sym,
    page: page,
    end_event_filter: end_event_filter.to_sym,
    use_aggregated_data_collector: use_aggregated_backend?
  }.merge(attributes.symbolize_keys.slice(*FINDER_PARAM_NAMES))
end