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
|
|
|
|
|
|
|
|
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
|
|
|
|
when Todo::ASSIGNED then 'assigned you'
|
|
|
|
when Todo::MENTIONED then 'mentioned you on'
|
2016-06-02 11:05:42 +05:30
|
|
|
when Todo::BUILD_FAILED then 'The build failed for your'
|
2016-06-22 15:30:34 +05:30
|
|
|
when Todo::MARKED then 'added a todo for'
|
2016-08-24 12:49:21 +05:30
|
|
|
when Todo::APPROVAL_REQUIRED then 'set you as an approver for'
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def todo_target_link(todo)
|
|
|
|
target = todo.target_type.titleize.downcase
|
2016-06-16 23:09:34 +05:30
|
|
|
link_to "#{target} #{todo.target_reference}", todo_target_path(todo),
|
|
|
|
class: 'has-tooltip',
|
|
|
|
title: todo.target.title
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def todo_target_path(todo)
|
2016-06-02 11:05:42 +05:30
|
|
|
return unless todo.target.present?
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
anchor = dom_id(todo.note) if todo.note.present?
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
if todo.for_commit?
|
|
|
|
namespace_project_commit_path(todo.project.namespace.becomes(Namespace), todo.project,
|
|
|
|
todo.target, anchor: anchor)
|
|
|
|
else
|
|
|
|
path = [todo.project.namespace.becomes(Namespace), todo.project, todo.target]
|
|
|
|
|
|
|
|
path.unshift(:builds) if todo.build_failed?
|
|
|
|
|
|
|
|
polymorphic_path(path, anchor: anchor)
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
def todo_target_state_pill(todo)
|
|
|
|
return unless show_todo_state?(todo)
|
|
|
|
|
|
|
|
content_tag(:span, nil, class: 'target-status') do
|
|
|
|
content_tag(:span, nil, class: "status-box status-box-#{todo.target.state.dasherize}") do
|
|
|
|
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],
|
|
|
|
action_id: params[:action_id],
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def todo_actions_options
|
2016-09-29 09:46:39 +05:30
|
|
|
[
|
|
|
|
{ id: '', text: 'Any Action' },
|
|
|
|
{ id: Todo::ASSIGNED, text: 'Assigned' },
|
|
|
|
{ id: Todo::MENTIONED, text: 'Mentioned' }
|
2016-04-02 18:10:28 +05:30
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def todo_projects_options
|
|
|
|
projects = current_user.authorized_projects.sorted_by_activity.non_archived
|
|
|
|
projects = projects.includes(:namespace)
|
|
|
|
|
|
|
|
projects = projects.map do |project|
|
2016-09-29 09:46:39 +05:30
|
|
|
{ id: project.id, text: project.name_with_namespace }
|
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
|
|
|
|
|
|
|
|
html = "· ".html_safe
|
|
|
|
html << content_tag(:span, class: css_class) do
|
|
|
|
"Due #{is_due_today ? "today" : todo.target.due_date.to_s(:medium)}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def show_todo_state?(todo)
|
|
|
|
(todo.target.is_a?(MergeRequest) || todo.target.is_a?(Issue)) && ['closed', 'merged'].include?(todo.target.state)
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|