2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
module Milestoneish
|
2021-04-29 21:17:54 +05:30
|
|
|
DISPLAY_ISSUES_LIMIT = 500
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
def total_issues_count
|
|
|
|
@total_issues_count ||= Milestones::IssuesCountService.new(self).count
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
def closed_issues_count
|
|
|
|
@close_issues_count ||= Milestones::ClosedIssuesCountService.new(self).count
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
def opened_issues_count
|
|
|
|
total_issues_count - closed_issues_count
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
def total_merge_requests_count
|
|
|
|
@total_merge_request_count ||= Milestones::MergeRequestsCountService.new(self).count
|
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
def complete?
|
|
|
|
total_issues_count > 0 && total_issues_count == closed_issues_count
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
def percent_complete
|
|
|
|
closed_issues_count * 100 / total_issues_count
|
2016-06-02 11:05:42 +05:30
|
|
|
rescue ZeroDivisionError
|
|
|
|
0
|
|
|
|
end
|
|
|
|
|
|
|
|
def remaining_days
|
|
|
|
return 0 if !due_date || expired?
|
|
|
|
|
|
|
|
(due_date - Date.today).to_i
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def elapsed_days
|
|
|
|
return 0 if !start_date || start_date.future?
|
|
|
|
|
|
|
|
(Date.today - start_date).to_i
|
|
|
|
end
|
|
|
|
|
2017-01-15 13:20:01 +05:30
|
|
|
def issues_visible_to_user(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
memoize_per_user(user, :issues_visible_to_user) do
|
|
|
|
IssuesFinder.new(user, issues_finder_params)
|
2019-02-15 15:39:39 +05:30
|
|
|
.execute.preload(:assignees).where(milestone_id: milestoneish_id)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-13 22:55:13 +05:30
|
|
|
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-09-10 17:25:29 +05:30
|
|
|
def sorted_issues(user)
|
2020-04-22 19:07:51 +05:30
|
|
|
# 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).sort_by_attribute('label_priority').limit(DISPLAY_ISSUES_LIMIT)
|
|
|
|
|
|
|
|
Issue
|
|
|
|
.where(id: Issue.select(:id).from(limited_ids))
|
|
|
|
.preload_associated_models
|
|
|
|
.sort_by_attribute('label_priority')
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2019-03-13 22:55:13 +05:30
|
|
|
def sorted_merge_requests(user)
|
|
|
|
merge_requests_visible_to_user(user).sort_by_attribute('label_priority')
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
def expired
|
|
|
|
expired? || false
|
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
def total_time_spent
|
|
|
|
@total_time_spent ||= issues.joins(:timelogs).sum(:time_spent) + merge_requests.joins(:timelogs).sum(:time_spent)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
def human_total_time_spent
|
|
|
|
Gitlab::TimeTrackingFormatter.output(total_time_spent)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
def total_time_estimate
|
|
|
|
@total_time_estimate ||= issues.sum(:time_estimate) + merge_requests.sum(:time_estimate)
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
def human_total_time_estimate
|
|
|
|
Gitlab::TimeTrackingFormatter.output(total_time_estimate)
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
private
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def memoize_per_user(user, method_name)
|
2018-03-17 18:26:18 +05:30
|
|
|
memoized_users[method_name][user&.id] ||= yield
|
|
|
|
end
|
|
|
|
|
|
|
|
def memoized_users
|
|
|
|
@memoized_users ||= Hash.new { |h, k| h[k] = {} }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
# override in a class that includes this module to get a faster query
|
|
|
|
# from IssuesFinder
|
|
|
|
def issues_finder_params
|
|
|
|
{}
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|