2016-06-02 11:05:42 +05:30
|
|
|
module Milestoneish
|
2017-01-15 13:20:01 +05:30
|
|
|
def closed_items_count(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
memoize_per_user(user, :closed_items_count) do
|
|
|
|
(count_issues_by_state(user)['closed'] || 0) + merge_requests.closed_and_merged.size
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2017-01-15 13:20:01 +05:30
|
|
|
def total_items_count(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
memoize_per_user(user, :total_items_count) do
|
|
|
|
total_issues_count(user) + merge_requests.size
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def total_issues_count(user)
|
|
|
|
count_issues_by_state(user).values.sum
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2017-01-15 13:20:01 +05:30
|
|
|
def complete?(user)
|
2016-06-02 11:05:42 +05:30
|
|
|
total_items_count(user) > 0 && total_items_count(user) == closed_items_count(user)
|
|
|
|
end
|
|
|
|
|
2017-01-15 13:20:01 +05:30
|
|
|
def percent_complete(user)
|
2016-06-02 11:05:42 +05:30
|
|
|
((closed_items_count(user) * 100) / total_items_count(user)).abs
|
|
|
|
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)
|
2017-09-10 17:25:29 +05:30
|
|
|
.execute.preload(:assignees).where(milestone_id: milestoneish_ids)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def sorted_issues(user)
|
2018-05-09 12:01:36 +05:30
|
|
|
issues_visible_to_user(user).preload_associations.sort_by_attribute('label_priority')
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def sorted_merge_requests
|
2018-05-09 12:01:36 +05:30
|
|
|
merge_requests.sort_by_attribute('label_priority')
|
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
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def group_milestone?
|
2017-09-10 17:25:29 +05:30
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def project_milestone?
|
2017-09-10 17:25:29 +05:30
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def legacy_group_milestone?
|
2017-09-10 17:25:29 +05:30
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def dashboard_milestone?
|
2017-09-10 17:25:29 +05:30
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
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
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def count_issues_by_state(user)
|
|
|
|
memoize_per_user(user, :count_issues_by_state) do
|
|
|
|
issues_visible_to_user(user).reorder(nil).group(:state).count
|
|
|
|
end
|
|
|
|
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
|