2015-11-13 18:20:48 +00:00
|
|
|
class GlobalMilestone
|
2016-03-07 04:07:19 +00:00
|
|
|
include Milestoneish
|
|
|
|
|
2015-10-14 10:33:39 +00:00
|
|
|
attr_accessor :title, :milestones
|
2015-10-09 04:24:55 +00:00
|
|
|
alias_attribute :name, :title
|
|
|
|
|
2015-11-13 18:20:48 +00:00
|
|
|
def self.build_collection(milestones)
|
|
|
|
milestones = milestones.group_by(&:title)
|
|
|
|
|
|
|
|
milestones.map do |title, milestones|
|
2016-03-29 11:19:09 +00:00
|
|
|
new(title, milestones)
|
2015-11-13 18:20:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-26 08:57:36 +00:00
|
|
|
def initialize(title, milestones)
|
|
|
|
@title = title
|
2016-03-24 15:20:35 +00:00
|
|
|
@name = title
|
2014-06-26 08:57:36 +00:00
|
|
|
@milestones = milestones
|
|
|
|
end
|
|
|
|
|
2014-06-27 08:14:57 +00:00
|
|
|
def safe_title
|
2015-12-22 21:15:32 +00:00
|
|
|
@title.to_slug.normalize.to_s
|
2014-06-27 08:14:57 +00:00
|
|
|
end
|
2015-11-13 18:20:48 +00:00
|
|
|
|
2015-11-30 20:47:44 +00:00
|
|
|
def expired?
|
|
|
|
if due_date
|
|
|
|
due_date.past?
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-26 11:32:35 +00:00
|
|
|
def projects
|
2016-02-23 00:08:00 +00:00
|
|
|
@projects ||= Project.for_milestones(milestones.map(&:id))
|
2014-06-26 08:57:36 +00:00
|
|
|
end
|
|
|
|
|
2014-06-26 09:58:40 +00:00
|
|
|
def state
|
2014-06-30 11:27:17 +00:00
|
|
|
state = milestones.map { |milestone| milestone.state }
|
2014-06-26 11:32:35 +00:00
|
|
|
|
2014-07-14 13:25:09 +00:00
|
|
|
if state.count('closed') == state.size
|
2014-06-26 09:58:40 +00:00
|
|
|
'closed'
|
2014-07-14 13:25:09 +00:00
|
|
|
else
|
|
|
|
'active'
|
2014-06-26 09:58:40 +00:00
|
|
|
end
|
|
|
|
end
|
2014-06-27 08:14:57 +00:00
|
|
|
|
|
|
|
def active?
|
|
|
|
state == 'active'
|
|
|
|
end
|
|
|
|
|
|
|
|
def closed?
|
|
|
|
state == 'closed'
|
|
|
|
end
|
|
|
|
|
2014-06-30 08:54:57 +00:00
|
|
|
def issues
|
2016-09-20 18:59:17 +00:00
|
|
|
@issues ||= Issue.of_milestones(milestones.map(&:id)).includes(:project, :assignee, :labels)
|
2014-06-27 08:14:57 +00:00
|
|
|
end
|
|
|
|
|
2014-06-30 08:54:57 +00:00
|
|
|
def merge_requests
|
2016-09-20 18:59:17 +00:00
|
|
|
@merge_requests ||= MergeRequest.of_milestones(milestones.map(&:id)).includes(:target_project, :assignee, :labels)
|
2014-06-27 08:14:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def participants
|
2016-09-20 21:05:49 +00:00
|
|
|
@participants ||= milestones_relation.includes(:participants).map(&:participants).flatten.compact.uniq
|
2014-06-27 08:14:57 +00:00
|
|
|
end
|
2014-06-30 10:41:27 +00:00
|
|
|
|
2016-02-23 21:22:36 +00:00
|
|
|
def labels
|
2016-09-20 21:05:49 +00:00
|
|
|
@labels ||= GlobalLabel.build_collection(milestones_relation.includes(:labels).map(&:labels).flatten)
|
2016-03-07 04:07:19 +00:00
|
|
|
.sort_by!(&:title)
|
2015-11-16 18:55:58 +00:00
|
|
|
end
|
2015-11-30 20:47:44 +00: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
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def expires_at
|
|
|
|
if due_date
|
|
|
|
if due_date.past?
|
2016-01-06 22:27:56 +00:00
|
|
|
"expired on #{due_date.to_s(:medium)}"
|
2015-11-30 20:47:44 +00:00
|
|
|
else
|
2016-01-06 22:27:56 +00:00
|
|
|
"expires on #{due_date.to_s(:medium)}"
|
2015-11-30 20:47:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-09-20 21:05:49 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def milestones_relation
|
|
|
|
@milestones_relation ||= if milestones.is_a?(ActiveRecord::Relation)
|
|
|
|
milestones
|
|
|
|
else
|
|
|
|
Milestone.where(id: milestones.map(&:id))
|
|
|
|
end
|
|
|
|
end
|
2014-06-26 08:57:36 +00:00
|
|
|
end
|