Commit 81f8114f24313bb90f09f5ed1ff656759cb55020
1 parent
039996bd
Exists in
master
and in
4 other branches
NamespacesHelper
Showing
2 changed files
with
26 additions
and
22 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -74,28 +74,6 @@ module ApplicationHelper |
74 | 74 | grouped_options_for_select(options, @ref || @project.default_branch) |
75 | 75 | end |
76 | 76 | |
77 | - def namespaces_options(selected = :current_user, scope = :default) | |
78 | - groups = current_user.namespaces.select {|n| n.type == 'Group'} | |
79 | - | |
80 | - users = if scope == :all | |
81 | - Namespace.root | |
82 | - else | |
83 | - current_user.namespaces.reject {|n| n.type == 'Group'} | |
84 | - end | |
85 | - | |
86 | - options = [ | |
87 | - ["Global", [['/', Namespace.global_id]] ], | |
88 | - ["Groups", groups.map {|g| [g.human_name, g.id]} ], | |
89 | - [ "Users", users.map {|u| [u.human_name, u.id]} ] | |
90 | - ] | |
91 | - | |
92 | - if selected == :current_user && current_user.namespace | |
93 | - selected = current_user.namespace.id | |
94 | - end | |
95 | - | |
96 | - grouped_options_for_select(options, selected) | |
97 | - end | |
98 | - | |
99 | 77 | def search_autocomplete_source |
100 | 78 | projects = current_user.projects.map{ |p| { label: p.name_with_namespace, url: project_path(p) } } |
101 | 79 | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +module NamespacesHelper | |
2 | + def namespaces_options(selected = :current_user, scope = :default) | |
3 | + groups = current_user.namespaces.select {|n| n.type == 'Group'} | |
4 | + | |
5 | + users = if scope == :all | |
6 | + Namespace.root | |
7 | + else | |
8 | + current_user.namespaces.reject {|n| n.type == 'Group'} | |
9 | + end | |
10 | + | |
11 | + global_opts = ["Global", [['/', Namespace.global_id]] ] | |
12 | + group_opts = ["Groups", groups.map {|g| [g.human_name, g.id]} ] | |
13 | + users_opts = [ "Users", users.map {|u| [u.human_name, u.id]} ] | |
14 | + | |
15 | + options = [] | |
16 | + options << global_opts if current_user.admin | |
17 | + options << group_opts | |
18 | + options << users_opts | |
19 | + | |
20 | + if selected == :current_user && current_user.namespace | |
21 | + selected = current_user.namespace.id | |
22 | + end | |
23 | + | |
24 | + grouped_options_for_select(options, selected) | |
25 | + end | |
26 | +end | ... | ... |