Module: TodosHelper

Defined in:
app/helpers/todos_helper.rb

Instance Method Summary collapse

Instance Method Details

#todo_action_name(todo) ⇒ Object


10
11
12
13
14
15
# File 'app/helpers/todos_helper.rb', line 10

def todo_action_name(todo)
  case todo.action
  when Todo::ASSIGNED then 'assigned you'
  when Todo::MENTIONED then 'mentioned you on'
  end
end

#todo_actions_optionsObject


62
63
64
65
66
67
68
69
70
# File 'app/helpers/todos_helper.rb', line 62

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

#todo_projects_optionsObject


72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/todos_helper.rb', line 72

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

17
18
19
20
# File 'app/helpers/todos_helper.rb', line 17

def todo_target_link(todo)
  target = todo.target_type.titleize.downcase
  link_to "#{target} #{todo.target_reference}", todo_target_path(todo), { title: todo.target.title }
end

#todo_target_path(todo) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/todos_helper.rb', line 22

def todo_target_path(todo)
  return unless todo.target.present?

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

  if todo.for_commit?
    namespace_project_commit_path(todo.project.namespace.becomes(Namespace), todo.project,
                                  todo.target, anchor: anchor)
  else
    polymorphic_path([todo.project.namespace.becomes(Namespace),
                      todo.project, todo.target], anchor: anchor)
  end
end

#todo_types_optionsObject


85
86
87
88
89
90
91
92
93
# File 'app/helpers/todos_helper.rb', line 85

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

#todos_done_countObject


6
7
8
# File 'app/helpers/todos_helper.rb', line 6

def todos_done_count
  current_user.todos.done.count
end

#todos_filter_paramsObject


36
37
38
39
40
41
42
43
44
# File 'app/helpers/todos_helper.rb', line 36

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

#todos_filter_path(options = {}) ⇒ Object


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/helpers/todos_helper.rb', line 46

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

#todos_pending_countObject


2
3
4
# File 'app/helpers/todos_helper.rb', line 2

def todos_pending_count
  current_user.todos.pending.count
end