2018-08-18 11:19:57 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-20 13:59:59 +00:00
|
|
|
module TodosHelper
|
|
|
|
def todos_pending_count
|
2016-08-11 16:39:50 +00:00
|
|
|
@todos_pending_count ||= current_user.todos_pending_count
|
2016-02-20 13:59:59 +00:00
|
|
|
end
|
|
|
|
|
2017-02-21 19:21:49 +00:00
|
|
|
def todos_count_format(count)
|
2017-06-09 22:12:00 +00:00
|
|
|
count > 99 ? '99+' : count.to_s
|
2017-02-21 19:21:49 +00:00
|
|
|
end
|
|
|
|
|
2016-02-20 13:59:59 +00:00
|
|
|
def todos_done_count
|
2016-08-11 16:39:50 +00:00
|
|
|
@todos_done_count ||= current_user.todos_done_count
|
2016-02-20 13:59:59 +00:00
|
|
|
end
|
|
|
|
|
2016-02-20 20:01:50 +00:00
|
|
|
def todo_action_name(todo)
|
|
|
|
case todo.action
|
2017-04-10 15:51:15 +00:00
|
|
|
when Todo::ASSIGNED then todo.self_added? ? 'assigned' : 'assigned you'
|
2020-09-21 12:09:34 +00:00
|
|
|
when Todo::REVIEW_REQUESTED then 'requested a review of'
|
2017-04-10 15:51:15 +00:00
|
|
|
when Todo::MENTIONED then "mentioned #{todo_action_subject(todo)} on"
|
2016-12-12 21:55:33 +00:00
|
|
|
when Todo::BUILD_FAILED then 'The build failed for'
|
2016-06-17 08:01:03 +00:00
|
|
|
when Todo::MARKED then 'added a todo for'
|
2017-04-10 15:51:15 +00:00
|
|
|
when Todo::APPROVAL_REQUIRED then "set #{todo_action_subject(todo)} as an approver for"
|
2016-12-14 14:37:31 +00:00
|
|
|
when Todo::UNMERGEABLE then 'Could not merge'
|
2017-04-10 15:51:15 +00:00
|
|
|
when Todo::DIRECTLY_ADDRESSED then "directly addressed #{todo_action_subject(todo)} on"
|
2020-07-09 09:09:27 +00:00
|
|
|
when Todo::MERGE_TRAIN_REMOVED then "Removed from Merge Train:"
|
2021-10-28 12:10:22 +00:00
|
|
|
when Todo::ATTENTION_REQUIRED then 'requested your attention on'
|
2016-02-20 20:01:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-21 12:09:34 +00:00
|
|
|
def todo_self_addressing(todo)
|
|
|
|
case todo.action
|
|
|
|
when Todo::ASSIGNED then 'to yourself'
|
|
|
|
when Todo::REVIEW_REQUESTED then 'from yourself'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-20 19:53:15 +00:00
|
|
|
def todo_target_link(todo)
|
2019-08-14 01:34:42 +00:00
|
|
|
text = raw(todo_target_type_name(todo) + ' ') +
|
2017-05-11 15:47:44 +00:00
|
|
|
if todo.for_commit?
|
|
|
|
content_tag(:span, todo.target_reference, class: 'commit-sha')
|
|
|
|
else
|
|
|
|
todo.target_reference
|
|
|
|
end
|
2018-01-11 16:34:01 +00:00
|
|
|
|
2019-06-27 05:56:08 +00:00
|
|
|
link_to text, todo_target_path(todo)
|
|
|
|
end
|
|
|
|
|
|
|
|
def todo_target_title(todo)
|
2020-05-21 09:08:04 +00:00
|
|
|
# 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-06-27 05:56:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def todo_parent_path(todo)
|
2019-10-17 12:07:33 +00:00
|
|
|
if todo.resource_parent.is_a?(Group)
|
|
|
|
link_to todo.resource_parent.name, group_path(todo.resource_parent)
|
2019-06-27 05:56:08 +00:00
|
|
|
else
|
|
|
|
link_to_project(todo.project)
|
|
|
|
end
|
2016-02-20 13:59:59 +00:00
|
|
|
end
|
|
|
|
|
2019-08-14 01:34:42 +00:00
|
|
|
def todo_target_type_name(todo)
|
2020-05-12 21:08:14 +00:00
|
|
|
return _('design') if todo.for_design?
|
2020-06-05 18:08:19 +00:00
|
|
|
return _('alert') if todo.for_alert?
|
2020-05-12 21:08:14 +00:00
|
|
|
|
2019-08-14 01:34:42 +00:00
|
|
|
todo.target_type.titleize.downcase
|
|
|
|
end
|
|
|
|
|
2016-02-20 13:59:59 +00:00
|
|
|
def todo_target_path(todo)
|
2016-04-12 21:06:52 +00:00
|
|
|
return unless todo.target.present?
|
|
|
|
|
2019-08-14 01:34:42 +00:00
|
|
|
path_options = todo_target_path_options(todo)
|
2016-02-20 13:59:59 +00:00
|
|
|
|
2016-03-16 23:31:30 +00:00
|
|
|
if todo.for_commit?
|
2019-08-14 01:34:42 +00:00
|
|
|
project_commit_path(todo.project, todo.target, path_options)
|
2020-05-12 21:08:14 +00:00
|
|
|
elsif todo.for_design?
|
|
|
|
todos_design_path(todo, path_options)
|
2020-06-05 18:08:19 +00:00
|
|
|
elsif todo.for_alert?
|
|
|
|
details_project_alert_management_path(todo.project, todo.target)
|
2016-03-16 23:31:30 +00:00
|
|
|
else
|
2019-10-17 12:07:33 +00:00
|
|
|
path = [todo.resource_parent, todo.target]
|
2017-03-21 15:25:00 +00:00
|
|
|
|
|
|
|
path.unshift(:pipelines) if todo.build_failed?
|
2016-03-08 18:22:50 +00:00
|
|
|
|
2019-08-14 01:34:42 +00:00
|
|
|
polymorphic_path(path, path_options)
|
2016-03-16 23:31:30 +00:00
|
|
|
end
|
2016-02-20 13:59:59 +00:00
|
|
|
end
|
|
|
|
|
2019-08-14 01:34:42 +00:00
|
|
|
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-04-28 18:54:13 +00:00
|
|
|
def todo_target_state_pill(todo)
|
2016-05-19 01:23:00 +00:00
|
|
|
return unless show_todo_state?(todo)
|
|
|
|
|
2018-01-17 14:09:59 +00:00
|
|
|
type =
|
|
|
|
case todo.target
|
|
|
|
when MergeRequest
|
|
|
|
'mr'
|
|
|
|
when Issue
|
|
|
|
'issue'
|
2020-07-07 12:09:16 +00:00
|
|
|
when AlertManagement::Alert
|
|
|
|
'alert'
|
2018-01-17 14:09:59 +00:00
|
|
|
end
|
|
|
|
|
2021-05-15 12:10:27 +00:00
|
|
|
tag.span class: "gl-my-0 gl-px-2 status-box status-box-#{type}-#{todo.target.state.to_s.dasherize}" do
|
|
|
|
todo.target.state.to_s.capitalize
|
2016-04-28 21:37:00 +00:00
|
|
|
end
|
2016-04-28 18:54:13 +00:00
|
|
|
end
|
|
|
|
|
2016-02-20 19:53:25 +00:00
|
|
|
def todos_filter_params
|
|
|
|
{
|
|
|
|
state: params[:state],
|
|
|
|
project_id: params[:project_id],
|
|
|
|
author_id: params[:author_id],
|
|
|
|
type: params[:type],
|
2017-05-03 11:22:03 +00:00
|
|
|
action_id: params[:action_id]
|
2016-02-20 19:53:25 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-11-07 16:12:05 +00:00
|
|
|
def todos_filter_empty?
|
2016-11-08 09:31:08 +00:00
|
|
|
todos_filter_params.values.none?
|
2016-11-07 16:12:05 +00:00
|
|
|
end
|
|
|
|
|
2016-02-20 19:53:25 +00:00
|
|
|
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-08-18 11:19:57 +00:00
|
|
|
"#{request.path}?#{options.to_param}"
|
2016-02-20 19:53:25 +00:00
|
|
|
end
|
|
|
|
|
2016-02-20 13:59:59 +00:00
|
|
|
def todo_actions_options
|
2016-08-27 22:45:01 +00:00
|
|
|
[
|
|
|
|
{ id: '', text: 'Any Action' },
|
|
|
|
{ id: Todo::ASSIGNED, text: 'Assigned' },
|
2020-09-21 12:09:34 +00:00
|
|
|
{ id: Todo::REVIEW_REQUESTED, text: 'Review requested' },
|
2017-01-28 22:39:24 +00:00
|
|
|
{ id: Todo::MENTIONED, text: 'Mentioned' },
|
|
|
|
{ id: Todo::MARKED, text: 'Added' },
|
2016-12-05 12:12:22 +00:00
|
|
|
{ id: Todo::BUILD_FAILED, text: 'Pipelines' },
|
|
|
|
{ id: Todo::DIRECTLY_ADDRESSED, text: 'Directly addressed' }
|
2016-02-20 13:59:59 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def todo_types_options
|
2016-08-27 22:45:01 +00:00
|
|
|
[
|
2016-08-28 15:24:48 +00:00
|
|
|
{ id: '', text: 'Any Type' },
|
|
|
|
{ id: 'Issue', text: 'Issue' },
|
2021-04-08 15:09:06 +00:00
|
|
|
{ id: 'MergeRequest', text: 'Merge request' },
|
2020-08-03 15:09:44 +00:00
|
|
|
{ id: 'DesignManagement::Design', text: 'Design' },
|
|
|
|
{ id: 'AlertManagement::Alert', text: 'Alert' }
|
2016-02-20 13:59:59 +00:00
|
|
|
]
|
|
|
|
end
|
2016-05-09 22:19:26 +00:00
|
|
|
|
2016-08-28 15:24:48 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-09-23 16:28:06 +00:00
|
|
|
def todo_due_date(todo)
|
2016-10-03 08:58:55 +00:00
|
|
|
return unless todo.target.try(:due_date)
|
|
|
|
|
2016-10-03 14:07:29 +00:00
|
|
|
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
|
2016-09-23 16:28:06 +00:00
|
|
|
|
2018-08-18 11:19:57 +00:00
|
|
|
content = content_tag(:span, class: css_class) do
|
2016-10-03 08:58:55 +00:00
|
|
|
"Due #{is_due_today ? "today" : todo.target.due_date.to_s(:medium)}"
|
|
|
|
end
|
2018-08-18 11:19:57 +00:00
|
|
|
|
|
|
|
"· #{content}".html_safe
|
2016-09-23 16:28:06 +00:00
|
|
|
end
|
|
|
|
|
2020-07-09 09:09:27 +00:00
|
|
|
def todo_author_display?(todo)
|
|
|
|
!todo.build_failed? && !todo.unmergeable?
|
|
|
|
end
|
|
|
|
|
2016-05-09 22:19:26 +00:00
|
|
|
private
|
|
|
|
|
2020-05-12 21:08:14 +00:00
|
|
|
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-04-10 15:51:15 +00:00
|
|
|
def todo_action_subject(todo)
|
|
|
|
todo.self_added? ? 'yourself' : 'you'
|
|
|
|
end
|
|
|
|
|
2016-05-09 22:19:26 +00:00
|
|
|
def show_todo_state?(todo)
|
2020-07-07 12:09:16 +00:00
|
|
|
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-05-09 22:19:26 +00:00
|
|
|
end
|
2016-02-20 13:59:59 +00:00
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
TodosHelper.prepend_mod_with('TodosHelper')
|