summaryrefslogtreecommitdiff
path: root/app/helpers/todos_helper.rb
blob: 7c36046894593d2c51022ee5305c5a535035924d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module TodosHelper
  def todos_pending_count
    current_user.todos.pending.count
  end

  def todos_done_count
    current_user.todos.done.count
  end

  def todo_action_name(todo)
    target =  todo.target_type.titleize.downcase

    [todo.action_name, target].join(" ")
  end

  def todo_target_link_html(todo)
    link_to "##{todo.target_iid}", todo_target_path(todo)
  end

  def todo_target_path(todo)
    anchor = dom_id(todo.note) if todo.note.present?

    polymorphic_path([todo.project.namespace.becomes(Namespace),
                      todo.project, todo.target], anchor: anchor)
  end

  def todo_actions_options
    actions = [
      OpenStruct.new(id: '', title: 'Any Action'),
      OpenStruct.new(id: Todo::ASSIGNED, title: 'Assigned'),
      OpenStruct.new(id: Todo::MENTIONED, title: 'Mentioned')
    ]

    options_from_collection_for_select(actions, 'id', 'title', params[:action_id])
  end

  def todo_projects_options
    projects = current_user.authorized_projects.sorted_by_activity.non_archived
    projects = projects.includes(:namespace)

    projects = projects.map do |project|
      OpenStruct.new(id: project.id, title: project.name_with_namespace)
    end

    projects.unshift(OpenStruct.new(id: '', title: 'Any Project'))

    options_from_collection_for_select(projects, 'id', 'title', params[:project_id])
  end

  def todo_types_options
    types = [
      OpenStruct.new(title: 'Any Type', name: ''),
      OpenStruct.new(title: 'Issue', name: 'Issue'),
      OpenStruct.new(title: 'Merge Request', name: 'MergeRequest')
    ]

    options_from_collection_for_select(types, 'name', 'title', params[:type])
  end
end