summaryrefslogtreecommitdiff
path: root/app/helpers/tasks_helper.rb
blob: 6975c1d1604d5e74ee2226e3fb06b6b0610fb28b (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
module TasksHelper
  def link_to_author(task)
    author = task.author

    if author
      link_to author.name, user_path(author.username)
    else
      task.author_name
    end
  end

  def tasks_pending_count
    current_user.tasks.pending.count
  end

  def tasks_done_count
    current_user.tasks.done.count
  end

  def task_action_name(task)
    target =  task.target_type.titleize.downcase

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

  def task_note_link_html(task)
    link_to task_note_target_path(task) do
      "##{task.target_iid}"
    end
  end

  def task_note_target_path(task)
    polymorphic_path([task.project.namespace.becomes(Namespace),
      task.project, task.target], anchor: dom_id(task.note))
  end

  def task_note(text, options = {})
    text = first_line_in_markdown(text, 150, options)
    sanitize(text, tags: %w(a img b pre code p span))
  end
end