diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-09-13 17:16:30 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-04 22:49:41 +0200 |
commit | 3a4dc55f2924debcdbb37eb63d8ce57b1358df81 (patch) | |
tree | 614d82e8b26b5c2698c564d9e244a86c35d714fe /app/controllers | |
parent | 39df53ff0aeac24d390eea52a1df6dfe103a4c14 (diff) | |
download | gitlab-ce-3a4dc55f2924debcdbb37eb63d8ce57b1358df81.tar.gz |
Reuse the groups tree for explore and dashboard.
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/concerns/group_tree.rb | 19 | ||||
-rw-r--r-- | app/controllers/dashboard/groups_controller.rb | 20 | ||||
-rw-r--r-- | app/controllers/explore/groups_controller.rb | 16 |
3 files changed, 26 insertions, 29 deletions
diff --git a/app/controllers/concerns/group_tree.rb b/app/controllers/concerns/group_tree.rb new file mode 100644 index 00000000000..6d5682ff769 --- /dev/null +++ b/app/controllers/concerns/group_tree.rb @@ -0,0 +1,19 @@ +module GroupTree + def render_group_tree(groups) + # Only show root groups if no parent-id is given + @groups = groups.where(parent_id: params[:parent_id]) + @groups = @groups.search(params[:filter]) if params[:filter].present? + @groups = @groups.includes(:route) + @groups = @groups.sort(@sort = params[:sort]) + @groups = @groups.page(params[:page]) + + respond_to do |format| + format.html + format.json do + serializer = GroupChildSerializer.new(current_user: current_user) + .with_pagination(request, response) + render json: serializer.represent(@groups) + end + end + end +end diff --git a/app/controllers/dashboard/groups_controller.rb b/app/controllers/dashboard/groups_controller.rb index 6488e0b6c09..025769f512a 100644 --- a/app/controllers/dashboard/groups_controller.rb +++ b/app/controllers/dashboard/groups_controller.rb @@ -1,20 +1,8 @@ class Dashboard::GroupsController < Dashboard::ApplicationController - def index - @groups = GroupsFinder.new(current_user, all_available: false).execute - # Only show root groups if no parent-id is given - @groups = @groups.where(parent_id: params[:parent_id]) - @groups = @groups.search(params[:filter]) if params[:filter].present? - @groups = @groups.includes(:route) - @groups = @groups.sort(@sort = params[:sort]) - @groups = @groups.page(params[:page]) + include GroupTree - respond_to do |format| - format.html - format.json do - serializer = GroupChildSerializer.new(current_user: current_user) - .with_pagination(request, response) - render json: serializer.represent(@groups) - end - end + def index + groups = GroupsFinder.new(current_user, all_available: false).execute + render_group_tree(groups) end end diff --git a/app/controllers/explore/groups_controller.rb b/app/controllers/explore/groups_controller.rb index 81883c543ba..fa0a0f68fbc 100644 --- a/app/controllers/explore/groups_controller.rb +++ b/app/controllers/explore/groups_controller.rb @@ -1,17 +1,7 @@ class Explore::GroupsController < Explore::ApplicationController - def index - @groups = GroupsFinder.new(current_user).execute - @groups = @groups.search(params[:filter_groups]) if params[:filter_groups].present? - @groups = @groups.sort(@sort = params[:sort]) - @groups = @groups.page(params[:page]) + include GroupTree - respond_to do |format| - format.html - format.json do - render json: { - html: view_to_html_string("explore/groups/_groups", locals: { groups: @groups }) - } - end - end + def index + render_group_tree GroupsFinder.new(current_user).execute end end |