2016-03-07 04:07:19 +00:00
|
|
|
module Milestoneish
|
2016-11-29 13:47:43 +00:00
|
|
|
def closed_items_count(user)
|
2016-03-17 20:59:30 +00:00
|
|
|
issues_visible_to_user(user).closed.size + merge_requests.closed_and_merged.size
|
2016-03-07 04:07:19 +00:00
|
|
|
end
|
|
|
|
|
2016-11-29 13:47:43 +00:00
|
|
|
def total_items_count(user)
|
2016-03-17 20:59:30 +00:00
|
|
|
issues_visible_to_user(user).size + merge_requests.size
|
2016-03-07 04:07:19 +00:00
|
|
|
end
|
|
|
|
|
2016-11-29 13:47:43 +00:00
|
|
|
def complete?(user)
|
2016-04-26 11:22:52 +00:00
|
|
|
total_items_count(user) > 0 && total_items_count(user) == closed_items_count(user)
|
2016-03-07 04:07:19 +00:00
|
|
|
end
|
|
|
|
|
2016-11-29 13:47:43 +00:00
|
|
|
def percent_complete(user)
|
2016-03-17 20:59:30 +00:00
|
|
|
((closed_items_count(user) * 100) / total_items_count(user)).abs
|
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-12 08:43:56 +00:00
|
|
|
IssuesFinder.new(user).execute.where(id: issues)
|
2016-03-17 20:59:30 +00:00
|
|
|
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-03-07 04:07:19 +00:00
|
|
|
end
|