issues_helper.rb 3.5 KB
Newer Older
gitlabhq's avatar
gitlabhq committed
1
module IssuesHelper
2
  def issue_css_classes(issue)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
3
    classes = "issue"
Andrew8xx8's avatar
Andrew8xx8 committed
4
    classes << " closed" if issue.closed?
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
5 6 7
    classes << " today" if issue.today?
    classes
  end
8

9 10 11 12
  # Returns an OpenStruct object suitable for use by <tt>options_from_collection_for_select</tt>
  # to allow filtering issues by an unassigned User or Milestone
  def unassigned_filter
    # Milestone uses :title, Issue uses :name
13
    OpenStruct.new(id: 0, title: 'None (backlog)', name: 'Unassigned')
14
  end
15

16
  def url_for_project_issues(project = @project, options = {})
skv's avatar
skv committed
17
    return '' if project.nil?
18

19 20 21 22 23
    if options[:only_path]
      project.issues_tracker.project_path
    else
      project.issues_tracker.project_url
    end
24 25
  end

26
  def url_for_new_issue(project = @project, options = {})
skv's avatar
skv committed
27
    return '' if project.nil?
28

29 30 31 32 33
    if options[:only_path]
      project.issues_tracker.new_issue_path
    else
      project.issues_tracker.new_issue_url
    end
34 35
  end

36
  def url_for_issue(issue_iid, project = @project, options = {})
skv's avatar
skv committed
37
    return '' if project.nil?
Andrew8xx8's avatar
Andrew8xx8 committed
38

39 40 41 42 43
    if options[:only_path]
      project.issues_tracker.issue_path(issue_iid)
    else
      project.issues_tracker.issue_url(issue_iid)
    end
44 45
  end

46
  def bulk_update_milestone_options
47 48 49 50
    milestones = project_active_milestones.to_a
    milestones.unshift(Milestone::None)

    options_from_collection_for_select(milestones, 'id', 'title', params[:milestone_id])
51 52
  end

53
  def milestone_options(object)
54 55 56 57
    milestones = object.project.milestones.active.to_a
    milestones.unshift(Milestone::None)

    options_from_collection_for_select(milestones, 'id', 'title', object.milestone_id)
58
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
59

60
  def status_box_class(item)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
61
    if item.respond_to?(:expired?) && item.expired?
62
      'status-box-expired'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
63
    elsif item.respond_to?(:merged?) && item.merged?
64
      'status-box-merged'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
65
    elsif item.closed?
66
      'status-box-closed'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
67
    else
68
      'status-box-open'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
69 70
    end
  end
71 72 73

  def issue_to_atom(xml, issue)
    xml.entry do
Vinnie Okada's avatar
Vinnie Okada committed
74 75 76 77
      xml.id      namespace_project_issue_url(issue.project.namespace,
                                              issue.project, issue)
      xml.link    href: namespace_project_issue_url(issue.project.namespace,
                                                    issue.project, issue)
78 79
      xml.title   truncate(issue.title, length: 80)
      xml.updated issue.created_at.strftime("%Y-%m-%dT%H:%M:%SZ")
80
      xml.media   :thumbnail, width: "40", height: "40", url: image_url(avatar_icon(issue.author_email))
81 82 83 84 85 86 87
      xml.author do |author|
        xml.name issue.author_name
        xml.email issue.author_email
      end
      xml.summary issue.title
    end
  end
Robert Speicher's avatar
Robert Speicher committed
88

89
  def merge_requests_sentence(merge_requests)
90 91 92 93 94
    # Sorting based on the `!123` or `group/project!123` reference will sort
    # local merge requests first.
    merge_requests.map do |merge_request|
      merge_request.to_reference(@project)
    end.sort.to_sentence(last_word_connector: ', or ')
95 96
  end

Valery Sizov's avatar
Valery Sizov committed
97
  def url_to_emoji(name)
98
    emoji_path = ::AwardEmoji.path_to_emoji_image(name)
Valery Sizov's avatar
Valery Sizov committed
99
    url_to_image(emoji_path)
Valery Sizov's avatar
Valery Sizov committed
100 101
  rescue StandardError
    ""
Valery Sizov's avatar
Valery Sizov committed
102 103
  end

Valery Sizov's avatar
Valery Sizov committed
104 105
  def emoji_author_list(notes, current_user)
    list = notes.map do |note|
Douwe Maan's avatar
Douwe Maan committed
106
             note.author == current_user ? "me" : note.author.name
Valery Sizov's avatar
Valery Sizov committed
107 108 109 110 111
           end

    list.join(", ")
  end

Valery Sizov's avatar
Valery Sizov committed
112 113 114 115
  def emoji_list
    ::AwardEmoji::EMOJI_LIST
  end

Valery Sizov's avatar
Valery Sizov committed
116
  def note_active_class(notes, current_user)
Valery Sizov's avatar
Valery Sizov committed
117 118 119 120 121
    if current_user && notes.pluck(:author_id).include?(current_user.id)
      "active"
    else
      ""
    end
Valery Sizov's avatar
Valery Sizov committed
122 123
  end

124
  # Required for Banzai::Filter::IssueReferenceFilter
125
  module_function :url_for_issue
gitlabhq's avatar
gitlabhq committed
126
end