Module: Milestoneish

Included in:
Milestone
Defined in:
app/models/concerns/milestoneish.rb

Constant Summary collapse

DISPLAY_ISSUES_LIMIT =
3000

Instance Method Summary collapse

Instance Method Details

#closed_issues_countObject


10
11
12
# File 'app/models/concerns/milestoneish.rb', line 10

def closed_issues_count
  @close_issues_count ||= Milestones::ClosedIssuesCountService.new(self).count
end

#complete?Boolean

Returns:

  • (Boolean)

18
19
20
# File 'app/models/concerns/milestoneish.rb', line 18

def complete?
  total_issues_count > 0 && total_issues_count == closed_issues_count
end

#elapsed_daysObject


34
35
36
37
38
# File 'app/models/concerns/milestoneish.rb', line 34

def elapsed_days
  return 0 if !start_date || start_date.future?

  (Date.today - start_date).to_i
end

#expired?Boolean

Returns:

  • (Boolean)

96
97
98
# File 'app/models/concerns/milestoneish.rb', line 96

def expired?
  due_date && due_date.past?
end

#expires_atObject


86
87
88
89
90
91
92
93
94
# File 'app/models/concerns/milestoneish.rb', line 86

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

#human_total_time_estimateObject


112
113
114
# File 'app/models/concerns/milestoneish.rb', line 112

def human_total_time_estimate
  Gitlab::TimeTrackingFormatter.output(total_time_estimate)
end

#human_total_time_spentObject


104
105
106
# File 'app/models/concerns/milestoneish.rb', line 104

def human_total_time_spent
  Gitlab::TimeTrackingFormatter.output(total_time_spent)
end

#issue_labels_visible_by_user(user) ⇒ Object


53
54
55
56
57
# File 'app/models/concerns/milestoneish.rb', line 53

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

#issue_participants_visible_by_user(user) ⇒ Object


47
48
49
50
51
# File 'app/models/concerns/milestoneish.rb', line 47

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

#issues_visible_to_user(user) ⇒ Object


40
41
42
43
44
45
# File 'app/models/concerns/milestoneish.rb', line 40

def issues_visible_to_user(user)
  memoize_per_user(user, :issues_visible_to_user) do
    IssuesFinder.new(user, issues_finder_params)
      .execute.preload(:assignees).where(milestone_id: milestoneish_id)
  end
end

#merge_requests_visible_to_user(user) ⇒ Object


75
76
77
78
79
80
# File 'app/models/concerns/milestoneish.rb', line 75

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

#opened_issues_countObject


14
15
16
# File 'app/models/concerns/milestoneish.rb', line 14

def opened_issues_count
  total_issues_count - closed_issues_count
end

#percent_completeObject


22
23
24
25
26
# File 'app/models/concerns/milestoneish.rb', line 22

def percent_complete
  closed_issues_count * 100 / total_issues_count
rescue ZeroDivisionError
  0
end

#remaining_daysObject


28
29
30
31
32
# File 'app/models/concerns/milestoneish.rb', line 28

def remaining_days
  return 0 if !due_date || expired?

  (due_date - Date.today).to_i
end

#sorted_issues(user) ⇒ Object


59
60
61
62
63
64
65
66
67
68
69
# File 'app/models/concerns/milestoneish.rb', line 59

def sorted_issues(user)
  # 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')
end

#sorted_merge_requests(user) ⇒ Object


71
72
73
# File 'app/models/concerns/milestoneish.rb', line 71

def sorted_merge_requests(user)
  merge_requests_visible_to_user(user).sort_by_attribute('label_priority')
end

#total_issues_countObject


6
7
8
# File 'app/models/concerns/milestoneish.rb', line 6

def total_issues_count
  @total_issues_count ||= Milestones::IssuesCountService.new(self).count
end

#total_time_estimateObject


108
109
110
# File 'app/models/concerns/milestoneish.rb', line 108

def total_time_estimate
  @total_time_estimate ||= issues.sum(:time_estimate) + merge_requests.sum(:time_estimate)
end

#total_time_spentObject


100
101
102
# File 'app/models/concerns/milestoneish.rb', line 100

def total_time_spent
  @total_time_spent ||= issues.joins(:timelogs).sum(:time_spent) + merge_requests.joins(:timelogs).sum(:time_spent)
end

#upcoming?Boolean

Returns:

  • (Boolean)

82
83
84
# File 'app/models/concerns/milestoneish.rb', line 82

def upcoming?
  start_date && start_date.future?
end