diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-09-08 20:22:33 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-04 23:49:41 +0300 |
commit | 8f6dac4991ba7f5771a24175784f19dc1bbd4103 (patch) | |
tree | 5d4f4c06f6bd56db03474dd5d97002d82331a91e /app/serializers/group_child_serializer.rb | |
parent | 518216c0627cb6c4b3db62f10877b44d0e912ddb (diff) |
Allow filtering children for a group
When fetching children for a group with a filter, we will search all
nested groups for results and render them in an expanded tree
Diffstat (limited to 'app/serializers/group_child_serializer.rb')
-rw-r--r-- | app/serializers/group_child_serializer.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/app/serializers/group_child_serializer.rb b/app/serializers/group_child_serializer.rb index ed84c3ae1d7..363f0c9b3d8 100644 --- a/app/serializers/group_child_serializer.rb +++ b/app/serializers/group_child_serializer.rb @@ -18,11 +18,14 @@ class GroupChildSerializer < BaseSerializer end end + protected + def represent_hierarchies(children, opts) if children.is_a?(GroupHierarchy) - represent_hierarchy(children.hierarchy(hierarchy_root), opts) + represent_hierarchy(children.hierarchy(hierarchy_root), opts).first else - children.map { |child| represent_hierarchy(child.hierarchy(hierarchy_root), opts) } + hierarchies = Array.wrap(GroupHierarchy.merge_hierarchies(children, hierarchy_root)) + hierarchies.map { |hierarchy| represent_hierarchy(hierarchy, opts) }.flatten end end @@ -30,9 +33,10 @@ class GroupChildSerializer < BaseSerializer serializer = self.class.new(parameters) result = if hierarchy.is_a?(Hash) - parent = hierarchy.keys.first - serializer.represent(parent, opts) - .merge(children: [serializer.represent_hierarchy(hierarchy[parent], opts)]) + 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 |