2013-01-07 13:48:57 -05:00
|
|
|
module GroupsHelper
|
2016-03-01 10:22:29 -05:00
|
|
|
def can_change_group_visibility_level?(group)
|
|
|
|
can?(current_user, :change_visibility_level, group)
|
|
|
|
end
|
|
|
|
|
2015-03-12 16:56:53 -04:00
|
|
|
def group_icon(group)
|
|
|
|
if group.is_a?(String)
|
2016-10-31 07:00:53 -04:00
|
|
|
group = Group.find_by_full_path(group)
|
2015-03-12 16:56:53 -04:00
|
|
|
end
|
|
|
|
|
2017-06-06 20:21:53 -04:00
|
|
|
group.try(:avatar_url) || ActionController::Base.helpers.image_path('no_group_avatar.png')
|
2015-03-12 16:56:53 -04:00
|
|
|
end
|
2015-09-07 07:18:11 -04:00
|
|
|
|
2015-09-17 06:16:24 -04:00
|
|
|
def group_title(group, name = nil, url = nil)
|
2017-02-28 21:59:55 -05:00
|
|
|
@has_group_title = true
|
2016-12-08 11:28:49 -05:00
|
|
|
full_title = ''
|
|
|
|
|
2017-08-16 05:35:59 -04:00
|
|
|
group.ancestors.reverse.each_with_index do |parent, index|
|
2017-08-16 08:13:34 -04:00
|
|
|
if show_new_nav? && index > 0
|
2017-08-18 12:19:23 -04:00
|
|
|
add_to_breadcrumb_dropdown(group_title_link(parent, hidable: false, show_avatar: true), location: :before)
|
2017-08-16 08:13:34 -04:00
|
|
|
else
|
|
|
|
full_title += if show_new_nav?
|
|
|
|
breadcrumb_list_item group_title_link(parent, hidable: false)
|
|
|
|
else
|
2017-08-17 05:42:04 -04:00
|
|
|
"#{group_title_link(parent, hidable: true)} <span class='hidable'> / </span>".html_safe
|
2017-08-16 08:13:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if show_new_nav?
|
|
|
|
full_title += render "layouts/nav/breadcrumbs/collapsed_dropdown", location: :before, title: _("Show parent subgroups")
|
2016-12-08 11:28:49 -05:00
|
|
|
end
|
|
|
|
|
2017-08-16 05:35:59 -04:00
|
|
|
full_title += if show_new_nav?
|
|
|
|
breadcrumb_list_item group_title_link(group)
|
|
|
|
else
|
|
|
|
group_title_link(group)
|
|
|
|
end
|
2017-02-28 21:59:55 -05:00
|
|
|
full_title += ' · '.html_safe + link_to(simple_sanitize(name), url, class: 'group-path') if name
|
2015-09-17 06:16:24 -04:00
|
|
|
|
2017-08-16 05:35:59 -04:00
|
|
|
if show_new_nav?
|
2016-12-08 11:28:49 -05:00
|
|
|
full_title.html_safe
|
2017-08-16 05:35:59 -04:00
|
|
|
else
|
|
|
|
content_tag :span, class: 'group-title' do
|
|
|
|
full_title.html_safe
|
|
|
|
end
|
2015-09-07 07:18:11 -04:00
|
|
|
end
|
|
|
|
end
|
2016-09-01 19:49:48 -04:00
|
|
|
|
2016-09-06 12:48:00 -04:00
|
|
|
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
|
2016-09-05 16:40:49 -04:00
|
|
|
|
2016-09-05 14:14:49 -04:00
|
|
|
size = group.projects.size
|
|
|
|
|
2016-09-06 12:48:00 -04:00
|
|
|
if lfs_status == size
|
|
|
|
'for all projects'
|
2016-09-05 14:14:49 -04:00
|
|
|
else
|
2016-09-06 12:48:00 -04:00
|
|
|
"for #{lfs_status} out of #{pluralize(size, 'project')}"
|
2016-09-05 14:14:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_lfs_status(group)
|
2016-09-05 16:40:49 -04:00
|
|
|
status = group.lfs_enabled? ? 'enabled' : 'disabled'
|
|
|
|
|
|
|
|
content_tag(:span, class: "lfs-#{status}") do
|
2016-09-06 12:48:00 -04:00
|
|
|
"#{status.humanize} #{projects_lfs_status(group)}"
|
2016-09-05 14:14:49 -04:00
|
|
|
end
|
2016-09-01 19:49:48 -04:00
|
|
|
end
|
2016-11-05 13:28:29 -04:00
|
|
|
|
|
|
|
def group_issues(group)
|
|
|
|
IssuesFinder.new(current_user, group_id: group.id).execute
|
|
|
|
end
|
2017-06-30 12:52:11 -04:00
|
|
|
|
2017-07-04 11:18:51 -04:00
|
|
|
def remove_group_message(group)
|
2017-08-14 07:35:28 -04:00
|
|
|
_("You are going to remove %{group_name}. Removed groups CANNOT be restored! Are you ABSOLUTELY sure?") %
|
2017-07-04 11:18:51 -04:00
|
|
|
{ group_name: group.name }
|
|
|
|
end
|
|
|
|
|
2017-06-30 12:52:11 -04:00
|
|
|
private
|
|
|
|
|
2017-08-18 12:19:23 -04:00
|
|
|
def group_title_link(group, hidable: false, show_avatar: false)
|
2017-06-30 12:52:11 -04:00
|
|
|
link_to(group_path(group), class: "group-path #{'hidable' if hidable}") do
|
|
|
|
output =
|
2017-09-04 10:30:03 -04:00
|
|
|
if (show_new_nav? && group.try(:avatar_url) || (show_new_nav? && show_avatar)) && !Rails.env.test?
|
2017-09-05 06:25:28 -04:00
|
|
|
image_tag(group_icon(group), class: "avatar-tile", width: 15, height: 15)
|
2017-06-30 12:52:11 -04:00
|
|
|
else
|
|
|
|
""
|
|
|
|
end
|
|
|
|
|
|
|
|
output << simple_sanitize(group.name)
|
|
|
|
output.html_safe
|
|
|
|
end
|
|
|
|
end
|
2013-01-07 13:48:57 -05:00
|
|
|
end
|