Add total time spent to milestones
This commit is contained in:
parent
d180affa21
commit
f39fe4d8db
5 changed files with 82 additions and 0 deletions
|
@ -152,4 +152,12 @@ class GlobalMilestone
|
|||
@milestones.first.start_date
|
||||
end
|
||||
end
|
||||
|
||||
def total_time_spent
|
||||
issues.joins(:timelogs).sum(:time_spent) + merge_requests.joins(:timelogs).sum(:time_spent)
|
||||
end
|
||||
|
||||
def human_total_time_spent
|
||||
Gitlab::TimeTrackingFormatter.output(total_time_spent) || 0
|
||||
end
|
||||
end
|
||||
|
|
|
@ -213,6 +213,14 @@ class Milestone < ActiveRecord::Base
|
|||
project_id.present?
|
||||
end
|
||||
|
||||
def total_time_spent
|
||||
issues.joins(:timelogs).sum(:time_spent) + merge_requests.joins(:timelogs).sum(:time_spent)
|
||||
end
|
||||
|
||||
def human_total_time_spent
|
||||
Gitlab::TimeTrackingFormatter.output(total_time_spent) || 0
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Milestone titles must be unique across project milestones and group milestones
|
||||
|
|
|
@ -85,6 +85,16 @@
|
|||
Closed:
|
||||
= milestone.issues_visible_to_user(current_user).closed.count
|
||||
|
||||
.block.time_spent
|
||||
.sidebar-collapsed-icon
|
||||
%strong
|
||||
= custom_icon('icon_clock_o')
|
||||
%span= milestone.human_total_time_spent
|
||||
.title.hide-collapsed
|
||||
Total time spent
|
||||
.value.hide-collapsed
|
||||
= milestone.human_total_time_spent
|
||||
|
||||
.block.merge-requests
|
||||
.sidebar-collapsed-icon
|
||||
%strong
|
||||
|
|
|
@ -190,4 +190,37 @@ describe GlobalMilestone do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#total_time_spent' do
|
||||
let(:milestone1_project1) { create(:milestone, title: "Milestone v1.2", project: project1) }
|
||||
let(:milestone1_project2) { create(:milestone, title: "Milestone v1.2", project: project2) }
|
||||
let(:issue1) { create(:issue, milestone: milestone1_project1) }
|
||||
let(:issue2) { create(:issue, milestone: milestone1_project2) }
|
||||
let(:merge_request1) { create(:merge_request, milestone: milestone1_project1) }
|
||||
let(:merge_request2) { create(:merge_request, milestone: milestone1_project2) }
|
||||
|
||||
before do
|
||||
milestones =
|
||||
[
|
||||
milestone1_project1,
|
||||
milestone1_project2
|
||||
]
|
||||
milestones_relation = Milestone.where(id: milestones.map(&:id))
|
||||
|
||||
@global_milestone = described_class.new(milestone1_project1.title, milestones_relation)
|
||||
end
|
||||
|
||||
it 'calculates total time spent' do
|
||||
issue1.spend_time(duration: 300, user: user)
|
||||
issue1.save!
|
||||
issue2.spend_time(duration: 600, user: user2)
|
||||
issue2.save!
|
||||
merge_request1.spend_time(duration: 200, user: user)
|
||||
merge_request1.save!
|
||||
merge_request2.spend_time(duration: 100, user: user2)
|
||||
merge_request2.save!
|
||||
|
||||
expect(@global_milestone.total_time_spent).to eq(1200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -284,4 +284,27 @@ describe Milestone do
|
|||
expect(milestone.participants).to eq [user]
|
||||
end
|
||||
end
|
||||
|
||||
describe '#total_time_spent' do
|
||||
let(:user) { build(:user) }
|
||||
let(:project) { build(:project, name: 'sample-project') }
|
||||
let(:milestone) { build(:milestone, iid: 1, project: project) }
|
||||
let(:issue1) { build(:issue, milestone: milestone) }
|
||||
let(:issue2) { build(:issue, milestone: milestone) }
|
||||
let(:merge_request1) { build(:merge_request, milestone: milestone) }
|
||||
let(:merge_request2) { build(:merge_request, milestone: milestone) }
|
||||
|
||||
it 'calculates total time spent' do
|
||||
issue1.spend_time(duration: 300, user: user)
|
||||
issue1.save!
|
||||
issue2.spend_time(duration: 600, user: user)
|
||||
issue2.save!
|
||||
merge_request1.spend_time(duration: 200, user: user)
|
||||
merge_request1.save!
|
||||
merge_request2.spend_time(duration: 100, user: user)
|
||||
merge_request2.save!
|
||||
|
||||
expect(milestone.total_time_spent).to eq(1200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue