debian-mirror-gitlab/app/models/global_milestone.rb

93 lines
1.7 KiB
Ruby
Raw Normal View History

2015-11-26 14:37:03 +05:30
class GlobalMilestone
2016-06-02 11:05:42 +05:30
include Milestoneish
2015-10-24 18:46:33 +05:30
attr_accessor :title, :milestones
alias_attribute :name, :title
2014-09-02 18:07:02 +05:30
2015-11-26 14:37:03 +05:30
def self.build_collection(milestones)
milestones = milestones.group_by(&:title)
milestones.map do |title, milestones|
new(title, milestones)
end
end
2014-09-02 18:07:02 +05:30
def initialize(title, milestones)
@title = title
2016-06-02 11:05:42 +05:30
@name = title
2014-09-02 18:07:02 +05:30
@milestones = milestones
end
def safe_title
@title.to_slug.normalize.to_s
2015-12-23 02:04:40 +05:30
end
def expired?
if due_date
due_date.past?
else
false
end
2014-09-02 18:07:02 +05:30
end
2015-11-26 14:37:03 +05:30
2014-09-02 18:07:02 +05:30
def projects
2016-06-02 11:05:42 +05:30
@projects ||= Project.for_milestones(milestones.map(&:id))
2014-09-02 18:07:02 +05:30
end
def state
state = milestones.map { |milestone| milestone.state }
if state.count('closed') == state.size
'closed'
else
'active'
end
end
def active?
state == 'active'
end
def closed?
state == 'closed'
end
def issues
2016-06-02 11:05:42 +05:30
@issues ||= Issue.of_milestones(milestones.map(&:id)).includes(:project)
2014-09-02 18:07:02 +05:30
end
def merge_requests
2016-06-02 11:05:42 +05:30
@merge_requests ||= MergeRequest.of_milestones(milestones.map(&:id)).includes(:target_project)
2014-09-02 18:07:02 +05:30
end
def participants
2015-11-26 14:37:03 +05:30
@participants ||= milestones.map(&:participants).flatten.compact.uniq
2014-09-02 18:07:02 +05:30
end
2016-06-02 11:05:42 +05:30
def labels
@labels ||= GlobalLabel.build_collection(milestones.map(&:labels).flatten)
.sort_by!(&:title)
2015-11-26 14:37:03 +05:30
end
2015-12-23 02:04:40 +05:30
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?
"expired on #{due_date.to_s(:medium)}"
2015-12-23 02:04:40 +05:30
else
"expires on #{due_date.to_s(:medium)}"
2015-12-23 02:04:40 +05:30
end
end
end
2014-09-02 18:07:02 +05:30
end