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
|
2017-08-17 22:00:37 +05:30
|
|
|
when Todo::ASSIGNED then todo.self_added? ? 'assigned' : 'assigned you'
|
2021-01-03 14:25:43 +05:30
|
|
|
when Todo::REVIEW_REQUESTED then 'requested a review of'
|
2022-07-16 23:28:13 +05:30
|
|
|
when Todo::MENTIONED, Todo::DIRECTLY_ADDRESSED then "mentioned #{todo_action_subject(todo)} on"
|
2022-05-07 20:08:51 +05:30
|
|
|
when Todo::BUILD_FAILED then 'The pipeline failed in'
|
2016-06-22 15:30:34 +05:30
|
|
|
when Todo::MARKED then 'added a todo for'
|
2017-08-17 22:00:37 +05:30
|
|
|
when Todo::APPROVAL_REQUIRED then "set #{todo_action_subject(todo)} as an approver for"
|
|
|
|
when Todo::UNMERGEABLE then 'Could not merge'
|
2020-07-28 23:09:34 +05:30
|
|
|
when Todo::MERGE_TRAIN_REMOVED then "Removed from Merge Train:"
|
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
|
|
|
|
when Todo::ASSIGNED then 'to yourself'
|
|
|
|
when Todo::REVIEW_REQUESTED then 'from yourself'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
def todo_target_link(todo)
|
2019-10-12 21:52:04 +05:30
|
|
|
text = raw(todo_target_type_name(todo) + ' ') +
|
2017-09-10 17:25:29 +05:30
|
|
|
if todo.for_commit?
|
|
|
|
content_tag(:span, todo.target_reference, class: 'commit-sha')
|
|
|
|
else
|
|
|
|
todo.target_reference
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
link_to text, todo_target_path(todo)
|
|
|
|
end
|
|
|
|
|
|
|
|
def todo_target_title(todo)
|
2020-06-23 00:09:42 +05:30
|
|
|
# Design To Dos' filenames are displayed in `#todo_target_link` (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.target.title}\""
|
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)
|
|
|
|
link_to todo.resource_parent.name, group_path(todo.resource_parent)
|
2019-12-04 20:38:33 +05:30
|
|
|
else
|
|
|
|
link_to_project(todo.project)
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
def todo_target_type_name(todo)
|
2020-05-24 23:13:21 +05:30
|
|
|
return _('design') if todo.for_design?
|
2020-06-23 00:09:42 +05:30
|
|
|
return _('alert') if todo.for_alert?
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
target_type = if todo.for_issue_or_work_item?
|
|
|
|
todo.target.issue_type
|
|
|
|
else
|
|
|
|
todo.target_type
|
|
|
|
end
|
|
|
|
|
|
|
|
target_type.titleize.downcase
|
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)
|
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
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
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
|
|
|
|
|
|
|
|
case todo.target
|
|
|
|
when MergeRequest
|
|
|
|
if state == 'closed'
|
|
|
|
background_class = 'gl-bg-red-500'
|
|
|
|
elsif state == 'merged'
|
|
|
|
background_class = 'gl-bg-blue-500'
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2022-07-23 23:45:48 +05:30
|
|
|
when Issue
|
|
|
|
background_class = 'gl-bg-blue-500' if state == 'closed'
|
|
|
|
when AlertManagement::Alert
|
|
|
|
background_class = 'gl-bg-blue-500' if state == 'resolved'
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
tag.span class: "gl-my-0 gl-px-2 status-box #{background_class}" do
|
2021-06-08 01:23:25 +05:30
|
|
|
todo.target.state.to_s.capitalize
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
def todos_filter_params
|
|
|
|
{
|
2022-08-27 11:52:29 +05:30
|
|
|
state: params[:state],
|
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]
|
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
|
|
|
[
|
|
|
|
{ id: '', text: 'Any Action' },
|
|
|
|
{ id: Todo::ASSIGNED, text: 'Assigned' },
|
2021-01-03 14:25:43 +05:30
|
|
|
{ id: Todo::REVIEW_REQUESTED, text: 'Review requested' },
|
2017-08-17 22:00:37 +05:30
|
|
|
{ id: Todo::MENTIONED, text: 'Mentioned' },
|
|
|
|
{ id: Todo::MARKED, text: 'Added' },
|
2022-07-16 23:28:13 +05:30
|
|
|
{ id: Todo::BUILD_FAILED, text: 'Pipelines' }
|
2016-04-02 18:10:28 +05:30
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def todo_types_options
|
2016-09-29 09:46:39 +05:30
|
|
|
[
|
|
|
|
{ id: '', text: 'Any Type' },
|
|
|
|
{ id: 'Issue', text: 'Issue' },
|
2021-04-29 21:17:54 +05:30
|
|
|
{ id: 'MergeRequest', text: 'Merge request' },
|
2020-10-24 23:57:45 +05:30
|
|
|
{ id: 'DesignManagement::Design', text: 'Design' },
|
|
|
|
{ id: 'AlertManagement::Alert', text: '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-06-16 23:09:34 +05:30
|
|
|
|
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
|
2016-11-03 12:29:30 +05:30
|
|
|
"Due #{is_due_today ? "today" : todo.target.due_date.to_s(:medium)}"
|
|
|
|
end
|
2018-12-05 23:21:45 +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
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
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)
|
|
|
|
todo.self_added? ? 'yourself' : 'you'
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
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
|
2016-06-16 23:09:34 +05:30
|
|
|
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')
|