2018-07-25 05:30:33 -04:00
|
|
|
# frozen_string_literal: true
|
2018-08-03 15:52:37 -04:00
|
|
|
# Group Milestones are milestones that can be shared among many projects within the same group
|
2017-01-06 07:47:18 -05:00
|
|
|
class GroupMilestone < GlobalMilestone
|
2019-09-13 09:26:31 -04:00
|
|
|
include_if_ee('::EE::GroupMilestone') # rubocop: disable Cop/InjectEnterpriseEditionModule
|
2018-12-20 06:14:33 -05:00
|
|
|
attr_reader :group, :milestones
|
2017-01-06 07:47:18 -05:00
|
|
|
|
|
|
|
def self.build_collection(group, projects, params)
|
2018-12-20 06:14:33 -05:00
|
|
|
params =
|
2019-01-17 09:35:23 -05:00
|
|
|
{ state: params[:state], search_title: params[:search_title] }
|
2018-12-20 06:14:33 -05:00
|
|
|
|
|
|
|
project_milestones = Milestone.of_projects(projects)
|
2019-01-17 09:35:23 -05:00
|
|
|
project_milestones = project_milestones.search_title(params[:search_title]) if params[:search_title].present?
|
2018-12-20 06:14:33 -05:00
|
|
|
child_milestones = Milestone.filter_by_state(project_milestones, params[:state])
|
|
|
|
grouped_milestones = child_milestones.group_by(&:title)
|
|
|
|
|
|
|
|
grouped_milestones.map do |title, grouped|
|
|
|
|
new(title, grouped, group)
|
2017-01-06 07:47:18 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.build(group, projects, title)
|
2018-12-20 06:14:33 -05:00
|
|
|
child_milestones = Milestone.of_projects(projects).where(title: title)
|
|
|
|
return if child_milestones.blank?
|
|
|
|
|
|
|
|
new(title, child_milestones, group)
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(title, milestones, group)
|
|
|
|
@milestones = milestones
|
|
|
|
@group = group
|
|
|
|
end
|
|
|
|
|
|
|
|
def milestone
|
|
|
|
@milestone ||= milestones.find { |m| m.description.present? } || milestones.first
|
2017-01-06 07:47:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def issues_finder_params
|
|
|
|
{ group_id: group.id }
|
|
|
|
end
|
2017-07-07 11:08:49 -04:00
|
|
|
|
2017-08-24 12:31:20 -04:00
|
|
|
def legacy_group_milestone?
|
2017-07-07 11:08:49 -04:00
|
|
|
true
|
|
|
|
end
|
2017-01-06 07:47:18 -05:00
|
|
|
end
|