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

99 lines
2 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
2016-11-03 12:29:30 +05:30
def for_display
@first_milestone
end
2015-11-26 14:37:03 +05:30
def self.build_collection(milestones)
milestones = milestones.group_by(&:title)
milestones.map do |title, milestones|
2016-11-03 12:29:30 +05:30
milestones_relation = Milestone.where(id: milestones.map(&:id))
new(title, milestones_relation)
2015-11-26 14:37:03 +05:30
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
2016-11-03 12:29:30 +05:30
@first_milestone = milestones.find {|m| m.description.present? } || milestones.first
2014-09-02 18:07:02 +05:30
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-11-03 12:29:30 +05:30
@projects ||= Project.for_milestones(milestones.select(: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-11-03 12:29:30 +05:30
@issues ||= Issue.of_milestones(milestones.select(:id)).includes(:project, :assignee, :labels)
2014-09-02 18:07:02 +05:30
end
def merge_requests
2016-11-03 12:29:30 +05:30
@merge_requests ||= MergeRequest.of_milestones(milestones.select(:id)).includes(:target_project, :assignee, :labels)
2014-09-02 18:07:02 +05:30
end
def participants
2016-11-03 12:29:30 +05:30
@participants ||= milestones.includes(:participants).map(&:participants).flatten.compact.uniq
2014-09-02 18:07:02 +05:30
end
2016-06-02 11:05:42 +05:30
def labels
2016-11-03 12:29:30 +05:30
@labels ||= GlobalLabel.build_collection(milestones.includes(:labels).map(&:labels).flatten)
2016-06-02 11:05:42 +05:30
.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