2012-11-27 15:48:25 +00:00
|
|
|
module NamespacesHelper
|
2016-09-19 10:29:49 +00:00
|
|
|
def namespaces_options(selected = :current_user, display_path: false, extra_group: nil)
|
2014-05-28 16:04:42 +00:00
|
|
|
groups = current_user.owned_groups + current_user.masters_groups
|
2016-08-08 13:05:58 +00:00
|
|
|
|
2016-09-19 10:29:49 +00:00
|
|
|
groups << extra_group if extra_group && !Group.exists?(name: extra_group.name)
|
2016-08-08 13:05:58 +00:00
|
|
|
|
2013-11-05 15:15:43 +00:00
|
|
|
users = [current_user.namespace]
|
2012-11-27 15:48:25 +00:00
|
|
|
|
2016-04-12 13:41:34 +00:00
|
|
|
data_attr_group = { 'data-options-parent' => 'groups' }
|
|
|
|
data_attr_users = { 'data-options-parent' => 'users' }
|
|
|
|
|
|
|
|
group_opts = [
|
|
|
|
"Groups", groups.sort_by(&:human_name).map { |g| [display_path ? g.path : g.human_name, g.id, data_attr_group] }
|
|
|
|
]
|
|
|
|
|
|
|
|
users_opts = [
|
|
|
|
"Users", users.sort_by(&:human_name).map { |u| [display_path ? u.path : u.human_name, u.id, data_attr_users] }
|
|
|
|
]
|
2012-11-27 15:48:25 +00:00
|
|
|
|
|
|
|
options = []
|
|
|
|
options << group_opts
|
|
|
|
options << users_opts
|
|
|
|
|
|
|
|
if selected == :current_user && current_user.namespace
|
|
|
|
selected = current_user.namespace.id
|
|
|
|
end
|
|
|
|
|
|
|
|
grouped_options_for_select(options, selected)
|
|
|
|
end
|
2013-11-15 13:25:09 +00:00
|
|
|
|
2014-11-14 14:06:39 +00:00
|
|
|
def namespace_icon(namespace, size = 40)
|
|
|
|
if namespace.kind_of?(Group)
|
2015-03-12 20:56:53 +00:00
|
|
|
group_icon(namespace)
|
2014-11-14 14:06:39 +00:00
|
|
|
else
|
|
|
|
avatar_icon(namespace.owner.email, size)
|
|
|
|
end
|
|
|
|
end
|
2012-11-27 15:48:25 +00:00
|
|
|
end
|