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'
|
|
|
|
when Todo::MENTIONED then "mentioned #{todo_action_subject(todo)} on"
|
|
|
|
when Todo::BUILD_FAILED then 'The build failed for'
|
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'
|
|
|
|
when Todo::DIRECTLY_ADDRESSED then "directly addressed #{todo_action_subject(todo)} on"
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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)
|
|
|
|
if todo.target
|
|
|
|
"\"#{todo.target.title}\""
|
|
|
|
else
|
|
|
|
""
|
|
|
|
end
|
|
|
|
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)
|
|
|
|
todo.target_type.titleize.downcase
|
|
|
|
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)
|
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)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
type =
|
|
|
|
case todo.target
|
|
|
|
when MergeRequest
|
|
|
|
'mr'
|
|
|
|
when Issue
|
|
|
|
'issue'
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
content_tag(:span, nil, class: 'target-status') do
|
2018-03-17 18:26:18 +05:30
|
|
|
content_tag(:span, nil, class: "status-box status-box-#{type}-#{todo.target.state.dasherize}") do
|
2016-06-16 23:09:34 +05:30
|
|
|
todo.target.state.capitalize
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
def todos_filter_params
|
|
|
|
{
|
|
|
|
state: params[:state],
|
|
|
|
project_id: params[:project_id],
|
|
|
|
author_id: params[:author_id],
|
|
|
|
type: params[:type],
|
2017-09-10 17:25:29 +05:30
|
|
|
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
|
|
|
|
|
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' },
|
2017-08-17 22:00:37 +05:30
|
|
|
{ id: Todo::MENTIONED, text: 'Mentioned' },
|
|
|
|
{ id: Todo::MARKED, text: 'Added' },
|
|
|
|
{ id: Todo::BUILD_FAILED, text: 'Pipelines' },
|
|
|
|
{ id: Todo::DIRECTLY_ADDRESSED, text: 'Directly addressed' }
|
2016-04-02 18:10:28 +05:30
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def todo_projects_options
|
2017-08-17 22:00:37 +05:30
|
|
|
projects = current_user.authorized_projects.sorted_by_activity.non_archived.with_route
|
2016-04-02 18:10:28 +05:30
|
|
|
|
|
|
|
projects = projects.map do |project|
|
2018-03-27 19:54:05 +05:30
|
|
|
{ id: project.id, text: project.full_name }
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
projects.unshift({ id: '', text: 'Any Project' }).to_json
|
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' },
|
|
|
|
{ id: 'MergeRequest', text: 'Merge Request' }
|
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)
|
|
|
|
selected_action = todo_actions_options.find { |action| action[:id] == selected_action_id.to_i}
|
|
|
|
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
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
private
|
|
|
|
|
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)
|
2017-08-17 22:00:37 +05:30
|
|
|
(todo.target.is_a?(MergeRequest) || todo.target.is_a?(Issue)) && %w(closed merged).include?(todo.target.state)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
def todo_group_options
|
2019-09-30 21:07:59 +05:30
|
|
|
groups = current_user.authorized_groups.with_route.map do |group|
|
2018-11-18 11:00:15 +05:30
|
|
|
{ id: group.id, text: group.full_name }
|
|
|
|
end
|
|
|
|
|
|
|
|
groups.unshift({ id: '', text: 'Any Group' }).to_json
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
TodosHelper.prepend_if_ee('EE::TodosHelper')
|