diff options
author | Ronald van Zon <rvzon84@gmail.com> | 2018-08-30 14:17:36 +0000 |
---|---|---|
committer | Eagllus <rvanzon@gitlab.com> | 2018-10-04 08:54:23 +0200 |
commit | 3cd511733b5b646becfdf72e36062b863dfbcf20 (patch) | |
tree | 364b8e7bf9421bb91c506749fa292485d0bef214 | |
parent | a5cfacc281855e3d2f1da4b08d4579a089c3d311 (diff) | |
download | gitlab-ce-3cd511733b5b646becfdf72e36062b863dfbcf20.tar.gz |
Fixing count on Milestones
By adding groups to milestones we can now include them
in the count of Open and Closed.
-rw-r--r-- | app/controllers/dashboard/application_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/dashboard/milestones_controller.rb | 3 | ||||
-rw-r--r-- | app/models/global_milestone.rb | 20 | ||||
-rw-r--r-- | changelogs/unreleased/rz_fix_milestone_count.yml | 5 |
4 files changed, 29 insertions, 3 deletions
diff --git a/app/controllers/dashboard/application_controller.rb b/app/controllers/dashboard/application_controller.rb index cee0753a021..1c9a5917da5 100644 --- a/app/controllers/dashboard/application_controller.rb +++ b/app/controllers/dashboard/application_controller.rb @@ -12,4 +12,8 @@ class Dashboard::ApplicationController < ApplicationController def projects @projects ||= current_user.authorized_projects.sorted_by_activity.non_archived end + + def groups + @groups ||= GroupsFinder.new(current_user, state_all: true).execute + end end diff --git a/app/controllers/dashboard/milestones_controller.rb b/app/controllers/dashboard/milestones_controller.rb index 6e17bc212e4..ddc1a66d11d 100644 --- a/app/controllers/dashboard/milestones_controller.rb +++ b/app/controllers/dashboard/milestones_controller.rb @@ -4,12 +4,13 @@ class Dashboard::MilestonesController < Dashboard::ApplicationController include MilestoneActions before_action :projects + before_action :groups before_action :milestone, only: [:show, :merge_requests, :participants, :labels] def index respond_to do |format| format.html do - @milestone_states = GlobalMilestone.states_count(@projects) + @milestone_states = GlobalMilestone.states_count(@projects, @groups) @milestones = Kaminari.paginate_array(milestones).page(params[:page]) end format.json do diff --git a/app/models/global_milestone.rb b/app/models/global_milestone.rb index a6cebabe089..d07ef43c97e 100644 --- a/app/models/global_milestone.rb +++ b/app/models/global_milestone.rb @@ -34,15 +34,31 @@ class GlobalMilestone new(title, child_milestones) end - def self.states_count(projects, group = nil) + def self.states_count(projects, groups = nil) legacy_group_milestones_count = legacy_group_milestone_states_count(projects) - group_milestones_count = group_milestones_states_count(group) + group_milestones_count = groups_milestone_state_count(groups) legacy_group_milestones_count.merge(group_milestones_count) do |k, legacy_group_milestones_count, group_milestones_count| legacy_group_milestones_count + group_milestones_count end end + def self.groups_milestone_state_count(groups) + return STATE_COUNT_HASH unless groups + return self.group_milestones_states_count(groups) unless groups.respond_to?(:each) + + milestone_states = STATE_COUNT_HASH + + groups.each do |group| + group_milestones_count = self.group_milestones_states_count(group) + milestone_states = milestone_states.merge(group_milestones_count) do |k, milestone_state, group_milestones_count| + milestone_state + group_milestones_count + end + end + + milestone_states + end + def self.group_milestones_states_count(group) return STATE_COUNT_HASH unless group diff --git a/changelogs/unreleased/rz_fix_milestone_count.yml b/changelogs/unreleased/rz_fix_milestone_count.yml new file mode 100644 index 00000000000..f85cfe48b2d --- /dev/null +++ b/changelogs/unreleased/rz_fix_milestone_count.yml @@ -0,0 +1,5 @@ +--- +title: Fixing count on Milestones +merge_request: 21446 +author: eagllus +type: fixed |