2018-07-25 09:30:33 +00:00
|
|
|
# frozen_string_literal: true
|
2018-08-03 19:52:37 +00:00
|
|
|
# Group Milestones are milestones that can be shared among many projects within the same group
|
2017-01-06 12:47:18 +00:00
|
|
|
class GroupMilestone < GlobalMilestone
|
2018-12-20 11:14:33 +00:00
|
|
|
attr_reader :group, :milestones
|
2017-01-06 12:47:18 +00:00
|
|
|
|
|
|
|
def self.build_collection(group, projects, params)
|
2018-12-20 11:14:33 +00:00
|
|
|
params =
|
2019-01-17 14:35:23 +00:00
|
|
|
{ state: params[:state], search_title: params[:search_title] }
|
2018-12-20 11:14:33 +00:00
|
|
|
|
|
|
|
project_milestones = Milestone.of_projects(projects)
|
2019-01-17 14:35:23 +00:00
|
|
|
project_milestones = project_milestones.search_title(params[:search_title]) if params[:search_title].present?
|
2018-12-20 11:14:33 +00: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 12:47:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.build(group, projects, title)
|
2018-12-20 11:14:33 +00: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 12:47:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def issues_finder_params
|
|
|
|
{ group_id: group.id }
|
|
|
|
end
|
2017-07-07 15:08:49 +00:00
|
|
|
|
2017-08-24 16:31:20 +00:00
|
|
|
def legacy_group_milestone?
|
2017-07-07 15:08:49 +00:00
|
|
|
true
|
|
|
|
end
|
2017-01-06 12:47:18 +00:00
|
|
|
end
|