Commit 3cd51173 authored by Ronald van Zon's avatar Ronald van Zon Committed by Eagllus

Fixing count on Milestones

By adding groups to milestones we can now include them
in the count of Open and Closed.
parent a5cfacc2
...@@ -12,4 +12,8 @@ class Dashboard::ApplicationController < ApplicationController ...@@ -12,4 +12,8 @@ class Dashboard::ApplicationController < ApplicationController
def projects def projects
@projects ||= current_user.authorized_projects.sorted_by_activity.non_archived @projects ||= current_user.authorized_projects.sorted_by_activity.non_archived
end end
def groups
@groups ||= GroupsFinder.new(current_user, state_all: true).execute
end
end end
...@@ -4,12 +4,13 @@ class Dashboard::MilestonesController < Dashboard::ApplicationController ...@@ -4,12 +4,13 @@ class Dashboard::MilestonesController < Dashboard::ApplicationController
include MilestoneActions include MilestoneActions
before_action :projects before_action :projects
before_action :groups
before_action :milestone, only: [:show, :merge_requests, :participants, :labels] before_action :milestone, only: [:show, :merge_requests, :participants, :labels]
def index def index
respond_to do |format| respond_to do |format|
format.html do format.html do
@milestone_states = GlobalMilestone.states_count(@projects) @milestone_states = GlobalMilestone.states_count(@projects, @groups)
@milestones = Kaminari.paginate_array(milestones).page(params[:page]) @milestones = Kaminari.paginate_array(milestones).page(params[:page])
end end
format.json do format.json do
......
...@@ -34,15 +34,31 @@ class GlobalMilestone ...@@ -34,15 +34,31 @@ class GlobalMilestone
new(title, child_milestones) new(title, child_milestones)
end 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) 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.merge(group_milestones_count) do |k, legacy_group_milestones_count, group_milestones_count|
legacy_group_milestones_count + group_milestones_count legacy_group_milestones_count + group_milestones_count
end end
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) def self.group_milestones_states_count(group)
return STATE_COUNT_HASH unless group return STATE_COUNT_HASH unless group
......
---
title: Fixing count on Milestones
merge_request: 21446
author: eagllus
type: fixed
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