diff options
author | Rubén Dávila <ruben@gitlab.com> | 2017-08-15 12:03:54 -0500 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2017-08-26 03:30:01 -0500 |
commit | a30257c0321e872646fe945739482fdeadbba4c2 (patch) | |
tree | 6e20ca077f869052fa16847023ef4a01fcb5b8c9 /app/helpers/namespaces_helper.rb | |
parent | 2be34630623711fc20ef8c101b5cef688f207cc1 (diff) | |
download | gitlab-ce-a30257c0321e872646fe945739482fdeadbba4c2.tar.gz |
Add some data attributes for options in namespace selector
Diffstat (limited to 'app/helpers/namespaces_helper.rb')
-rw-r--r-- | app/helpers/namespaces_helper.rb | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb index 7f656b8caae..df8b247aff5 100644 --- a/app/helpers/namespaces_helper.rb +++ b/app/helpers/namespaces_helper.rb @@ -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' @@ -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 @@ -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 |