2017-09-13 11:16:30 -04:00
|
|
|
module GroupTree
|
2017-11-22 02:50:36 -05:00
|
|
|
# rubocop:disable Gitlab/ModuleWithInstanceVariables
|
2017-09-13 11:16:30 -04:00
|
|
|
def render_group_tree(groups)
|
2017-10-09 06:02:40 -04:00
|
|
|
@groups = if params[:filter].present?
|
|
|
|
Gitlab::GroupHierarchy.new(groups.search(params[:filter]))
|
|
|
|
.base_and_ancestors
|
|
|
|
else
|
|
|
|
# Only show root groups if no parent-id is given
|
|
|
|
groups.where(parent_id: params[:parent_id])
|
|
|
|
end
|
2017-10-11 11:05:39 -04:00
|
|
|
@groups = @groups.with_selects_for_list(archived: params[:archived])
|
2017-10-02 04:36:34 -04:00
|
|
|
.sort(@sort = params[:sort])
|
|
|
|
.page(params[:page])
|
2017-09-13 11:16:30 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
|
|
|
serializer = GroupChildSerializer.new(current_user: current_user)
|
|
|
|
.with_pagination(request, response)
|
2017-09-14 03:01:29 -04:00
|
|
|
serializer.expand_hierarchy if params[:filter].present?
|
2017-09-13 11:16:30 -04:00
|
|
|
render json: serializer.represent(@groups)
|
|
|
|
end
|
|
|
|
end
|
2017-11-22 02:50:36 -05:00
|
|
|
# rubocop:enable Gitlab/ModuleWithInstanceVariables
|
2017-09-13 11:16:30 -04:00
|
|
|
end
|
|
|
|
end
|