Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
2eac1537
Commit
2eac1537
authored
Sep 04, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fetch children using new finder for the `show` of a group.
parent
ca538899
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
29 deletions
+32
-29
app/controllers/groups_controller.rb
app/controllers/groups_controller.rb
+4
-7
app/finders/group_children_finder.rb
app/finders/group_children_finder.rb
+20
-9
app/views/groups/_children.html.haml
app/views/groups/_children.html.haml
+4
-0
app/views/groups/_show_nav.html.haml
app/views/groups/_show_nav.html.haml
+0
-8
app/views/groups/show.html.haml
app/views/groups/show.html.haml
+1
-2
spec/finders/group_children_finder_spec.rb
spec/finders/group_children_finder_spec.rb
+3
-3
No files found.
app/controllers/groups_controller.rb
View file @
2eac1537
...
...
@@ -45,18 +45,15 @@ class GroupsController < Groups::ApplicationController
end
def
show
setup_projects
@children
=
GroupChildrenFinder
.
new
(
current_user
,
parent_group:
@group
,
params:
params
).
execute
@children
=
@children
.
page
(
params
[
:page
])
respond_to
do
|
format
|
format
.
html
format
.
json
do
render
json:
{
html:
view_to_html_string
(
"dashboard/projects/_projects"
,
locals:
{
projects:
@projects
})
}
end
format
.
atom
do
setup_projects
load_events
render
layout:
'xml.atom'
end
...
...
app/finders/group_children_finder.rb
View file @
2eac1537
...
...
@@ -16,27 +16,38 @@ class GroupChildrenFinder
# This allows us to fetch only the count without loading the objects. Unless
# the objects were already loaded.
def
total_count
@total_count
||=
if
defined?
(
@children
)
children
.
size
@total_count
||=
subgroup_count
+
project_count
end
def
subgroup_count
@subgroup_count
||=
if
defined?
(
@children
)
children
.
count
{
|
child
|
child
.
is_a?
(
Group
)
}
else
subgroups
.
count
end
end
def
project_count
@project_count
||=
if
defined?
(
@children
)
children
.
count
{
|
child
|
child
.
is_a?
(
Project
)
}
else
child_groups
.
count
+
projects
.
count
projects
.
count
end
end
private
def
children
@children
||=
child_
groups
+
projects
@children
||=
sub
groups
+
projects
end
def
child_
groups
def
sub
groups
return
Group
.
none
unless
Group
.
supports_nested_groups?
return
Group
.
none
unless
can?
(
current_user
,
:read_group
,
parent_group
)
groups
=
GroupsFinder
.
new
(
current_user
,
parent:
parent_group
,
all_available:
true
,
all_children_for_parent:
params
[
:filter_groups
].
present?
).
execute
all_available:
true
).
execute
groups
=
groups
.
search
(
params
[
:filter
])
if
params
[
:filter
].
present?
groups
=
groups
.
includes
(
:route
).
includes
(
:children
)
...
...
app/views/groups/_children.html.haml
0 → 100644
View file @
2eac1537
-
if
children
.
any?
render children here
-
else
.nothing-here-block
No children found
app/views/groups/_show_nav.html.haml
deleted
100644 → 0
View file @
ca538899
%ul
.nav-links
=
nav_link
(
page:
group_path
(
@group
))
do
=
link_to
group_path
(
@group
)
do
Projects
-
if
Group
.
supports_nested_groups?
=
nav_link
(
page:
subgroups_group_path
(
@group
))
do
=
link_to
subgroups_group_path
(
@group
)
do
Subgroups
app/views/groups/show.html.haml
View file @
2eac1537
...
...
@@ -8,7 +8,6 @@
.groups-header
{
class:
container_class
}
.top-area
=
render
'groups/show_nav'
.nav-controls
=
render
'shared/projects/search_form'
=
render
'shared/projects/dropdown'
...
...
@@ -16,4 +15,4 @@
=
link_to
new_project_path
(
namespace_id:
@group
.
id
),
class:
'btn btn-new pull-right'
do
New Project
=
render
"
projects"
,
projects:
@projects
=
render
"
children"
,
children:
@children
spec/finders/group_children_finder_spec.rb
View file @
2eac1537
...
...
@@ -52,16 +52,16 @@ describe GroupChildrenFinder do
describe
'#total_count'
do
it
'counts the array children were already loaded'
do
finder
.
instance_variable_set
(
:@children
,
[
double
])
finder
.
instance_variable_set
(
:@children
,
[
build
(
:project
)
])
expect
(
finder
).
not_to
receive
(
:
child_
groups
)
expect
(
finder
).
not_to
receive
(
:
sub
groups
)
expect
(
finder
).
not_to
receive
(
:projects
)
expect
(
finder
.
total_count
).
to
eq
(
1
)
end
it
'performs a count without loading children when they are not loaded yet'
do
expect
(
finder
).
to
receive
(
:
child_
groups
).
and_call_original
expect
(
finder
).
to
receive
(
:
sub
groups
).
and_call_original
expect
(
finder
).
to
receive
(
:projects
).
and_call_original
expect
(
finder
.
total_count
).
to
eq
(
2
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment