Commit 0723bf1a authored by Marin Jankovski's avatar Marin Jankovski

Move group milestone processing from service to model.

parent 8e8c0742
No related merge requests found
......@@ -5,8 +5,7 @@ class Groups::MilestonesController < ApplicationController
@group = Group.find_by(path: params[:group_id])
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)
@group_milestones = Milestones::GroupService.new(project_milestones).execute
end
end
class GroupMilestone
def initialize(title, milestones)
@title = title
@milestones = milestones
end
def title
@title
end
def milestones
@milestones
end
def project_names
milestones.map{ |milestone| milestone.project.name }
end
def issue_count
milestones.map{ |milestone| milestone.issues.count }.sum
end
def merge_requests_count
milestones.map{ |milestone| milestone.merge_requests.count }.sum
end
def closed_items_count
milestones.map{ |milestone| milestone.closed_items_count }.sum
end
def total_items_count
milestones.map{ |milestone| milestone.total_items_count }.sum
end
def percent_complete
((closed_items_count * 100) / total_items_count).abs
rescue ZeroDivisionError
100
end
end
module Milestones
class GroupService < Milestones::BaseService
def initialize(group, user, project_milestones)
@group = group
@user = user
def initialize(project_milestones)
@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
@project_milestones.merge(@project_milestones){ |title, milestone| milestone.map{|m| m.open_items_count }.sum }
end
def closed_items_count
@project_milestones.merge(@project_milestones){ |title, milestone| milestone.map{|m| m.closed_items_count }.sum }
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
def execute
@project_milestones.map{ |title, milestone| GroupMilestone.new(title, milestone) }
end
end
......
%h3.page-title
Milestones
%span.pull-right #{@group_milestones.titles.count} milestones
%span.pull-right #{@group_milestones.count} milestones
%p.light
Only milestones from
......@@ -21,31 +21,28 @@
%li
.nothing-here-block No milestones to show
- else
- @group_milestones.titles.each do |title|
- @group_milestones.each do |milestone|
%li{class: "milestone milestone-open", id: 1 }
.pull-right
= link_to root_path, class: "btn btn-small edit-milestone-link btn-grouped" do
%i.icon-edit
Edit
= link_to 'Close Milestone', root_path, method: :put, remote: true, class: "btn btn-small btn-remove"
%h4
= link_to_gfm truncate(title, length: 100), root_path
= link_to_gfm truncate(milestone.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'
= pluralize milestone.issue_count, 'Issue'
&nbsp;
= link_to root_path do
= pluralize @group_milestones.mr_count[title], 'Merge Request'
= pluralize milestone.merge_requests_count, 'Merge Request'
&nbsp;
%span.light #{@group_milestones.percent_complete[title]}% complete
%span.light #{milestone.percent_complete}% complete
.progress.progress-info
.progress-bar{style: "width: #{@group_milestones.percent_complete[title]}%;"}
.progress-bar{style: "width: #{milestone.percent_complete}%;"}
%div
%br
- @group_milestones.project_names[title].each do |name|
- milestone.project_names.each do |name|
%span.label.label-default
= name
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment