issues_helper.rb 2.74 KB
Newer Older
gitlabhq's avatar
gitlabhq committed
1
module IssuesHelper
2
3
4
5
  def project_issues_filter_path project, params = {}
    params[:f] ||= cookies['issue_filter']
    project_issues_path project, params
  end
6

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
7
8
  def issue_css_classes issue
    classes = "issue"
Andrew8xx8's avatar
Andrew8xx8 committed
9
    classes << " closed" if issue.closed?
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
10
11
12
    classes << " today" if issue.today?
    classes
  end
13

14
  def issue_tags
15
16
    @project.issues.tag_counts_on(:labels).map(&:name)
  end
17

18
19
20
21
22
  # 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
    OpenStruct.new(id: 0, title: 'Unspecified', name: 'Unassigned')
23
  end
24
25
26
27
28
29

  def issues_filter
    {
      all: "all",
      closed: "closed",
      to_me: "assigned-to-me",
30
      by_me: "created-by-me",
31
32
33
      open: "open"
    }
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
34
35
36
37
38
39

  def labels_autocomplete_source
    labels = @project.issues_labels.order('count DESC')
    labels = labels.map{ |l| { label: l.name, value: l.name } }
    labels.to_json
  end
40
41
42
43

  def issues_active_milestones
    @project.milestones.active.order("id desc").all
  end
44

45
46
47
48
  def url_for_project_issues
    return "" if @project.nil?

    if @project.used_default_issues_tracker?
49
      project_issues_filter_path(@project)
50
    else
51
      url = Gitlab.config.issues_tracker[@project.issues_tracker]["project_url"]
52
53
54
55
56
      url.gsub(':project_id', @project.id.to_s)
         .gsub(':issues_tracker_id', @project.issues_tracker_id.to_s)
    end
  end

57
58
59
60
61
62
  def url_for_new_issue
    return "" if @project.nil?

    if @project.used_default_issues_tracker?
      url = new_project_issue_path project_id: @project
    else
63
      url = Gitlab.config.issues_tracker[@project.issues_tracker]["new_issue_url"]
64
65
66
67
68
      url.gsub(':project_id', @project.id.to_s)
        .gsub(':issues_tracker_id', @project.issues_tracker_id.to_s)
    end
  end

69
  def url_for_issue(issue_id)
Andrew8xx8's avatar
Andrew8xx8 committed
70
71
    return "" if @project.nil?

72
    if @project.used_default_issues_tracker?
73
74
      url = project_issue_url project_id: @project, id: issue_id
    else
75
      url = Gitlab.config.issues_tracker[@project.issues_tracker]["issues_url"]
Andrew8xx8's avatar
Andrew8xx8 committed
76
77
78
      url.gsub(':id', issue_id.to_s)
        .gsub(':project_id', @project.id.to_s)
        .gsub(':issues_tracker_id', @project.issues_tracker_id.to_s)
79
80
81
82
    end
  end

  def title_for_issue(issue_id)
Andrew8xx8's avatar
Andrew8xx8 committed
83
84
    return "" if @project.nil?

85
    if @project.used_default_issues_tracker? && issue = @project.issues.where(id: issue_id).first
86
87
88
89
90
      issue.title
    else
      ""
    end
  end
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

  def label_css_class(name)
    case name
    when *warning_labels
      'label-warning'
    when *neutral_labels
      'label-inverse'
    when *positive_labels
      'label-success'
    when *important_labels
      'label-important'
    else
      'label-info'
    end
  end
gitlabhq's avatar
gitlabhq committed
106
end