2018-08-03 13:22:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-06 23:07:19 -05:00
|
|
|
module Milestoneish
|
2016-11-29 08:47:43 -05:00
|
|
|
def closed_items_count(user)
|
2016-12-16 10:52:27 -05:00
|
|
|
memoize_per_user(user, :closed_items_count) do
|
2017-06-09 14:53:32 -04:00
|
|
|
(count_issues_by_state(user)['closed'] || 0) + merge_requests.closed_and_merged.size
|
2016-12-16 10:52:27 -05:00
|
|
|
end
|
2016-03-06 23:07:19 -05:00
|
|
|
end
|
|
|
|
|
2016-11-29 08:47:43 -05:00
|
|
|
def total_items_count(user)
|
2016-12-16 10:52:27 -05:00
|
|
|
memoize_per_user(user, :total_items_count) do
|
2017-01-10 13:30:28 -05:00
|
|
|
total_issues_count(user) + merge_requests.size
|
2016-12-16 10:52:27 -05:00
|
|
|
end
|
2016-03-06 23:07:19 -05:00
|
|
|
end
|
|
|
|
|
2017-01-10 13:30:28 -05:00
|
|
|
def total_issues_count(user)
|
2017-06-09 14:53:32 -04:00
|
|
|
count_issues_by_state(user).values.sum
|
2017-01-10 13:30:28 -05:00
|
|
|
end
|
|
|
|
|
2016-11-29 08:47:43 -05:00
|
|
|
def complete?(user)
|
2016-04-26 07:22:52 -04:00
|
|
|
total_items_count(user) > 0 && total_items_count(user) == closed_items_count(user)
|
2016-03-06 23:07:19 -05:00
|
|
|
end
|
|
|
|
|
2016-11-29 08:47:43 -05:00
|
|
|
def percent_complete(user)
|
2016-03-17 16:59:30 -04:00
|
|
|
((closed_items_count(user) * 100) / total_items_count(user)).abs
|
2016-03-06 23:07:19 -05:00
|
|
|
rescue ZeroDivisionError
|
|
|
|
0
|
|
|
|
end
|
|
|
|
|
|
|
|
def remaining_days
|
|
|
|
return 0 if !due_date || expired?
|
|
|
|
|
|
|
|
(due_date - Date.today).to_i
|
|
|
|
end
|
2016-03-17 16:59:30 -04:00
|
|
|
|
2016-11-15 12:48:30 -05:00
|
|
|
def elapsed_days
|
|
|
|
return 0 if !start_date || start_date.future?
|
|
|
|
|
|
|
|
(Date.today - start_date).to_i
|
|
|
|
end
|
|
|
|
|
2016-11-29 08:47:43 -05:00
|
|
|
def issues_visible_to_user(user)
|
2016-12-16 10:52:27 -05:00
|
|
|
memoize_per_user(user, :issues_visible_to_user) do
|
2017-06-08 15:55:50 -04:00
|
|
|
IssuesFinder.new(user, issues_finder_params)
|
2017-06-07 17:14:23 -04:00
|
|
|
.execute.preload(:assignees).where(milestone_id: milestoneish_ids)
|
2016-12-16 10:52:27 -05:00
|
|
|
end
|
2016-03-17 16:59:30 -04:00
|
|
|
end
|
2016-11-15 12:48:30 -05:00
|
|
|
|
2017-06-09 14:53:32 -04:00
|
|
|
def sorted_issues(user)
|
2018-04-04 05:19:47 -04:00
|
|
|
issues_visible_to_user(user).preload_associations.sort_by_attribute('label_priority')
|
2017-06-09 14:53:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def sorted_merge_requests
|
2018-04-04 05:19:47 -04:00
|
|
|
merge_requests.sort_by_attribute('label_priority')
|
2017-06-09 14:53:32 -04:00
|
|
|
end
|
|
|
|
|
2016-11-15 12:48:30 -05:00
|
|
|
def upcoming?
|
|
|
|
start_date && start_date.future?
|
|
|
|
end
|
|
|
|
|
|
|
|
def expires_at
|
|
|
|
if due_date
|
|
|
|
if due_date.past?
|
|
|
|
"expired on #{due_date.to_s(:medium)}"
|
|
|
|
else
|
|
|
|
"expires on #{due_date.to_s(:medium)}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def expired?
|
|
|
|
due_date && due_date.past?
|
|
|
|
end
|
2016-12-16 10:52:27 -05:00
|
|
|
|
2017-08-24 12:41:44 -04:00
|
|
|
def group_milestone?
|
2017-07-07 11:08:49 -04:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2017-08-24 12:37:37 -04:00
|
|
|
def project_milestone?
|
2017-07-07 11:08:49 -04:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2017-08-24 12:31:20 -04:00
|
|
|
def legacy_group_milestone?
|
2017-07-07 11:08:49 -04:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2017-08-24 12:46:42 -04:00
|
|
|
def dashboard_milestone?
|
2017-07-07 11:08:49 -04:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2017-11-06 13:18:20 -05:00
|
|
|
def total_issue_time_spent
|
2017-11-10 15:18:42 -05:00
|
|
|
@total_issue_time_spent ||= issues.joins(:timelogs).sum(:time_spent)
|
2017-11-06 13:18:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def human_total_issue_time_spent
|
|
|
|
Gitlab::TimeTrackingFormatter.output(total_issue_time_spent)
|
|
|
|
end
|
|
|
|
|
2018-02-21 12:20:56 -05:00
|
|
|
def total_issue_time_estimate
|
|
|
|
@total_issue_time_estimate ||= issues.sum(:time_estimate)
|
|
|
|
end
|
|
|
|
|
|
|
|
def human_total_issue_time_estimate
|
|
|
|
Gitlab::TimeTrackingFormatter.output(total_issue_time_estimate)
|
|
|
|
end
|
|
|
|
|
2016-12-16 10:52:27 -05:00
|
|
|
def count_issues_by_state(user)
|
|
|
|
memoize_per_user(user, :count_issues_by_state) do
|
2017-06-09 14:53:32 -04:00
|
|
|
issues_visible_to_user(user).reorder(nil).group(:state).count
|
2016-12-16 10:52:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-19 10:43:20 -04:00
|
|
|
private
|
|
|
|
|
2016-12-16 10:52:27 -05:00
|
|
|
def memoize_per_user(user, method_name)
|
2017-11-17 07:27:16 -05:00
|
|
|
memoized_users[method_name][user&.id] ||= yield
|
|
|
|
end
|
|
|
|
|
|
|
|
def memoized_users
|
|
|
|
@memoized_users ||= Hash.new { |h, k| h[k] = {} }
|
2016-12-16 10:52:27 -05:00
|
|
|
end
|
2017-01-06 07:47:18 -05:00
|
|
|
|
|
|
|
# override in a class that includes this module to get a faster query
|
|
|
|
# from IssuesFinder
|
|
|
|
def issues_finder_params
|
2017-06-09 14:53:32 -04:00
|
|
|
{}
|
2017-01-06 07:47:18 -05:00
|
|
|
end
|
2016-03-06 23:07:19 -05:00
|
|
|
end
|