diff options
author | Marin Jankovski <marin@gitlab.com> | 2014-06-25 16:19:03 +0200 |
---|---|---|
committer | Marin Jankovski <marin@gitlab.com> | 2014-06-30 09:44:30 +0200 |
commit | 58570880f0ffde173de31a0093f6a9d243467fef (patch) | |
tree | 60663bfd1930411e1a49afbe827394d4031bc840 | |
parent | e1afea777a6f0d2e28adc2765c9445cb10bd25f8 (diff) | |
download | gitlab-ce-58570880f0ffde173de31a0093f6a9d243467fef.tar.gz |
Create group milestones service.
-rw-r--r-- | app/controllers/groups/milestones_controller.rb | 2 | ||||
-rw-r--r-- | app/services/milestones/group_service.rb | 73 | ||||
-rw-r--r-- | app/views/groups/milestones/index.html.haml | 25 |
3 files changed, 97 insertions, 3 deletions
diff --git a/app/controllers/groups/milestones_controller.rb b/app/controllers/groups/milestones_controller.rb index 88a709024d4..e85ef3ff25f 100644 --- a/app/controllers/groups/milestones_controller.rb +++ b/app/controllers/groups/milestones_controller.rb @@ -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 diff --git a/app/services/milestones/group_service.rb b/app/services/milestones/group_service.rb new file mode 100644 index 00000000000..1655100e012 --- /dev/null +++ b/app/services/milestones/group_service.rb @@ -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 diff --git a/app/views/groups/milestones/index.html.haml b/app/views/groups/milestones/index.html.haml index a9cf06b817d..b5d68153a9a 100644 --- a/app/views/groups/milestones/index.html.haml +++ b/app/views/groups/milestones/index.html.haml @@ -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 |