BigW Consortium Gitlab

issuables_helper.rb 2.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
module IssuablesHelper

  def sidebar_gutter_toggle_icon
    sidebar_gutter_collapsed? ? icon('angle-double-left') : icon('angle-double-right')
  end

  def sidebar_gutter_collapsed_class
    "right-sidebar-#{sidebar_gutter_collapsed? ? 'collapsed' : 'expanded'}"
  end

  def issuables_count(issuable)
12
    base_issuable_scope(issuable).maximum(:iid)
13 14 15
  end

  def next_issuable_for(issuable)
16
    base_issuable_scope(issuable).where('iid > ?', issuable.iid).last
17 18
  end

19
  def multi_label_name(current_labels, default_label)
20
    # current_labels may be a string from before
Arinde Eniola committed
21 22 23
    if current_labels.is_a?(Array)
      if current_labels.count > 1
        "#{current_labels[0]} +#{current_labels.count - 1} more"
24
      else
Arinde Eniola committed
25
        current_labels[0]
26
      end
Arinde Eniola committed
27
    elsif current_labels.is_a?(String)
Arinde Eniola committed
28
      if current_labels.nil? || current_labels.empty?
29 30 31 32
        default_label
      else
        current_labels
      end
Arinde Eniola committed
33 34
    else
      default_label
35 36 37
    end
  end

38 39 40 41 42 43 44 45 46 47
  def issuable_json_path(issuable)
    project = issuable.project

    if issuable.kind_of?(MergeRequest)
      namespace_project_merge_request_path(project.namespace, project, issuable.iid, :json)
    else
      namespace_project_issue_path(project.namespace, project, issuable.iid, :json)
    end
  end

48
  def prev_issuable_for(issuable)
49
    base_issuable_scope(issuable).where('iid < ?', issuable.iid).first
50 51
  end

52 53 54
  def user_dropdown_label(user_id, default_label)
    return "Unassigned" if user_id == "0"

55 56
    if @project
      member = @project.team.find_member(user_id)
57
      user = member.user if member
58
    else
59
      user = User.find_by(id: user_id)
60
    end
61 62 63 64 65 66 67 68

    if user
      user.name
    else
      default_label
    end
  end

69
  def milestone_dropdown_label(milestone_title, default_label = "Milestone")
Phil Hughes committed
70 71
    if milestone_title == Milestone::Upcoming.name
      milestone_title = Milestone::Upcoming.title
72
    end
Phil Hughes committed
73 74

    h(milestone_title.presence || default_label)
75 76
  end

77 78
  def issuable_meta(issuable, project, text)
    output = content_tag :strong, "#{text} #{issuable.to_reference}", class: "identifier"
Phil Hughes committed
79
    output << " opened #{time_ago_with_tooltip(issuable.created_at)} by".html_safe
80 81 82 83 84 85
    output << content_tag(:strong) do
      author_output = link_to_member(project, issuable.author, size: 24, mobile_classes: "hidden-xs")
      author_output << link_to_member(project, issuable.author, size: 24, by_username: true, avatar: false, mobile_classes: "hidden-sm hidden-md hidden-lg")
    end
  end

86 87 88 89 90 91 92
  private

  def sidebar_gutter_collapsed?
    cookies[:collapsed_gutter] == 'true'
  end

  def base_issuable_scope(issuable)
93
    issuable.project.send(issuable.class.table_name).send(issuable_state_scope(issuable))
94 95 96
  end

  def issuable_state_scope(issuable)
97 98 99 100 101
    if issuable.respond_to?(:merged?) && issuable.merged?
      :merged
    else
      issuable.open? ? :opened : :closed
    end
102 103 104
  end

end