BigW Consortium Gitlab

issues_helper.rb 3.37 KB
Newer Older
gitlabhq committed
1
module IssuesHelper
Dmitriy Zaporozhets committed
2 3
  def issue_css_classes issue
    classes = "issue"
Andrew8xx8 committed
4
    classes << " closed" if issue.closed?
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

skv committed
16 17
  def url_for_project_issues(project = @project)
    return '' if project.nil?
18

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

skv committed
28 29
  def url_for_new_issue(project = @project)
    return '' if project.nil?
30

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

skv committed
41 42
  def url_for_issue(issue_iid, project = @project)
    return '' if project.nil?
Andrew8xx8 committed
43

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

skv committed
54 55
  def title_for_issue(issue_iid, project = @project)
    return '' if project.nil?
Andrew8xx8 committed
56

skv committed
57 58 59
    if project.used_default_issues_tracker?
      issue = project.issues.where(iid: issue_iid).first
      return issue.title if issue
60
    end
skv committed
61 62

    ''
63
  end
64

65 66
  # Checks if issues_tracker setting exists in gitlab.yml
  def external_issues_tracker_enabled?
skv committed
67
    Gitlab.config.issues_tracker && Gitlab.config.issues_tracker.values.any?
68
  end
69 70

  def bulk_update_milestone_options
skv committed
71 72 73
    options_for_select(['None (backlog)']) +
        options_from_collection_for_select(project_active_milestones, 'id',
                                           'title', params[:milestone_id])
74 75
  end

skv committed
76 77 78 79
  def bulk_update_assignee_options(project = @project)
    options_for_select(['None (unassigned)']) +
        options_from_collection_for_select(project.team.members, 'id',
                                           'name', params[:assignee_id])
80
  end
81

skv committed
82 83 84
  def assignee_options(object, project = @project)
    options_from_collection_for_select(project.team.members.sort_by(&:name),
                                       'id', 'name', object.assignee_id)
85 86 87
  end

  def milestone_options object
skv committed
88 89
    options_from_collection_for_select(object.project.milestones.active,
                                       'id', 'title', object.milestone_id)
90
  end
91

Dmitriy Zaporozhets committed
92 93 94 95 96 97 98
  def issue_box_class(item)
    if item.respond_to?(:expired?) && item.expired?
      'issue-box-expired'
    elsif item.respond_to?(:merged?) && item.merged?
      'issue-box-merged'
    elsif item.closed?
      'issue-box-closed'
99
    else
Dmitriy Zaporozhets committed
100
      'issue-box-open'
101 102
    end
  end
gitlabhq committed
103
end