Module: TimeboxesHelper

Includes:
EntityDateHelper, Gitlab::Utils::StrongMemoize
Defined in:
app/helpers/timeboxes_helper.rb

Instance Method Summary collapse

Methods included from EntityDateHelper

#distance_of_time_as_hash, #interval_in_words, #remaining_days_in_words

Instance Method Details

#can_admin_group_milestones?Boolean

Returns:

  • (Boolean)


283
284
285
286
287
# File 'app/helpers/timeboxes_helper.rb', line 283

def can_admin_group_milestones?
  strong_memoize(:can_admin_group_milestones) do
    can?(current_user, :admin_milestone, @project.group)
  end
end

#can_admin_project_milestones?Boolean

Returns:

  • (Boolean)


277
278
279
280
281
# File 'app/helpers/timeboxes_helper.rb', line 277

def can_admin_project_milestones?
  strong_memoize(:can_admin_project_milestones) do
    can?(current_user, :admin_milestone, @project)
  end
end

#display_issues_count_warning?(milestone) ⇒ Boolean

Returns:

  • (Boolean)


289
290
291
# File 'app/helpers/timeboxes_helper.rb', line 289

def display_issues_count_warning?(milestone)
  milestone_visible_issues_count(milestone) > Milestone::DISPLAY_ISSUES_LIMIT
end

#edit_milestone_path(milestone) ⇒ Object



269
270
271
272
273
274
275
# File 'app/helpers/timeboxes_helper.rb', line 269

def edit_milestone_path(milestone)
  if milestone.group_milestone?
    edit_group_milestone_path(milestone.group, milestone)
  elsif milestone.project_milestone?
    edit_project_milestone_path(milestone.project, milestone)
  end
end

#group_milestone_route(milestone, params = {}) ⇒ Object



252
253
254
255
256
# File 'app/helpers/timeboxes_helper.rb', line 252

def group_milestone_route(milestone, params = {})
  params = nil if params.empty?

  group_milestone_path(milestone.group, milestone.iid, milestone: params)
end

#group_or_project_milestone_path(milestone) ⇒ Object



258
259
260
261
262
263
264
265
266
267
# File 'app/helpers/timeboxes_helper.rb', line 258

def group_or_project_milestone_path(milestone)
  params =
    if milestone.group_milestone?
      { milestone: { title: milestone.title } }
    else
      { title: milestone.title }
    end

  milestone_path(milestone.milestone, params)
end

#milestone_badge_variant(milestone) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/timeboxes_helper.rb', line 19

def milestone_badge_variant(milestone)
  if milestone.closed?
    :info
  elsif milestone.expired?
    :warning
  elsif milestone.upcoming?
    :neutral
  else
    :success
  end
end

#milestone_issues_by_label_count(milestone, label, state:) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/helpers/timeboxes_helper.rb', line 63

def milestone_issues_by_label_count(milestone, label, state:)
  issues = milestone.issues.with_label(label.title)
  issues =
    case state
    when :opened
      issues.opened
    when :closed
      issues.closed
    else
      raise ArgumentError, _("invalid milestone state `%{state}`") % { state: state }
    end

  issues.size
end

#milestone_issues_count_message(milestone) ⇒ Object



293
294
295
296
297
298
299
300
301
302
# File 'app/helpers/timeboxes_helper.rb', line 293

def milestone_issues_count_message(milestone)
  total_count = milestone_visible_issues_count(milestone)
  limit = Milestone::DISPLAY_ISSUES_LIMIT
  link_options = { milestone_title: @milestone.title }

  message = _('Showing %{limit} of %{total_count} issues. ') % { limit: limit, total_count: total_count }
  message += link_to(_('View all issues'), milestones_issues_path(link_options))

  message.html_safe
end

#milestone_issues_tooltip_text(milestone) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/helpers/timeboxes_helper.rb', line 122

def milestone_issues_tooltip_text(milestone)
  total = milestone.total_issues_count
  opened = milestone.opened_issues_count
  closed = milestone.closed_issues_count

  return _("Issues") if total == 0

  content = []

  content << (n_("1 open issue", "%{issues} open issues", opened) % { issues: opened }) if opened > 0

  content << (n_("1 closed issue", "%{issues} closed issues", closed) % { issues: closed }) if closed > 0

  content.join('<br />').html_safe
end

#milestone_merge_requests_tooltip_text(milestone) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'app/helpers/timeboxes_helper.rb', line 138

def milestone_merge_requests_tooltip_text(milestone)
  merge_requests = milestone.merge_requests

  return _("Merge requests") if merge_requests.empty?

  content = []

  if merge_requests.opened.any?
    content << (
      n_(
        "1 open merge request", "%{merge_requests} open merge requests",
        merge_requests.opened.count
      ) % { merge_requests: merge_requests.opened.count }
    )
  end

  if merge_requests.closed.any?
    content << (
      n_(
        "1 closed merge request", "%{merge_requests} closed merge requests",
        merge_requests.closed.count
      ) % { merge_requests: merge_requests.closed.count }
    )
  end

  if merge_requests.merged.any?
    content << (
      n_(
        "1 merged merge request", "%{merge_requests} merged merge requests",
        merge_requests.merged.count
      ) % { merge_requests: merge_requests.merged.count }
    )
  end

  content.join('<br />').html_safe
end

#milestone_progress_bar(milestone) ⇒ Object



91
92
93
94
95
96
# File 'app/helpers/timeboxes_helper.rb', line 91

def milestone_progress_bar(milestone)
  render Pajamas::ProgressComponent.new(
    value: milestone.percent_complete,
    variant: :primary
  )
end

#milestone_progress_tooltip_text(milestone) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/helpers/timeboxes_helper.rb', line 78

def milestone_progress_tooltip_text(milestone)
  has_issues = milestone.total_issues_count > 0

  if has_issues
    [
      _('Progress'),
      _("%{percent}%% complete") % { percent: milestone.percent_complete }
    ].join('<br />')
  else
    _('Progress')
  end
end

#milestone_releases_tooltip_list(releases, more_count = 0) ⇒ Object



192
193
194
195
196
# File 'app/helpers/timeboxes_helper.rb', line 192

def milestone_releases_tooltip_list(releases, more_count = 0)
  list = releases.map(&:name).join(", ")
  list += format(_(", and %{number} more"), number: more_count) if more_count > 0
  list
end

#milestone_releases_tooltip_text(milestone) ⇒ Object



175
176
177
178
179
180
181
# File 'app/helpers/timeboxes_helper.rb', line 175

def milestone_releases_tooltip_text(milestone)
  count = milestone.releases.count

  return _("Releases") if count == 0

  n_("%{releases} release", "%{releases} releases", count) % { releases: count }
end

#milestone_status_string(milestone) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/timeboxes_helper.rb', line 7

def milestone_status_string(milestone)
  if milestone.closed?
    _('Closed')
  elsif milestone.expired?
    _('Expired')
  elsif milestone.upcoming?
    _('Upcoming')
  else
    _('Open')
  end
end

#milestone_tab_path(milestone, tab, params = {}) ⇒ Object



240
241
242
# File 'app/helpers/timeboxes_helper.rb', line 240

def milestone_tab_path(milestone, tab, params = {})
  url_for(params.merge(action: tab, format: :json))
end

#milestone_time_for(date, date_type) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/helpers/timeboxes_helper.rb', line 98

def milestone_time_for(date, date_type)
  title = date_type == :start ? "Start date" : "End date"

  if date
    time_ago = time_ago_in_words(date).sub("about ", "")
    state = if date.past?
              "ago"
            else
              "remaining"
            end

    content = [
      title,
      "<br />",
      date.to_fs(:medium),
      "(#{time_ago} #{state})"
    ].join(" ")

    content.html_safe
  else
    title
  end
end

#milestone_tooltip_due_date(milestone) ⇒ Object



198
199
200
201
202
203
204
# File 'app/helpers/timeboxes_helper.rb', line 198

def milestone_tooltip_due_date(milestone)
  if milestone.due_date
    "#{milestone.due_date.to_fs(:medium)} (#{remaining_days_in_words(milestone.due_date, milestone.start_date)})"
  else
    _('Milestone')
  end
end

#milestones_browse_issuables_path(milestone, type:, state: nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/timeboxes_helper.rb', line 51

def milestones_browse_issuables_path(milestone, type:, state: nil)
  opts = { milestone_title: milestone.title, state: state }

  if @project
    polymorphic_path([@project, type], opts)
  elsif @group
    polymorphic_url([type, @group], opts)
  else
    polymorphic_url([type, :dashboard], opts)
  end
end

#milestones_filter_path(opts = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'app/helpers/timeboxes_helper.rb', line 31

def milestones_filter_path(opts = {})
  if @project
    project_milestones_path(@project, opts)
  elsif @group
    group_milestones_path(@group, opts)
  else
    dashboard_milestones_path(opts)
  end
end

#milestones_issues_path(opts = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'app/helpers/timeboxes_helper.rb', line 41

def milestones_issues_path(opts = {})
  if @project
    project_issues_path(@project, opts)
  elsif @group
    issues_group_path(@group, opts)
  else
    issues_dashboard_path(opts)
  end
end

#recent_releases_with_counts(milestone, user) ⇒ Object



183
184
185
186
187
188
189
190
# File 'app/helpers/timeboxes_helper.rb', line 183

def recent_releases_with_counts(milestone, user)
  total_count = milestone.releases.size
  return [[], 0, 0] if total_count == 0

  recent_releases = milestone.releases.recent.filter { |release| Ability.allowed?(user, :read_release, release) }
  more_count = total_count - recent_releases.size
  [recent_releases, total_count, more_count]
end

#timebox_date_range(timebox) ⇒ Object Also known as: milestone_date_range



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'app/helpers/timeboxes_helper.rb', line 206

def timebox_date_range(timebox)
  if timebox.start_date && timebox.due_date
    s_("DateRange|%{start_date}–%{end_date}") % {
      start_date: l(timebox.start_date, format: Date::DATE_FORMATS[:medium]),
      end_date: l(timebox.due_date, format: Date::DATE_FORMATS[:medium])
    }
  elsif timebox.due_date
    if timebox.due_date.past?
      _("expired on %{timebox_due_date}") % {
        timebox_due_date: l(timebox.due_date,
          format: Date::DATE_FORMATS[:medium])
      }
    else
      _("expires on %{timebox_due_date}") % {
        timebox_due_date: l(timebox.due_date,
          format: Date::DATE_FORMATS[:medium])
      }
    end
  elsif timebox.start_date
    if timebox.start_date.past?
      _("started on %{timebox_start_date}") % {
        timebox_start_date: l(timebox.start_date,
          format: Date::DATE_FORMATS[:medium])
      }
    else
      _("starts on %{timebox_start_date}") % {
        timebox_start_date: l(timebox.start_date,
          format: Date::DATE_FORMATS[:medium])
      }
    end
  end
end

#update_milestone_path(milestone, params = {}) ⇒ Object



244
245
246
247
248
249
250
# File 'app/helpers/timeboxes_helper.rb', line 244

def update_milestone_path(milestone, params = {})
  if milestone.project_milestone?
    project_milestone_path(milestone.project, milestone, milestone: params)
  else
    group_milestone_route(milestone, params)
  end
end