Skip to content
Snippets Groups Projects
Commit a30257c0 authored by Rubén Dávila's avatar Rubén Dávila Committed by Mike Greiling
Browse files

Add some data attributes for options in namespace selector

parent 2be34630
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -4,7 +4,9 @@ module NamespacesHelper
end
 
def namespaces_options(selected = :current_user, display_path: false, extra_group: nil)
groups = current_user.owned_groups + current_user.masters_groups
groups = current_user.owned_groups + current_user.masters_groups
users = [current_user.namespace]
options = []
 
unless extra_group.nil? || extra_group.is_a?(Group)
extra_group = Group.find(extra_group) if Namespace.find(extra_group).kind == 'group'
Loading
Loading
@@ -14,22 +16,8 @@ module NamespacesHelper
groups |= [extra_group]
end
 
users = [current_user.namespace]
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.full_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] }
]
options = []
options << group_opts
options << users_opts
options << options_for_group(groups, display_path)
options << options_for_group(users, display_path)
 
if selected == :current_user && current_user.namespace
selected = current_user.namespace.id
Loading
Loading
@@ -45,4 +33,17 @@ module NamespacesHelper
avatar_icon(namespace.owner.email, size)
end
end
private
def options_for_group(namespaces, display_path)
type = namespaces.first.is_a?(Group) ? 'group' : 'users'
elements = namespaces.sort_by(&:human_name).map! do |n|
[display_path ? n.full_path : n.human_name, n.id,
data: { options_parent: type, visibility_level: n.visibility_level_value, name: n.human_name }]
end
[type.camelize, elements]
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment