Commit 2eac1537 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Fetch children using new finder for the `show` of a group.

parent ca538899
......@@ -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
......
......@@ -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
else
child_groups.count + projects.count
end
@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
projects.count
end
end
private
def children
@children ||= child_groups + projects
@children ||= subgroups + projects
end
def child_groups
def subgroups
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)
......
- if children.any?
render children here
- else
.nothing-here-block No children found
%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
......@@ -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
......@@ -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(:subgroups)
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(:subgroups).and_call_original
expect(finder).to receive(:projects).and_call_original
expect(finder.total_count).to eq(2)
......
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