groups_helper.rb 2.07 KB
Newer Older
1
module GroupsHelper
2 3 4 5
  def can_change_group_visibility_level?(group)
    can?(current_user, :change_visibility_level, group)
  end

6 7
  def group_icon(group)
    if group.is_a?(String)
8
      group = Group.find_by_full_path(group)
9 10
    end

11
    group.try(:avatar_url) || ActionController::Base.helpers.image_path('no_group_avatar.png')
12
  end
13

14
  def group_title(group, name = nil, url = nil)
Sam Rose's avatar
Sam Rose committed
15
    @has_group_title = true
16 17
    full_title = ''

Michael Kozono's avatar
Michael Kozono committed
18
    group.ancestors.reverse.each do |parent|
Phil Hughes's avatar
Phil Hughes committed
19 20
      full_title += group_title_link(parent, hidable: true)

Sam Rose's avatar
Sam Rose committed
21
      full_title += '<span class="hidable"> / </span>'.html_safe
22 23
    end

Phil Hughes's avatar
Phil Hughes committed
24
    full_title += group_title_link(group)
Sam Rose's avatar
Sam Rose committed
25
    full_title += ' &middot; '.html_safe + link_to(simple_sanitize(name), url, class: 'group-path') if name
26

Sam Rose's avatar
Sam Rose committed
27
    content_tag :span, class: 'group-title' do
28
      full_title.html_safe
29 30
    end
  end
31

32 33 34 35 36 37 38
  def projects_lfs_status(group)
    lfs_status =
      if group.lfs_enabled?
        group.projects.select(&:lfs_enabled?).size
      else
        group.projects.reject(&:lfs_enabled?).size
      end
39

40 41
    size = group.projects.size

42 43
    if lfs_status == size
      'for all projects'
44
    else
45
      "for #{lfs_status} out of #{pluralize(size, 'project')}"
46 47 48 49
    end
  end

  def group_lfs_status(group)
50 51 52
    status = group.lfs_enabled? ? 'enabled' : 'disabled'

    content_tag(:span, class: "lfs-#{status}") do
53
      "#{status.humanize} #{projects_lfs_status(group)}"
54
    end
55
  end
56 57 58 59

  def group_issues(group)
    IssuesFinder.new(current_user, group_id: group.id).execute
  end
Phil Hughes's avatar
Phil Hughes committed
60

61
  def remove_group_message(group)
62
    _("You are going to remove %{group_name}. Removed groups CANNOT be restored! Are you ABSOLUTELY sure?") %
63 64 65
      { group_name: group.name }
  end

Phil Hughes's avatar
Phil Hughes committed
66 67 68 69 70
  private

  def group_title_link(group, hidable: false)
    link_to(group_path(group), class: "group-path #{'hidable' if hidable}") do
      output =
Phil Hughes's avatar
Phil Hughes committed
71
        if show_new_nav? && !Rails.env.test?
Phil Hughes's avatar
Phil Hughes committed
72 73 74 75 76 77 78 79 80
          image_tag(group_icon(group), class: "avatar-tile", width: 16, height: 16)
        else
          ""
        end

      output << simple_sanitize(group.name)
      output.html_safe
    end
  end
81
end