Commit 3d24c01a authored by Sean McGivern's avatar Sean McGivern

Merge branch '39335-add-time-spend-to-milestones' into 'master'

Add total time spent to milestones

Closes #39335

See merge request gitlab-org/gitlab-ce!15116
parents 9b1e9da9 8f6b3d74
...@@ -86,6 +86,14 @@ module Milestoneish ...@@ -86,6 +86,14 @@ module Milestoneish
false false
end end
def total_issue_time_spent
@total_issue_time_spent ||= issues.joins(:timelogs).sum(:time_spent)
end
def human_total_issue_time_spent
Gitlab::TimeTrackingFormatter.output(total_issue_time_spent)
end
private private
def count_issues_by_state(user) def count_issues_by_state(user)
......
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path d="M10.331 4.889A2.988 2.988 0 0 0 11 3V2H5v1c0 .362.064.709.182 1.03l5.15.859zM3 14v-1c0-1.78.93-3.342 2.33-4.228.447-.327.67-.582.67-.764 0-.19-.242-.46-.725-.815A4.996 4.996 0 0 1 3 3V2H2a1 1 0 1 1 0-2h12a1 1 0 0 1 0 2h-1v1a4.997 4.997 0 0 1-2.39 4.266c-.407.3-.61.545-.61.734 0 .19.203.434.61.734A4.997 4.997 0 0 1 13 13v1h1a1 1 0 0 1 0 2H2a1 1 0 0 1 0-2h1zm8 0v-1a3 3 0 0 0-6 0v1h6z"/></svg>
...@@ -85,6 +85,22 @@ ...@@ -85,6 +85,22 @@
Closed: Closed:
= milestone.issues_visible_to_user(current_user).closed.count = milestone.issues_visible_to_user(current_user).closed.count
.block.time_spent
.sidebar-collapsed-icon
= custom_icon('icon_hourglass')
%span.collapsed-milestone-total-time-spent
- if milestone.human_total_issue_time_spent
= milestone.human_total_issue_time_spent
- else
= _("None")
.title.hide-collapsed
= _("Total issue time spent")
.value.hide-collapsed
- if milestone.human_total_issue_time_spent
%span.bold= milestone.human_total_issue_time_spent
- else
%span.no-value= _("No time spent")
.block.merge-requests .block.merge-requests
.sidebar-collapsed-icon .sidebar-collapsed-icon
%strong %strong
......
---
title: Add total time spent to milestones
merge_request: 15116
author: George Andrinopoulos
type: added
...@@ -65,4 +65,33 @@ feature 'Milestone' do ...@@ -65,4 +65,33 @@ feature 'Milestone' do
expect(find('.alert-danger')).to have_content('already being used for another group or project milestone.') expect(find('.alert-danger')).to have_content('already being used for another group or project milestone.')
end end
end end
feature 'Open a milestone' do
scenario 'shows total issue time spent correctly when no time has been logged' do
milestone = create(:milestone, project: project, title: 8.7)
visit project_milestone_path(project, milestone)
page.within('.block.time_spent') do
expect(page).to have_content 'No time spent'
expect(page).to have_content 'None'
end
end
scenario 'shows total issue time spent' do
milestone = create(:milestone, project: project, title: 8.7)
issue1 = create(:issue, project: project, milestone: milestone)
issue2 = create(:issue, project: project, milestone: milestone)
issue1.spend_time(duration: 3600, user: user)
issue1.save!
issue2.spend_time(duration: 7200, user: user)
issue2.save!
visit project_milestone_path(project, milestone)
page.within('.block.time_spent') do
expect(page).to have_content '3h'
end
end
end
end end
...@@ -186,4 +186,21 @@ describe Milestone, 'Milestoneish' do ...@@ -186,4 +186,21 @@ describe Milestone, 'Milestoneish' do
expect(milestone.elapsed_days).to eq(2) expect(milestone.elapsed_days).to eq(2)
end end
end end
describe '#total_issue_time_spent' do
it 'calculates total issue time spent' do
closed_issue_1.spend_time(duration: 300, user: author)
closed_issue_1.save!
closed_issue_2.spend_time(duration: 600, user: assignee)
closed_issue_2.save!
expect(milestone.total_issue_time_spent).to eq(900)
end
end
describe '#human_total_issue_time_spent' do
it 'returns nil if no time has been spent' do
expect(milestone.human_total_issue_time_spent).to be_nil
end
end
end end
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