summaryrefslogtreecommitdiff
path: root/app/serializers
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-09-15 12:28:21 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2017-10-04 22:49:41 +0200
commit9781ac552d4ae41983b2d95768e0fb06817e0ef9 (patch)
tree8beef5af5c8ac701ce53fcf47591d0ea1f6aff32 /app/serializers
parent20a08965bc949ea233cdde4e777698222fcabff2 (diff)
downloadgitlab-ce-9781ac552d4ae41983b2d95768e0fb06817e0ef9.tar.gz
Include pagination when rendering expanded hierarchies
Diffstat (limited to 'app/serializers')
-rw-r--r--app/serializers/concerns/with_pagination.rb6
-rw-r--r--app/serializers/group_child_serializer.rb32
2 files changed, 21 insertions, 17 deletions
diff --git a/app/serializers/concerns/with_pagination.rb b/app/serializers/concerns/with_pagination.rb
index 484c6855f7c..d29e22d6740 100644
--- a/app/serializers/concerns/with_pagination.rb
+++ b/app/serializers/concerns/with_pagination.rb
@@ -1,10 +1,12 @@
module WithPagination
+ attr_accessor :paginator
+
def with_pagination(request, response)
- tap { @paginator = Gitlab::Serializer::Pagination.new(request, response) }
+ tap { self.paginator = Gitlab::Serializer::Pagination.new(request, response) }
end
def paginated?
- @paginator.present?
+ paginator.present?
end
# super is `BaseSerializer#represent` here.
diff --git a/app/serializers/group_child_serializer.rb b/app/serializers/group_child_serializer.rb
index 65dd1ced2a3..fb47bf0b4eb 100644
--- a/app/serializers/group_child_serializer.rb
+++ b/app/serializers/group_child_serializer.rb
@@ -1,18 +1,20 @@
class GroupChildSerializer < BaseSerializer
include WithPagination
- attr_reader :hierarchy_root
+ attr_reader :hierarchy_root, :should_expand_hierarchy
entity GroupChildEntity
def expand_hierarchy(hierarchy_root = nil)
- @hierarchy_root = hierarchy_root
- @expand_hierarchy = true
- self
+ tap do
+ @hierarchy_root = hierarchy_root
+ @should_expand_hierarchy = true
+ end
end
def represent(resource, opts = {}, entity_class = nil)
- if @expand_hierarchy
+ if should_expand_hierarchy
+ paginator.paginate(resource) if paginated?
represent_hierarchies(resource, opts)
else
super(resource, opts)
@@ -33,15 +35,15 @@ class GroupChildSerializer < BaseSerializer
def represent_hierarchy(hierarchy, opts)
serializer = self.class.new(parameters)
- result = if hierarchy.is_a?(Hash)
- hierarchy.map do |parent, children|
- serializer.represent(parent, opts)
- .merge(children: Array.wrap(serializer.represent_hierarchy(children, opts)))
- end
- else
- serializer.represent(hierarchy, opts)
- end
-
- result
+ if hierarchy.is_a?(Hash)
+ hierarchy.map do |parent, children|
+ serializer.represent(parent, opts)
+ .merge(children: Array.wrap(serializer.represent_hierarchy(children, opts)))
+ end
+ elsif hierarchy.is_a?(Array)
+ hierarchy.map { |child| serializer.represent_hierarchy(child, opts) }
+ else
+ serializer.represent(hierarchy, opts)
+ end
end
end