issues_helper.rb 2.82 KB
Newer Older
gitlabhq's avatar
gitlabhq committed
1
module IssuesHelper
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
2 3
  def issue_css_classes issue
    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 17 18
  def url_for_project_issues
    return "" if @project.nil?

19
    if @project.used_default_issues_tracker? || !external_issues_tracker_enabled?
20
      project_issues_path(@project)
21
    else
22
      url = Gitlab.config.issues_tracker[@project.issues_tracker]["project_url"]
23 24 25 26 27
      url.gsub(':project_id', @project.id.to_s)
         .gsub(':issues_tracker_id', @project.issues_tracker_id.to_s)
    end
  end

28 29 30
  def url_for_new_issue
    return "" if @project.nil?

31
    if @project.used_default_issues_tracker? || !external_issues_tracker_enabled?
32 33
      url = new_project_issue_path project_id: @project
    else
34
      url = Gitlab.config.issues_tracker[@project.issues_tracker]["new_issue_url"]
35 36 37 38 39
      url.gsub(':project_id', @project.id.to_s)
        .gsub(':issues_tracker_id', @project.issues_tracker_id.to_s)
    end
  end

40
  def url_for_issue(issue_iid)
Andrew8xx8's avatar
Andrew8xx8 committed
41 42
    return "" if @project.nil?

43
    if @project.used_default_issues_tracker? || !external_issues_tracker_enabled?
44
      url = project_issue_url project_id: @project, id: issue_iid
45
    else
46
      url = Gitlab.config.issues_tracker[@project.issues_tracker]["issues_url"]
47
      url.gsub(':id', issue_iid.to_s)
Andrew8xx8's avatar
Andrew8xx8 committed
48 49
        .gsub(':project_id', @project.id.to_s)
        .gsub(':issues_tracker_id', @project.issues_tracker_id.to_s)
50 51 52
    end
  end

53
  def title_for_issue(issue_iid)
Andrew8xx8's avatar
Andrew8xx8 committed
54 55
    return "" if @project.nil?

56
    if @project.used_default_issues_tracker? && issue = @project.issues.where(iid: issue_iid).first
57 58 59 60 61
      issue.title
    else
      ""
    end
  end
62

63 64 65 66 67 68 69
  # Checks if issues_tracker setting exists in gitlab.yml
  def external_issues_tracker_enabled?
    if Gitlab.config.issues_tracker && Gitlab.config.issues_tracker.values.any?
      true
    else
      false
    end
70
  end
71 72 73 74 75 76 77 78

  def bulk_update_milestone_options
    options_for_select(["None (backlog)", nil]) + options_from_collection_for_select(project_active_milestones, "id", "title", params[:milestone_id])
  end

  def bulk_update_assignee_options
    options_for_select(["None (unassigned)", nil]) + options_from_collection_for_select(@project.team.members, "id", "name", params[:assignee_id])
  end
79 80 81 82 83 84 85 86

  def assignee_options object
    options_from_collection_for_select(@project.team.members.sort_by(&:name), 'id', 'name', object.assignee_id)
  end

  def milestone_options object
    options_from_collection_for_select(@project.milestones.active, 'id', 'title', object.milestone_id)
  end
gitlabhq's avatar
gitlabhq committed
87
end