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

96 lines
1.8 KiB
Ruby
Raw Normal View History

class GroupMilestone
def initialize(title, milestones)
@title = title
@milestones = milestones
end
def title
@title
end
def safe_title
2014-06-30 10:18:26 -04:00
@title.parameterize
end
def milestones
@milestones
end
2014-06-26 07:32:35 -04:00
def projects
2014-06-30 07:27:17 -04:00
milestones.map { |milestone| milestone.project }
end
def issue_count
2014-06-30 07:27:17 -04:00
milestones.map { |milestone| milestone.issues.count }.sum
end
def merge_requests_count
2014-06-30 07:27:17 -04:00
milestones.map { |milestone| milestone.merge_requests.count }.sum
end
def open_items_count
2014-06-30 07:27:17 -04:00
milestones.map { |milestone| milestone.open_items_count }.sum
end
def closed_items_count
2014-06-30 07:27:17 -04:00
milestones.map { |milestone| milestone.closed_items_count }.sum
end
def total_items_count
2014-06-30 07:27:17 -04:00
milestones.map { |milestone| milestone.total_items_count }.sum
end
def percent_complete
((closed_items_count * 100) / total_items_count).abs
rescue ZeroDivisionError
100
end
2014-06-26 05:58:40 -04:00
def state
2014-06-30 07:27:17 -04:00
state = milestones.map { |milestone| milestone.state }
2014-06-26 07:32:35 -04:00
if state.count('closed') == state.size
2014-06-26 05:58:40 -04:00
'closed'
else
'active'
2014-06-26 05:58:40 -04:00
end
end
def active?
state == 'active'
end
def closed?
state == 'closed'
end
def issues
2014-06-30 07:27:17 -04:00
@group_issues ||= milestones.map { |milestone| milestone.issues }.flatten.group_by(&:state)
end
def merge_requests
2014-06-30 07:27:17 -04:00
@group_merge_requests ||= milestones.map { |milestone| milestone.merge_requests }.flatten.group_by(&:state)
end
def participants
2014-06-30 07:27:17 -04:00
milestones.map { |milestone| milestone.participants.uniq }.reject(&:empty?).flatten
end
def opened_issues
issues.values_at("opened", "reopened").compact.flatten
end
def closed_issues
issues['closed']
end
def opened_merge_requests
merge_requests.values_at("opened", "reopened").compact.flatten
end
def closed_merge_requests
merge_requests.values_at("closed", "merged", "locked").compact.flatten
end
end