2018-08-03 17:22:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-07 04:07:19 +00:00
|
|
|
module Milestoneish
|
2020-01-21 15:08:26 +00:00
|
|
|
DISPLAY_ISSUES_LIMIT = 20
|
|
|
|
|
2017-01-10 18:30:28 +00:00
|
|
|
def total_issues_count(user)
|
2017-06-09 18:53:32 +00:00
|
|
|
count_issues_by_state(user).values.sum
|
2017-01-10 18:30:28 +00:00
|
|
|
end
|
|
|
|
|
2019-05-27 09:42:58 +00:00
|
|
|
def closed_issues_count(user)
|
2019-10-18 11:11:44 +00:00
|
|
|
closed_state_id = Issue.available_states[:closed]
|
|
|
|
|
|
|
|
count_issues_by_state(user)[closed_state_id].to_i
|
2019-05-27 09:42:58 +00:00
|
|
|
end
|
|
|
|
|
2016-11-29 13:47:43 +00:00
|
|
|
def complete?(user)
|
2019-05-27 09:42:58 +00:00
|
|
|
total_issues_count(user) > 0 && total_issues_count(user) == closed_issues_count(user)
|
2016-03-07 04:07:19 +00:00
|
|
|
end
|
|
|
|
|
2016-11-29 13:47:43 +00:00
|
|
|
def percent_complete(user)
|
2019-05-27 09:42:58 +00:00
|
|
|
closed_issues_count(user) * 100 / total_issues_count(user)
|
2016-03-07 04:07:19 +00:00
|
|
|
rescue ZeroDivisionError
|
|
|
|
0
|
|
|
|
end
|
|
|
|
|
|
|
|
def remaining_days
|
|
|
|
return 0 if !due_date || expired?
|
|
|
|
|
|
|
|
(due_date - Date.today).to_i
|
|
|
|
end
|
2016-03-17 20:59:30 +00:00
|
|
|
|
2016-11-15 17:48:30 +00:00
|
|
|
def elapsed_days
|
|
|
|
return 0 if !start_date || start_date.future?
|
|
|
|
|
|
|
|
(Date.today - start_date).to_i
|
|
|
|
end
|
|
|
|
|
2016-11-29 13:47:43 +00:00
|
|
|
def issues_visible_to_user(user)
|
2016-12-16 15:52:27 +00:00
|
|
|
memoize_per_user(user, :issues_visible_to_user) do
|
2017-06-08 19:55:50 +00:00
|
|
|
IssuesFinder.new(user, issues_finder_params)
|
2018-12-20 11:14:33 +00:00
|
|
|
.execute.preload(:assignees).where(milestone_id: milestoneish_id)
|
2016-12-16 15:52:27 +00:00
|
|
|
end
|
2016-03-17 20:59:30 +00:00
|
|
|
end
|
2016-11-15 17:48:30 +00:00
|
|
|
|
2019-01-17 19:41:53 +00:00
|
|
|
def issue_participants_visible_by_user(user)
|
|
|
|
User.joins(:issue_assignees)
|
|
|
|
.where('issue_assignees.issue_id' => issues_visible_to_user(user).select(:id))
|
|
|
|
.distinct
|
|
|
|
end
|
|
|
|
|
|
|
|
def issue_labels_visible_by_user(user)
|
|
|
|
Label.joins(:label_links)
|
|
|
|
.where('label_links.target_id' => issues_visible_to_user(user).select(:id), 'label_links.target_type' => 'Issue')
|
|
|
|
.distinct
|
|
|
|
end
|
|
|
|
|
2017-06-09 18:53:32 +00:00
|
|
|
def sorted_issues(user)
|
2020-01-21 15:08:26 +00:00
|
|
|
# This method is used on milestone view to filter opened assigned, opened unassigned and closed issues columns.
|
|
|
|
# We want a limit of DISPLAY_ISSUES_LIMIT for total issues present on all columns.
|
|
|
|
limited_ids = issues_visible_to_user(user).limit(DISPLAY_ISSUES_LIMIT).select(:id)
|
|
|
|
|
|
|
|
Issue.where(id: limited_ids).preload_associated_models.sort_by_attribute('label_priority')
|
2017-06-09 18:53:32 +00:00
|
|
|
end
|
|
|
|
|
2019-02-11 10:31:30 +00:00
|
|
|
def sorted_merge_requests(user)
|
|
|
|
merge_requests_visible_to_user(user).sort_by_attribute('label_priority')
|
2017-06-09 18:53:32 +00:00
|
|
|
end
|
|
|
|
|
2019-03-05 15:15:22 +00:00
|
|
|
def merge_requests_visible_to_user(user)
|
|
|
|
memoize_per_user(user, :merge_requests_visible_to_user) do
|
|
|
|
MergeRequestsFinder.new(user, issues_finder_params)
|
|
|
|
.execute.where(milestone_id: milestoneish_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-15 17:48:30 +00: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 15:52:27 +00:00
|
|
|
|
2017-08-24 16:41:44 +00:00
|
|
|
def group_milestone?
|
2017-07-07 15:08:49 +00:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2017-08-24 16:37:37 +00:00
|
|
|
def project_milestone?
|
2017-07-07 15:08:49 +00:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2017-08-24 16:31:20 +00:00
|
|
|
def legacy_group_milestone?
|
2017-07-07 15:08:49 +00:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2017-08-24 16:46:42 +00:00
|
|
|
def dashboard_milestone?
|
2017-07-07 15:08:49 +00:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2019-11-07 21:06:14 +00:00
|
|
|
def global_milestone?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2017-11-06 18:18:20 +00:00
|
|
|
def total_issue_time_spent
|
2017-11-10 20:18:42 +00:00
|
|
|
@total_issue_time_spent ||= issues.joins(:timelogs).sum(:time_spent)
|
2017-11-06 18:18:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def human_total_issue_time_spent
|
|
|
|
Gitlab::TimeTrackingFormatter.output(total_issue_time_spent)
|
|
|
|
end
|
|
|
|
|
2018-02-21 17:20:56 +00: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 15:52:27 +00:00
|
|
|
def count_issues_by_state(user)
|
|
|
|
memoize_per_user(user, :count_issues_by_state) do
|
2019-10-18 11:11:44 +00:00
|
|
|
issues_visible_to_user(user).reorder(nil).group(:state_id).count
|
2016-12-16 15:52:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-19 14:43:20 +00:00
|
|
|
private
|
|
|
|
|
2016-12-16 15:52:27 +00:00
|
|
|
def memoize_per_user(user, method_name)
|
2017-11-17 12:27:16 +00:00
|
|
|
memoized_users[method_name][user&.id] ||= yield
|
|
|
|
end
|
|
|
|
|
|
|
|
def memoized_users
|
|
|
|
@memoized_users ||= Hash.new { |h, k| h[k] = {} }
|
2016-12-16 15:52:27 +00:00
|
|
|
end
|
2017-01-06 12:47:18 +00:00
|
|
|
|
|
|
|
# override in a class that includes this module to get a faster query
|
|
|
|
# from IssuesFinder
|
|
|
|
def issues_finder_params
|
2017-06-09 18:53:32 +00:00
|
|
|
{}
|
2017-01-06 12:47:18 +00:00
|
|
|
end
|
2016-03-07 04:07:19 +00:00
|
|
|
end
|