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
9781ac55
Commit
9781ac55
authored
Sep 15, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include pagination when rendering expanded hierarchies
parent
20a08965
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
17 deletions
+33
-17
app/serializers/concerns/with_pagination.rb
app/serializers/concerns/with_pagination.rb
+4
-2
app/serializers/group_child_serializer.rb
app/serializers/group_child_serializer.rb
+17
-15
spec/controllers/groups_controller_spec.rb
spec/controllers/groups_controller_spec.rb
+12
-0
No files found.
app/serializers/concerns/with_pagination.rb
View file @
9781ac55
module
WithPagination
module
WithPagination
attr_accessor
:paginator
def
with_pagination
(
request
,
response
)
def
with_pagination
(
request
,
response
)
tap
{
@
paginator
=
Gitlab
::
Serializer
::
Pagination
.
new
(
request
,
response
)
}
tap
{
self
.
paginator
=
Gitlab
::
Serializer
::
Pagination
.
new
(
request
,
response
)
}
end
end
def
paginated?
def
paginated?
@
paginator
.
present?
paginator
.
present?
end
end
# super is `BaseSerializer#represent` here.
# super is `BaseSerializer#represent` here.
...
...
app/serializers/group_child_serializer.rb
View file @
9781ac55
class
GroupChildSerializer
<
BaseSerializer
class
GroupChildSerializer
<
BaseSerializer
include
WithPagination
include
WithPagination
attr_reader
:hierarchy_root
attr_reader
:hierarchy_root
,
:should_expand_hierarchy
entity
GroupChildEntity
entity
GroupChildEntity
def
expand_hierarchy
(
hierarchy_root
=
nil
)
def
expand_hierarchy
(
hierarchy_root
=
nil
)
@hierarchy_root
=
hierarchy_root
tap
do
@expand_hierarchy
=
true
@hierarchy_root
=
hierarchy_root
self
@should_expand_hierarchy
=
true
end
end
end
def
represent
(
resource
,
opts
=
{},
entity_class
=
nil
)
def
represent
(
resource
,
opts
=
{},
entity_class
=
nil
)
if
@expand_hierarchy
if
should_expand_hierarchy
paginator
.
paginate
(
resource
)
if
paginated?
represent_hierarchies
(
resource
,
opts
)
represent_hierarchies
(
resource
,
opts
)
else
else
super
(
resource
,
opts
)
super
(
resource
,
opts
)
...
@@ -33,15 +35,15 @@ class GroupChildSerializer < BaseSerializer
...
@@ -33,15 +35,15 @@ class GroupChildSerializer < BaseSerializer
def
represent_hierarchy
(
hierarchy
,
opts
)
def
represent_hierarchy
(
hierarchy
,
opts
)
serializer
=
self
.
class
.
new
(
parameters
)
serializer
=
self
.
class
.
new
(
parameters
)
result
=
if
hierarchy
.
is_a?
(
Hash
)
if
hierarchy
.
is_a?
(
Hash
)
hierarchy
.
map
do
|
parent
,
children
|
hierarchy
.
map
do
|
parent
,
children
|
serializer
.
represent
(
parent
,
opts
)
serializer
.
represent
(
parent
,
opts
)
.
merge
(
children:
Array
.
wrap
(
serializer
.
represent_hierarchy
(
children
,
opts
)))
.
merge
(
children:
Array
.
wrap
(
serializer
.
represent_hierarchy
(
children
,
opts
)))
end
end
else
elsif
hierarchy
.
is_a?
(
Array
)
serializer
.
represent
(
hierarchy
,
opts
)
hierarchy
.
map
{
|
child
|
serializer
.
represent_hierarchy
(
child
,
opts
)
}
end
else
serializer
.
represent
(
hierarchy
,
opts
)
result
end
end
end
end
end
spec/controllers/groups_controller_spec.rb
View file @
9781ac55
...
@@ -152,6 +152,10 @@ describe GroupsController do
...
@@ -152,6 +152,10 @@ describe GroupsController do
describe
'GET #show'
do
describe
'GET #show'
do
context
'pagination'
do
context
'pagination'
do
before
do
allow
(
Kaminari
.
config
).
to
receive
(
:default_per_page
).
and_return
(
2
)
end
context
'with only projects'
do
context
'with only projects'
do
let!
(
:other_project
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
let!
(
:other_project
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
let!
(
:first_page_projects
)
{
create_list
(
:project
,
Kaminari
.
config
.
default_per_page
,
:public
,
namespace:
group
)
}
let!
(
:first_page_projects
)
{
create_list
(
:project
,
Kaminari
.
config
.
default_per_page
,
:public
,
namespace:
group
)
}
...
@@ -288,6 +292,14 @@ describe GroupsController do
...
@@ -288,6 +292,14 @@ describe GroupsController do
expect
(
group_json
[
'id'
]).
to
eq
(
public_subgroup
.
id
)
expect
(
group_json
[
'id'
]).
to
eq
(
public_subgroup
.
id
)
expect
(
matched_group_json
[
'id'
]).
to
eq
(
matched_group
.
id
)
expect
(
matched_group_json
[
'id'
]).
to
eq
(
matched_group
.
id
)
end
end
it
'includes pagination headers'
do
2
.
times
{
|
i
|
create
(
:group
,
:public
,
parent:
public_subgroup
,
name:
"filterme
#{
i
}
"
)
}
get
:children
,
id:
group
.
to_param
,
filter:
'filter'
,
per_page:
1
,
format: :json
expect
(
response
).
to
include_pagination_headers
end
end
end
context
'queries per rendered element'
,
:request_store
do
context
'queries per rendered element'
,
:request_store
do
...
...
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