debian-mirror-gitlab/app/helpers/todos_helper.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

280 lines
8.1 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2016-04-02 18:10:28 +05:30
module TodosHelper
def todos_pending_count
2016-09-13 17:45:13 +05:30
@todos_pending_count ||= current_user.todos_pending_count
2016-04-02 18:10:28 +05:30
end
2017-08-17 22:00:37 +05:30
def todos_count_format(count)
2017-09-10 17:25:29 +05:30
count > 99 ? '99+' : count.to_s
2017-08-17 22:00:37 +05:30
end
2016-04-02 18:10:28 +05:30
def todos_done_count
2016-09-13 17:45:13 +05:30
@todos_done_count ||= current_user.todos_done_count
2016-04-02 18:10:28 +05:30
end
def todo_action_name(todo)
case todo.action
2023-01-13 00:05:48 +05:30
when Todo::ASSIGNED then todo.self_added? ? _('assigned') : _('assigned you')
2023-03-04 22:38:38 +05:30
when Todo::REVIEW_REQUESTED then s_('Todos|requested a review')
2023-01-13 00:05:48 +05:30
when Todo::MENTIONED, Todo::DIRECTLY_ADDRESSED then format(
2023-03-04 22:38:38 +05:30
s_("Todos|mentioned %{who}"), who: todo_action_subject(todo)
2023-01-13 00:05:48 +05:30
)
2023-03-04 22:38:38 +05:30
when Todo::BUILD_FAILED then s_('Todos|The pipeline failed')
when Todo::MARKED then s_('Todos|added a to-do item')
2023-01-13 00:05:48 +05:30
when Todo::APPROVAL_REQUIRED then format(
2023-03-04 22:38:38 +05:30
s_("Todos|set %{who} as an approver"), who: todo_action_subject(todo)
2023-01-13 00:05:48 +05:30
)
when Todo::UNMERGEABLE then s_('Todos|Could not merge')
2023-03-04 22:38:38 +05:30
when Todo::MERGE_TRAIN_REMOVED then s_("Todos|Removed from Merge Train")
when Todo::MEMBER_ACCESS_REQUESTED then format(
2023-03-17 16:20:25 +05:30
s_("Todos|has requested access to %{what} %{which}"), what: _(todo.member_access_type), which: _(todo.target.name)
2023-03-04 22:38:38 +05:30
)
2016-04-02 18:10:28 +05:30
end
end
2021-01-03 14:25:43 +05:30
def todo_self_addressing(todo)
case todo.action
2023-01-13 00:05:48 +05:30
when Todo::ASSIGNED then _('to yourself')
when Todo::REVIEW_REQUESTED then _('from yourself')
2021-01-03 14:25:43 +05:30
end
end
2023-03-04 22:38:38 +05:30
def todo_target_name(todo)
return todo.target_reference unless todo.for_commit?
2018-03-17 18:26:18 +05:30
2023-03-04 22:38:38 +05:30
content_tag(:span, todo.target_reference, class: 'commit-sha')
2019-12-04 20:38:33 +05:30
end
def todo_target_title(todo)
2023-03-04 22:38:38 +05:30
# Design To Dos' filenames are displayed in `#todo_target_name` (see `Design#to_reference`),
2020-06-23 00:09:42 +05:30
# so to avoid displaying duplicate filenames in the To Do list for designs,
# we return an empty string here.
2023-03-04 22:38:38 +05:30
return "" if todo.target.blank? || todo.for_design? || todo.member_access_requested?
2020-06-23 00:09:42 +05:30
2023-03-04 22:38:38 +05:30
todo.target.title.to_s
2019-12-04 20:38:33 +05:30
end
def todo_parent_path(todo)
2019-12-21 20:55:43 +05:30
if todo.resource_parent.is_a?(Group)
2023-03-04 22:38:38 +05:30
todo.resource_parent.name
2019-12-04 20:38:33 +05:30
else
2023-03-04 22:38:38 +05:30
title = content_tag(:span, todo.project.name, class: 'project-name')
namespace = content_tag(:span, "#{todo.project.namespace.human_name} / ", class: 'namespace-name')
title.prepend(namespace) if todo.project.namespace
title
2019-12-04 20:38:33 +05:30
end
2016-04-02 18:10:28 +05:30
end
2023-03-04 22:38:38 +05:30
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?
2023-01-13 00:05:48 +05:30
IntegrationsHelper.integration_issue_type(todo.target.issue_type)
2022-08-13 15:12:31 +05:30
else
2023-01-13 00:05:48 +05:30
IntegrationsHelper.integration_todo_target_type(todo.target_type)
2022-08-13 15:12:31 +05:30
end
2023-03-04 22:38:38 +05:30
"#{target_type} #{todo_target_name(todo)}"
2019-10-12 21:52:04 +05:30
end
2016-04-02 18:10:28 +05:30
def todo_target_path(todo)
2016-06-02 11:05:42 +05:30
return unless todo.target.present?
2019-10-12 21:52:04 +05:30
path_options = todo_target_path_options(todo)
2016-04-02 18:10:28 +05:30
2016-06-02 11:05:42 +05:30
if todo.for_commit?
2019-10-12 21:52:04 +05:30
project_commit_path(todo.project, todo.target, path_options)
2020-05-24 23:13:21 +05:30
elsif todo.for_design?
todos_design_path(todo, path_options)
2020-06-23 00:09:42 +05:30
elsif todo.for_alert?
details_project_alert_management_path(todo.project, todo.target)
2022-08-13 15:12:31 +05:30
elsif todo.for_issue_or_work_item?
path_options[:only_path] = true
Gitlab::UrlBuilder.build(todo.target, **path_options)
2023-03-04 22:38:38 +05:30
elsif todo.member_access_requested?
2023-03-17 16:20:25 +05:30
todo.access_request_url(only_path: true)
2016-06-02 11:05:42 +05:30
else
2019-12-21 20:55:43 +05:30
path = [todo.resource_parent, todo.target]
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
path.unshift(:pipelines) if todo.build_failed?
2016-06-02 11:05:42 +05:30
2019-10-12 21:52:04 +05:30
polymorphic_path(path, path_options)
2016-06-02 11:05:42 +05:30
end
2016-04-02 18:10:28 +05:30
end
2019-10-12 21:52:04 +05:30
def todo_target_path_options(todo)
{ anchor: todo_target_path_anchor(todo) }
end
def todo_target_path_anchor(todo)
dom_id(todo.note) if todo.note.present?
end
def todo_target_state_pill(todo)
return unless show_todo_state?(todo)
2022-07-23 23:45:48 +05:30
state = todo.target.state.to_s
2023-01-13 00:05:48 +05:30
raw_state_to_i18n = {
"closed" => _('Closed'),
"merged" => _('Merged'),
"resolved" => _('Resolved')
}
2022-07-23 23:45:48 +05:30
case todo.target
when MergeRequest
2023-01-13 00:05:48 +05:30
case state
when 'closed'
2023-03-04 22:38:38 +05:30
variant = 'danger'
2023-01-13 00:05:48 +05:30
when 'merged'
2023-03-04 22:38:38 +05:30
variant = 'info'
2018-03-17 18:26:18 +05:30
end
2022-07-23 23:45:48 +05:30
when Issue
2023-03-04 22:38:38 +05:30
variant = 'info' if state == 'closed'
2022-07-23 23:45:48 +05:30
when AlertManagement::Alert
2023-03-04 22:38:38 +05:30
variant = 'info' if state == 'resolved'
2022-07-23 23:45:48 +05:30
end
2018-03-17 18:26:18 +05:30
2023-03-04 22:38:38 +05:30
content_tag(:span, class: 'todo-target-state') do
gl_badge_tag(raw_state_to_i18n[state] || state.capitalize, { variant: variant, size: 'sm' })
end
end
2016-04-02 18:10:28 +05:30
def todos_filter_params
{
2022-11-25 23:54:43 +05:30
state: params[:state].presence,
2016-04-02 18:10:28 +05:30
project_id: params[:project_id],
2022-08-27 11:52:29 +05:30
author_id: params[:author_id],
type: params[:type],
action_id: params[:action_id]
2022-11-25 23:54:43 +05:30
}.compact
2016-04-02 18:10:28 +05:30
end
2017-08-17 22:00:37 +05:30
def todos_filter_empty?
todos_filter_params.values.none?
end
2022-10-11 01:57:18 +05:30
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
2016-04-02 18:10:28 +05:30
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
2018-12-05 23:21:45 +05:30
"#{request.path}?#{options.to_param}"
2016-04-02 18:10:28 +05:30
end
def todo_actions_options
2016-09-29 09:46:39 +05:30
[
2022-11-25 23:54:43 +05:30
{ 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') },
2023-03-04 22:38:38 +05:30
{ id: Todo::BUILD_FAILED, text: s_('Todos|Pipelines') },
{ id: Todo::MEMBER_ACCESS_REQUESTED, text: s_('Todos|Member access requested') }
2016-04-02 18:10:28 +05:30
]
end
def todo_types_options
2016-09-29 09:46:39 +05:30
[
2022-11-25 23:54:43 +05:30
{ 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') }
2016-04-02 18:10:28 +05:30
]
2016-09-29 09:46:39 +05:30
end
def todo_actions_dropdown_label(selected_action_id, default_action)
2022-08-27 11:52:29 +05:30
selected_action = todo_actions_options.find { |action| action[:id] == selected_action_id.to_i }
2016-09-29 09:46:39 +05:30
selected_action ? selected_action[:text] : default_action
end
2016-04-02 18:10:28 +05:30
2016-09-29 09:46:39 +05:30
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
2016-04-02 18:10:28 +05:30
end
2016-11-03 12:29:30 +05:30
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
2018-12-05 23:21:45 +05:30
content = content_tag(:span, class: css_class) do
2023-03-04 22:38:38 +05:30
format(s_("Todos|Due %{due_date}"), due_date: if is_due_today
_("today")
else
l(todo.target.due_date,
format: Date::DATE_FORMATS[:medium])
end)
2016-11-03 12:29:30 +05:30
end
2018-12-05 23:21:45 +05:30
2023-03-04 22:38:38 +05:30
"#{content} ·".html_safe
2016-11-03 12:29:30 +05:30
end
2020-07-28 23:09:34 +05:30
def todo_author_display?(todo)
!todo.build_failed? && !todo.unmergeable?
end
private
2020-05-24 23:13:21 +05:30
def todos_design_path(todo, path_options)
design = todo.target
designs_project_issue_path(
todo.resource_parent,
design.issue,
path_options.merge(
vueroute: design.filename
)
)
end
2017-08-17 22:00:37 +05:30
def todo_action_subject(todo)
2023-01-13 00:05:48 +05:30
todo.self_added? ? s_('Todos|yourself') : _('you')
2017-08-17 22:00:37 +05:30
end
def show_todo_state?(todo)
2020-07-28 23:09:34 +05:30
case todo.target
when MergeRequest, Issue
%w(closed merged).include?(todo.target.state)
when AlertManagement::Alert
%i(resolved).include?(todo.target.state)
else
false
end
end
2016-04-02 18:10:28 +05:30
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
TodosHelper.prepend_mod_with('TodosHelper')