Create group milestones service.
This commit is contained in:
parent
e1afea777a
commit
58570880f0
|
@ -6,5 +6,7 @@ class Groups::MilestonesController < ApplicationController
|
|||
project_ids = @group.projects
|
||||
project_milestones = Milestone.where(project_id: project_ids)
|
||||
@milestones = project_milestones
|
||||
@group_milestones = Milestones::GroupService.new(@group, current_user, project_milestones)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
module Milestones
|
||||
class GroupService < Milestones::BaseService
|
||||
def initialize(group, user, project_milestones)
|
||||
@group = group
|
||||
@user = user
|
||||
@project_milestones = project_milestones.group_by(&:title)
|
||||
end
|
||||
|
||||
def titles
|
||||
@project_milestones.map{ |title, milestone| title }
|
||||
end
|
||||
|
||||
def project_names
|
||||
names = {}
|
||||
@project_milestones.map do |title, milestone|
|
||||
projects = milestone.map{|m| m.project.name }
|
||||
names.store(title, projects)
|
||||
end
|
||||
names
|
||||
end
|
||||
|
||||
def issue_count
|
||||
@project_milestones.merge(@project_milestones){ |title, milestone| milestone.map{|m| m.issues.count }.sum }
|
||||
end
|
||||
|
||||
def mr_count
|
||||
@project_milestones.merge(@project_milestones){ |title, milestone| milestone.map{|m| m.merge_requests.count }.sum }
|
||||
end
|
||||
|
||||
def open_issues_count
|
||||
@project_milestones.merge(@project_milestones){ |title, milestone| milestone.map{|m| m.issues.opened.count }.sum }
|
||||
end
|
||||
|
||||
def closed_issues_count
|
||||
@project_milestones.merge(@project_milestones){ |title, milestone| milestone.map{|m| m.issues.closed.count }.sum }
|
||||
end
|
||||
|
||||
def open_mr_count
|
||||
@project_milestones.merge(@project_milestones){ |title, milestone| milestone.map{|m| m.merge_requests.opened.count }.sum }
|
||||
end
|
||||
|
||||
def close_mr_count
|
||||
@project_milestones.merge(@project_milestones){ |title, milestone| milestone.map{|m| m.merge_requests.closed.count }.sum }
|
||||
end
|
||||
|
||||
def open_items_count
|
||||
open_issues_count.merge(open_mr_count){ |title,issue,mr| issue + mr }
|
||||
end
|
||||
|
||||
def closed_items_count
|
||||
closed_issues_count.merge(close_mr_count){ |title,issue,mr| issue + mr }
|
||||
end
|
||||
|
||||
def total_items_count
|
||||
issue_count.merge(mr_count){ |title,issue,mr| issue + mr }
|
||||
end
|
||||
|
||||
def percent_complete
|
||||
percentage_per_milestone = {}
|
||||
closed_items_count.map do |title, closed_items|
|
||||
total_items = total_items_count[title]
|
||||
percentage = begin
|
||||
((closed_items * 100) / total_items).abs
|
||||
rescue ZeroDivisionError
|
||||
100
|
||||
end
|
||||
percentage_per_milestone.store(title, percentage)
|
||||
end
|
||||
percentage_per_milestone
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -17,11 +17,11 @@
|
|||
.col-md-9
|
||||
.panel.panel-default
|
||||
%ul.well-list
|
||||
- if @milestones.blank?
|
||||
- if @group_milestones.blank?
|
||||
%li
|
||||
.nothing-here-block No milestones to show
|
||||
- else
|
||||
- @milestones.group_by(&:title).each do |milestone|
|
||||
- @group_milestones.titles.each do |title|
|
||||
%li{class: "milestone milestone-open", id: 1 }
|
||||
.pull-right
|
||||
= link_to root_path, class: "btn btn-small edit-milestone-link btn-grouped" do
|
||||
|
@ -29,4 +29,23 @@
|
|||
Edit
|
||||
= link_to 'Close Milestone', root_path, method: :put, remote: true, class: "btn btn-small btn-remove"
|
||||
%h4
|
||||
= link_to_gfm truncate(milestone.first, length: 100), root_path
|
||||
= link_to_gfm truncate(title, length: 100), root_path
|
||||
- if false
|
||||
%span.muted Empty
|
||||
- else
|
||||
%div
|
||||
%div
|
||||
= link_to root_path do
|
||||
= pluralize @group_milestones.issue_count[title], 'Issue'
|
||||
|
||||
= link_to root_path do
|
||||
= pluralize @group_milestones.mr_count[title], 'Merge Request'
|
||||
|
||||
%span.light #{@group_milestones.percent_complete[title]}% complete
|
||||
.progress.progress-info
|
||||
.progress-bar{style: "width: #{@group_milestones.percent_complete[title]}%;"}
|
||||
%div
|
||||
%br
|
||||
- @group_milestones.project_names[title].each do |name|
|
||||
%span.label.label-default
|
||||
= name
|
||||
|
|
Loading…
Reference in New Issue