2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
# Group Milestones are milestones that can be shared among many projects within the same group
|
2017-08-17 22:00:37 +05:30
|
|
|
class GroupMilestone < GlobalMilestone
|
2019-12-16 22:33:55 +05:30
|
|
|
include_if_ee('::EE::GroupMilestone') # rubocop: disable Cop/InjectEnterpriseEditionModule
|
2019-02-15 15:39:39 +05:30
|
|
|
attr_reader :group, :milestones
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
def self.build_collection(group, projects, params)
|
2019-02-15 15:39:39 +05:30
|
|
|
params =
|
2019-03-02 22:35:43 +05:30
|
|
|
{ state: params[:state], search_title: params[:search_title] }
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
project_milestones = Milestone.of_projects(projects)
|
2019-03-02 22:35:43 +05:30
|
|
|
project_milestones = project_milestones.search_title(params[:search_title]) if params[:search_title].present?
|
2019-02-15 15:39:39 +05:30
|
|
|
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-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.build(group, projects, title)
|
2019-02-15 15:39:39 +05:30
|
|
|
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-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def issues_finder_params
|
|
|
|
{ group_id: group.id }
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def legacy_group_milestone?
|
2017-09-10 17:25:29 +05:30
|
|
|
true
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|