diff options
author | Alex Braha Stoll <alexbrahastoll@gmail.com> | 2016-12-13 07:29:12 +0300 |
---|---|---|
committer | Adam Niedzielski <adamsunday@gmail.com> | 2017-03-10 15:04:19 +0300 |
commit | 50a8f16e165d45bf6b518c0e250e1f5a360a6d3f (patch) | |
tree | 750a23b4089a654453c612a79e595fd701c12c70 /app/models/global_milestone.rb | |
parent | 81ad61113112c49704cfe24b8e47479976422e60 (diff) |
Add count badges to both dashboard and group milestones
Diffstat (limited to 'app/models/global_milestone.rb')
-rw-r--r-- | app/models/global_milestone.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/models/global_milestone.rb b/app/models/global_milestone.rb index b991d78e27f..0afbca2cb32 100644 --- a/app/models/global_milestone.rb +++ b/app/models/global_milestone.rb @@ -28,6 +28,28 @@ class GlobalMilestone new(title, child_milestones) end + def self.states_count(projects) + relation = MilestonesFinder.new.execute(projects, state: 'all') + milestones_by_state_and_title = relation.reorder(nil).group(:state, :title).count + + opened = count_by_state(milestones_by_state_and_title, 'active') + closed = count_by_state(milestones_by_state_and_title, 'closed') + all = milestones_by_state_and_title.map { |(_, title), _| title }.uniq.count + + { + opened: opened, + closed: closed, + all: all + } + end + + def self.count_by_state(milestones_by_state_and_title, state) + milestones_by_state_and_title.count do |(milestone_state, _), _| + milestone_state == state + end + end + private_class_method :count_by_state + def initialize(title, milestones) @title = title @name = title |