2016-02-20 08:59:59 -05:00
|
|
|
module TodosHelper
|
|
|
|
def todos_pending_count
|
2016-08-11 12:39:50 -04:00
|
|
|
@todos_pending_count ||= current_user.todos_pending_count
|
2016-02-20 08:59:59 -05:00
|
|
|
end
|
|
|
|
|
2017-02-21 14:21:49 -05:00
|
|
|
def todos_count_format(count)
|
2017-06-09 18:12:00 -04:00
|
|
|
count > 99 ? '99+' : count.to_s
|
2017-02-21 14:21:49 -05:00
|
|
|
end
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
def todos_done_count
|
2016-08-11 12:39:50 -04:00
|
|
|
@todos_done_count ||= current_user.todos_done_count
|
2016-02-20 08:59:59 -05:00
|
|
|
end
|
|
|
|
|
2016-02-20 15:01:50 -05:00
|
|
|
def todo_action_name(todo)
|
|
|
|
case todo.action
|
2017-04-10 11:51:15 -04:00
|
|
|
when Todo::ASSIGNED then todo.self_added? ? 'assigned' : 'assigned you'
|
|
|
|
when Todo::MENTIONED then "mentioned #{todo_action_subject(todo)} on"
|
2016-12-12 16:55:33 -05:00
|
|
|
when Todo::BUILD_FAILED then 'The build failed for'
|
2016-06-17 04:01:03 -04:00
|
|
|
when Todo::MARKED then 'added a todo for'
|
2017-04-10 11:51:15 -04:00
|
|
|
when Todo::APPROVAL_REQUIRED then "set #{todo_action_subject(todo)} as an approver for"
|
2016-12-14 09:37:31 -05:00
|
|
|
when Todo::UNMERGEABLE then 'Could not merge'
|
2017-04-10 11:51:15 -04:00
|
|
|
when Todo::DIRECTLY_ADDRESSED then "directly addressed #{todo_action_subject(todo)} on"
|
2016-02-20 15:01:50 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-20 14:53:15 -05:00
|
|
|
def todo_target_link(todo)
|
2017-05-11 11:47:44 -04:00
|
|
|
text = raw("#{todo.target_type.titleize.downcase} ") +
|
|
|
|
if todo.for_commit?
|
|
|
|
content_tag(:span, todo.target_reference, class: 'commit-sha')
|
|
|
|
else
|
|
|
|
todo.target_reference
|
|
|
|
end
|
2018-01-11 11:34:01 -05:00
|
|
|
|
2017-05-11 11:47:44 -04:00
|
|
|
link_to text, todo_target_path(todo), class: 'has-tooltip', title: todo.target.title
|
2016-02-20 08:59:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def todo_target_path(todo)
|
2016-04-12 17:06:52 -04:00
|
|
|
return unless todo.target.present?
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
anchor = dom_id(todo.note) if todo.note.present?
|
|
|
|
|
2016-03-16 19:31:30 -04:00
|
|
|
if todo.for_commit?
|
2017-06-29 13:06:35 -04:00
|
|
|
project_commit_path(todo.project,
|
2016-03-16 19:31:30 -04:00
|
|
|
todo.target, anchor: anchor)
|
|
|
|
else
|
2018-07-16 09:35:19 -04:00
|
|
|
path = [todo.parent, todo.target]
|
2017-03-21 11:25:00 -04:00
|
|
|
|
|
|
|
path.unshift(:pipelines) if todo.build_failed?
|
2016-03-08 13:22:50 -05:00
|
|
|
|
|
|
|
polymorphic_path(path, anchor: anchor)
|
2016-03-16 19:31:30 -04:00
|
|
|
end
|
2016-02-20 08:59:59 -05:00
|
|
|
end
|
|
|
|
|
2016-04-28 14:54:13 -04:00
|
|
|
def todo_target_state_pill(todo)
|
2016-05-18 21:23:00 -04:00
|
|
|
return unless show_todo_state?(todo)
|
|
|
|
|
2018-01-17 09:09:59 -05:00
|
|
|
type =
|
|
|
|
case todo.target
|
|
|
|
when MergeRequest
|
|
|
|
'mr'
|
|
|
|
when Issue
|
|
|
|
'issue'
|
|
|
|
end
|
|
|
|
|
2016-05-18 21:23:00 -04:00
|
|
|
content_tag(:span, nil, class: 'target-status') do
|
2018-01-17 09:09:59 -05:00
|
|
|
content_tag(:span, nil, class: "status-box status-box-#{type}-#{todo.target.state.dasherize}") do
|
2016-05-18 21:23:00 -04:00
|
|
|
todo.target.state.capitalize
|
2016-05-09 18:19:26 -04:00
|
|
|
end
|
2016-04-28 17:37:00 -04:00
|
|
|
end
|
2016-04-28 14:54:13 -04:00
|
|
|
end
|
|
|
|
|
2016-02-20 14:53:25 -05:00
|
|
|
def todos_filter_params
|
|
|
|
{
|
|
|
|
state: params[:state],
|
|
|
|
project_id: params[:project_id],
|
|
|
|
author_id: params[:author_id],
|
|
|
|
type: params[:type],
|
2017-05-03 07:22:03 -04:00
|
|
|
action_id: params[:action_id]
|
2016-02-20 14:53:25 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-11-07 11:12:05 -05:00
|
|
|
def todos_filter_empty?
|
2016-11-08 04:31:08 -05:00
|
|
|
todos_filter_params.values.none?
|
2016-11-07 11:12:05 -05:00
|
|
|
end
|
|
|
|
|
2016-02-20 14:53:25 -05: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
|
|
|
|
|
|
|
|
path = request.path
|
|
|
|
path << "?#{options.to_param}"
|
|
|
|
path
|
|
|
|
end
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
def todo_actions_options
|
2016-08-27 18:45:01 -04:00
|
|
|
[
|
|
|
|
{ id: '', text: 'Any Action' },
|
|
|
|
{ id: Todo::ASSIGNED, text: 'Assigned' },
|
2017-01-28 17:39:24 -05:00
|
|
|
{ id: Todo::MENTIONED, text: 'Mentioned' },
|
|
|
|
{ id: Todo::MARKED, text: 'Added' },
|
2016-12-05 07:12:22 -05:00
|
|
|
{ id: Todo::BUILD_FAILED, text: 'Pipelines' },
|
|
|
|
{ id: Todo::DIRECTLY_ADDRESSED, text: 'Directly addressed' }
|
2016-02-20 08:59:59 -05:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def todo_projects_options
|
2017-03-16 09:28:14 -04:00
|
|
|
projects = current_user.authorized_projects.sorted_by_activity.non_archived.with_route
|
2016-02-20 08:59:59 -05:00
|
|
|
|
|
|
|
projects = projects.map do |project|
|
2018-03-05 09:15:26 -05:00
|
|
|
{ id: project.id, text: project.full_name }
|
2016-02-20 08:59:59 -05:00
|
|
|
end
|
|
|
|
|
2016-08-27 18:45:01 -04:00
|
|
|
projects.unshift({ id: '', text: 'Any Project' }).to_json
|
2016-02-20 08:59:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def todo_types_options
|
2016-08-27 18:45:01 -04:00
|
|
|
[
|
2016-08-28 11:24:48 -04:00
|
|
|
{ id: '', text: 'Any Type' },
|
|
|
|
{ id: 'Issue', text: 'Issue' },
|
|
|
|
{ id: 'MergeRequest', text: 'Merge Request' }
|
2016-02-20 08:59:59 -05:00
|
|
|
]
|
|
|
|
end
|
2016-05-09 18:19:26 -04:00
|
|
|
|
2016-08-28 11:24:48 -04: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 12:28:06 -04:00
|
|
|
def todo_due_date(todo)
|
2016-10-03 04:58:55 -04:00
|
|
|
return unless todo.target.try(:due_date)
|
|
|
|
|
2016-10-03 10:07:29 -04: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 12:28:06 -04:00
|
|
|
|
2016-10-03 05:08:34 -04:00
|
|
|
html = "· ".html_safe
|
2016-10-03 10:07:29 -04:00
|
|
|
html << content_tag(:span, class: css_class) do
|
2016-10-03 04:58:55 -04:00
|
|
|
"Due #{is_due_today ? "today" : todo.target.due_date.to_s(:medium)}"
|
|
|
|
end
|
2016-09-23 12:28:06 -04:00
|
|
|
end
|
|
|
|
|
2016-05-09 18:19:26 -04:00
|
|
|
private
|
|
|
|
|
2017-04-10 11:51:15 -04:00
|
|
|
def todo_action_subject(todo)
|
|
|
|
todo.self_added? ? 'yourself' : 'you'
|
|
|
|
end
|
|
|
|
|
2016-05-09 18:19:26 -04:00
|
|
|
def show_todo_state?(todo)
|
2017-02-22 12:46:57 -05:00
|
|
|
(todo.target.is_a?(MergeRequest) || todo.target.is_a?(Issue)) && %w(closed merged).include?(todo.target.state)
|
2016-05-09 18:19:26 -04:00
|
|
|
end
|
2018-07-16 09:35:19 -04:00
|
|
|
|
|
|
|
def todo_group_options
|
|
|
|
groups = current_user.authorized_groups.map do |group|
|
|
|
|
{ id: group.id, text: group.full_name }
|
|
|
|
end
|
|
|
|
|
|
|
|
groups.unshift({ id: '', text: 'Any Group' }).to_json
|
|
|
|
end
|
2016-02-20 08:59:59 -05:00
|
|
|
end
|