gitlab-org--gitlab-foss/app/models/global_milestone.rb

86 lines
1.9 KiB
Ruby
Raw Normal View History

class GlobalMilestone
2016-03-06 23:07:19 -05:00
include Milestoneish
attr_accessor :title, :milestones
alias_attribute :name, :title
def for_display
@first_milestone
end
def self.build_collection(milestones)
milestones = milestones.group_by(&:title)
milestones.map do |title, milestones|
milestones_relation = Milestone.where(id: milestones.map(&:id))
new(title, milestones_relation)
end
end
def initialize(title, milestones)
@title = title
@name = title
@milestones = milestones
@first_milestone = milestones.find {|m| m.description.present? } || milestones.first
end
def safe_title
@title.to_slug.normalize.to_s
end
2014-06-26 07:32:35 -04:00
def projects
@projects ||= Project.for_milestones(milestones.select(:id))
end
2014-06-26 05:58:40 -04:00
def state
2016-11-15 12:48:30 -05:00
milestones.each do |milestone|
return 'active' if milestone.state != 'closed'
2014-06-26 05:58:40 -04:00
end
2016-11-15 12:48:30 -05:00
'closed'
2014-06-26 05:58:40 -04:00
end
def active?
state == 'active'
end
def closed?
state == 'closed'
end
def issues
@issues ||= Issue.of_milestones(milestones.select(:id)).includes(:project, :assignee, :labels)
end
def merge_requests
@merge_requests ||= MergeRequest.of_milestones(milestones.select(:id)).includes(:target_project, :assignee, :labels)
end
def participants
@participants ||= milestones.includes(:participants).map(&:participants).flatten.compact.uniq
end
def labels
@labels ||= GlobalLabel.build_collection(milestones.includes(:labels).map(&:labels).flatten)
2016-03-06 23:07:19 -05:00
.sort_by!(&:title)
end
2015-11-30 15:47:44 -05:00
def due_date
return @due_date if defined?(@due_date)
@due_date =
if @milestones.all? { |x| x.due_date == @milestones.first.due_date }
@milestones.first.due_date
end
end
2016-11-15 12:48:30 -05:00
def start_date
return @start_date if defined?(@start_date)
@start_date =
if @milestones.all? { |x| x.start_date == @milestones.first.start_date }
@milestones.first.start_date
2015-11-30 15:47:44 -05:00
end
end
end