2015-04-30 13:06:18 -04:00
|
|
|
class Dashboard::GroupsController < Dashboard::ApplicationController
|
2013-07-12 11:22:03 -04:00
|
|
|
def index
|
2017-05-04 16:45:02 -04:00
|
|
|
@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])
|
2017-03-01 08:31:56 -05:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
2017-05-04 16:45:02 -04:00
|
|
|
render json: GroupSerializer
|
|
|
|
.new(current_user: @current_user)
|
|
|
|
.with_pagination(request, response)
|
|
|
|
.represent(@groups)
|
2017-03-01 08:31:56 -05:00
|
|
|
end
|
|
|
|
end
|
2013-07-12 11:22:03 -04:00
|
|
|
end
|
|
|
|
end
|