Commit a30257c0 authored by Rubén Dávila's avatar Rubén Dávila Committed by Mike Greiling

Add some data attributes for options in namespace selector

parent 2be34630
...@@ -4,7 +4,9 @@ module NamespacesHelper ...@@ -4,7 +4,9 @@ module NamespacesHelper
end end
def namespaces_options(selected = :current_user, display_path: false, extra_group: nil) 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) unless extra_group.nil? || extra_group.is_a?(Group)
extra_group = Group.find(extra_group) if Namespace.find(extra_group).kind == 'group' extra_group = Group.find(extra_group) if Namespace.find(extra_group).kind == 'group'
...@@ -14,22 +16,8 @@ module NamespacesHelper ...@@ -14,22 +16,8 @@ module NamespacesHelper
groups |= [extra_group] groups |= [extra_group]
end end
users = [current_user.namespace] options << options_for_group(groups, display_path)
options << options_for_group(users, display_path)
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
if selected == :current_user && current_user.namespace if selected == :current_user && current_user.namespace
selected = current_user.namespace.id selected = current_user.namespace.id
...@@ -45,4 +33,17 @@ module NamespacesHelper ...@@ -45,4 +33,17 @@ module NamespacesHelper
avatar_icon(namespace.owner.email, size) avatar_icon(namespace.owner.email, size)
end end
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 end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment