Module: TodosHelper

Defined in:
app/helpers/todos_helper.rb

Instance Method Summary collapse

Instance Method Details

#no_todos_messagesObject



166
167
168
169
170
171
172
173
174
# File 'app/helpers/todos_helper.rb', line 166

def no_todos_messages
  [
    s_('Todos|Good job! Looks like you don\'t have anything left on your To-Do List'),
    s_('Todos|Isn\'t an empty To-Do List beautiful?'),
    s_('Todos|Give yourself a pat on the back!'),
    s_('Todos|Nothing left to do. High five!'),
    s_('Todos|Henceforth, you shall be known as "To-Do Destroyer"')
  ]
end

#todo_action_name(todo) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/todos_helper.rb', line 16

def todo_action_name(todo)
  case todo.action
  when Todo::ASSIGNED then todo.self_added? ? _('assigned') : _('assigned you')
  when Todo::REVIEW_REQUESTED then s_('Todos|requested a review')
  when Todo::MENTIONED, Todo::DIRECTLY_ADDRESSED then format(
    s_("Todos|mentioned %{who}"), who: todo_action_subject(todo)
  )
  when Todo::BUILD_FAILED then s_('Todos|The pipeline failed')
  when Todo::MARKED then s_('Todos|added a to-do item')
  when Todo::APPROVAL_REQUIRED then format(
    s_("Todos|set %{who} as an approver"), who: todo_action_subject(todo)
  )
  when Todo::UNMERGEABLE then s_('Todos|Could not merge')
  when Todo::MERGE_TRAIN_REMOVED then s_("Todos|Removed from Merge Train")
  when Todo::MEMBER_ACCESS_REQUESTED then format(
    s_("Todos|has requested access to %{what} %{which}"), what: _(todo.member_access_type), which: _(todo.target.name)
  )
  when Todo::REVIEW_SUBMITTED then s_('Todos|reviewed your merge request')
  end
end

#todo_actions_dropdown_label(selected_action_id, default_action) ⇒ Object



212
213
214
215
# File 'app/helpers/todos_helper.rb', line 212

def todo_actions_dropdown_label(selected_action_id, default_action)
  selected_action = todo_actions_options.find { |action| action[:id] == selected_action_id.to_i }
  selected_action ? selected_action[:text] : default_action
end

#todo_actions_optionsObject



190
191
192
193
194
195
196
197
198
199
200
# File 'app/helpers/todos_helper.rb', line 190

def todo_actions_options
  [
    { id: '', text: s_('Todos|Any Action') },
    { id: Todo::ASSIGNED, text: s_('Todos|Assigned') },
    { id: Todo::REVIEW_REQUESTED, text: s_('Todos|Review requested') },
    { id: Todo::MENTIONED, text: s_('Todos|Mentioned') },
    { id: Todo::MARKED, text: s_('Todos|Added') },
    { id: Todo::BUILD_FAILED, text: s_('Todos|Pipelines') },
    { id: Todo::MEMBER_ACCESS_REQUESTED, text: s_('Todos|Member access requested') }
  ]
end

#todo_author_display?(todo) ⇒ Boolean

Returns:

  • (Boolean)


250
251
252
# File 'app/helpers/todos_helper.rb', line 250

def todo_author_display?(todo)
  !todo.build_failed? && !todo.unmergeable?
end

#todo_due_date(todo) ⇒ Object



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'app/helpers/todos_helper.rb', line 222

def todo_due_date(todo)
  return unless todo.target.try(:due_date)

  is_due_today = todo.target.due_date.today?
  is_overdue = todo.target.overdue?
  css_class =
    if is_due_today
      'text-warning'
    elsif is_overdue
      'text-danger'
    else
      ''
    end

  due_date =
    if is_due_today
      _("today")
    else
      l(todo.target.due_date, format: Date::DATE_FORMATS[:medium])
    end

  content = (:span, class: css_class) do
    format(s_("Todos|Due %{due_date}"), due_date: due_date)
  end

  "#{content} ·".html_safe
end

#todo_parent_path(todo) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/helpers/todos_helper.rb', line 59

def todo_parent_path(todo)
  if todo.resource_parent.is_a?(Group)
    todo.resource_parent.name
  else
    title = (:span, todo.project.name, class: 'project-name')
    namespace = (:span, "#{todo.project.namespace.human_name} / ", class: 'namespace-name')

    title.prepend(namespace) if todo.project.namespace

    title
  end
end

#todo_self_addressing(todo) ⇒ Object



37
38
39
40
41
42
# File 'app/helpers/todos_helper.rb', line 37

def todo_self_addressing(todo)
  case todo.action
  when Todo::ASSIGNED then _('to yourself')
  when Todo::REVIEW_REQUESTED then _('from yourself')
  end
end

#todo_target_aria_label(todo) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/helpers/todos_helper.rb', line 72

def todo_target_aria_label(todo)
  target_type = if todo.for_design?
                  _('Design')
                elsif todo.for_alert?
                  _('Alert')
                elsif todo.member_access_requested?
                  _('Group')
                elsif todo.for_issue_or_work_item?
                  IntegrationsHelper.integration_issue_type(todo.target.issue_type)
                else
                  IntegrationsHelper.integration_todo_target_type(todo.target_type)
                end

  "#{target_type} #{todo_target_name(todo)}"
end

#todo_target_name(todo) ⇒ Object



44
45
46
47
48
# File 'app/helpers/todos_helper.rb', line 44

def todo_target_name(todo)
  return todo.target_reference unless todo.for_commit?

  (:span, todo.target_reference, class: 'commit-sha')
end

#todo_target_path(todo) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/helpers/todos_helper.rb', line 88

def todo_target_path(todo)
  return unless todo.target.present?

  path_options = todo_target_path_options(todo)

  if todo.for_commit?
    project_commit_path(todo.project, todo.target, path_options)
  elsif todo.for_design?
    todos_design_path(todo, path_options)
  elsif todo.for_alert?
    details_project_alert_management_path(todo.project, todo.target)
  elsif todo.for_issue_or_work_item?
    path_options[:only_path] = true
    Gitlab::UrlBuilder.build(todo.target, **path_options)
  elsif todo.member_access_requested?
    todo.access_request_url(only_path: true)
  else
    path = [todo.resource_parent, todo.target]

    path.unshift(:pipelines) if todo.build_failed?

    polymorphic_path(path, path_options)
  end
end

#todo_target_path_anchor(todo) ⇒ Object



117
118
119
# File 'app/helpers/todos_helper.rb', line 117

def todo_target_path_anchor(todo)
  dom_id(todo.note) if todo.note.present?
end

#todo_target_path_options(todo) ⇒ Object



113
114
115
# File 'app/helpers/todos_helper.rb', line 113

def todo_target_path_options(todo)
  { anchor: todo_target_path_anchor(todo) }
end

#todo_target_state_pill(todo) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'app/helpers/todos_helper.rb', line 121

def todo_target_state_pill(todo)
  return unless show_todo_state?(todo)

  state = todo.target.state.to_s
  raw_state_to_i18n = {
    "closed" => _('Closed'),
    "merged" => _('Merged'),
    "resolved" => _('Resolved')
  }

  case todo.target
  when MergeRequest
    case state
    when 'closed'
      variant = 'danger'
    when 'merged'
      variant = 'info'
    end
  when Issue
    variant = 'info' if state == 'closed'
  when AlertManagement::Alert
    variant = 'info' if state == 'resolved'
  else
    variant = 'info'
  end

  (:span, class: 'todo-target-state') do
    gl_badge_tag(raw_state_to_i18n[state] || state.capitalize, { variant: variant, size: 'sm' })
  end
end

#todo_target_title(todo) ⇒ Object



50
51
52
53
54
55
56
57
# File 'app/helpers/todos_helper.rb', line 50

def todo_target_title(todo)
  # Design To Dos' filenames are displayed in `#todo_target_name` (see `Design#to_reference`),
  # so to avoid displaying duplicate filenames in the To Do list for designs,
  # we return an empty string here.
  return "" if todo.target.blank? || todo.for_design? || todo.member_access_requested?

  todo.target.title.to_s
end

#todo_types_dropdown_label(selected_type, default_type) ⇒ Object



217
218
219
220
# File 'app/helpers/todos_helper.rb', line 217

def todo_types_dropdown_label(selected_type, default_type)
  selected_type = todo_types_options.find { |type| type[:id] == selected_type && type[:id] != '' }
  selected_type ? selected_type[:text] : default_type
end

#todo_types_optionsObject



202
203
204
205
206
207
208
209
210
# File 'app/helpers/todos_helper.rb', line 202

def todo_types_options
  [
    { id: '', text: s_('Todos|Any Type') },
    { id: 'Issue', text: s_('Todos|Issue') },
    { id: 'MergeRequest', text: s_('Todos|Merge request') },
    { id: 'DesignManagement::Design', text: s_('Todos|Design') },
    { id: 'AlertManagement::Alert', text: s_('Todos|Alert') }
  ]
end

#todos_count_format(count) ⇒ Object



8
9
10
# File 'app/helpers/todos_helper.rb', line 8

def todos_count_format(count)
  count > 99 ? '99+' : count.to_s
end

#todos_done_countObject



12
13
14
# File 'app/helpers/todos_helper.rb', line 12

def todos_done_count
  @todos_done_count ||= current_user.todos_done_count
end

#todos_filter_empty?Boolean

Returns:

  • (Boolean)


162
163
164
# File 'app/helpers/todos_helper.rb', line 162

def todos_filter_empty?
  todos_filter_params.values.none?
end

#todos_filter_paramsObject



152
153
154
155
156
157
158
159
160
# File 'app/helpers/todos_helper.rb', line 152

def todos_filter_params
  {
    state: params[:state].presence,
    project_id: params[:project_id],
    author_id: params[:author_id],
    type: params[:type],
    action_id: params[:action_id]
  }.compact
end

#todos_filter_path(options = {}) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'app/helpers/todos_helper.rb', line 176

def todos_filter_path(options = {})
  without = options.delete(:without)

  options = todos_filter_params.merge(options)

  if without.present?
    without.each do |key|
      options.delete(key)
    end
  end

  "#{request.path}?#{options.to_param}"
end

#todos_pending_countObject



4
5
6
# File 'app/helpers/todos_helper.rb', line 4

def todos_pending_count
  @todos_pending_count ||= current_user.todos_pending_count
end