Commit 5bce197b authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Serialize groups as json for Dashboard::GroupsController

Signed-off-by: Dmitriy Zaporozhets's avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 17dca783
class Dashboard::GroupsController < Dashboard::ApplicationController
def index
@group_members = current_user.group_members.includes(source: :route).joins(:group)
@group_members = @group_members.merge(Group.search(params[:filter_groups])) if params[:filter_groups].present?
@group_members = @group_members.merge(Group.sort(@sort = params[:sort]))
@group_members = @group_members.page(params[:page])
@groups = if params[:parent_id]
parent = Group.find(params[:parent_id])
if parent.users_with_parents.find_by(id: current_user)
Group.where(id: parent.children)
else
Group.none
end
else
Group.joins(:group_members).merge(current_user.group_members)
end
@groups = @groups.search(params[:filter_groups]) if params[:filter_groups].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
render json: {
html: view_to_html_string("dashboard/groups/_groups", locals: { group_members: @group_members })
}
render json: GroupSerializer
.new(current_user: @current_user)
.with_pagination(request, response)
.represent(@groups)
end
end
end
......
class GroupEntity < Grape::Entity
include RequestAwareEntity
expose :id, :name, :path, :description, :visibility
expose :avatar_url
expose :web_url
expose :full_name, :full_path
expose :parent_id
expose :created_at, :updated_at
expose :permissions do
expose :group_access do |group, options|
group.group_members.find_by(user_id: request.current_user)&.access_level
end
end
end
class GroupSerializer < BaseSerializer
entity GroupEntity
def with_pagination(request, response)
tap { @paginator = Gitlab::Serializer::Pagination.new(request, response) }
end
def paginated?
@paginator.present?
end
def represent(resource, opts = {})
if paginated?
super(@paginator.paginate(resource), opts)
else
super(resource, opts)
end
end
end
.js-groups-list-holder
%ul.content-list
- @group_members.each do |group_member|
- @groups.each do |group|
- group_member = group.group_members.find_by(user_id: current_user)
= render 'shared/groups/group', group: group_member.group, group_member: group_member
= paginate @group_members, theme: 'gitlab'
= paginate @groups, theme: 'gitlab'
......@@ -2,7 +2,7 @@
- header_title "Groups", dashboard_groups_path
= render 'dashboard/groups_head'
- if @group_members.empty?
- if @groups.empty?
= render 'empty_state'
- else
= render 'groups'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment