From 120c8394bbc0141a2ca6d2cd7124d8fbad459073 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 23 Nov 2015 19:18:00 -0800 Subject: [PATCH] Fixes #1380 - groups pagination --- app/config/version.php | 2 +- app/controllers/admin/GroupsController.php | 77 +++++++++++++++++- app/routes.php | 5 ++ app/views/backend/groups/index.blade.php | 93 ++++++++++++++-------- 4 files changed, 140 insertions(+), 37 deletions(-) diff --git a/app/config/version.php b/app/config/version.php index cc844071a1..ed1d1e6150 100644 --- a/app/config/version.php +++ b/app/config/version.php @@ -1,5 +1,5 @@ 'v2.0.5-pre', - 'hash_version' => 'v2.0.5-pre-131-g4a49e6f', + 'hash_version' => 'v2.0.5-pre-133-gc24f172', ); \ No newline at end of file diff --git a/app/controllers/admin/GroupsController.php b/app/controllers/admin/GroupsController.php index eb394c67ef..74105f8981 100755 --- a/app/controllers/admin/GroupsController.php +++ b/app/controllers/admin/GroupsController.php @@ -22,9 +22,6 @@ class GroupsController extends AdminController */ public function getIndex() { - // Grab all the groups - $groups = Sentry::getGroupProvider()->createModel()->paginate(); - // Show the page return View::make('backend/groups/index', compact('groups')); } @@ -215,4 +212,78 @@ class GroupsController extends AdminController } } + + + public function getDatatable($status = null) + { + + if (Input::has('offset')) { + $offset = e(Input::get('offset')); + } else { + $offset = 0; + } + + if (Input::has('limit')) { + $limit = e(Input::get('limit')); + } else { + $limit = 50; + } + + if (Input::get('sort')=='name') { + $sort = 'first_name'; + } else { + $sort = e(Input::get('sort')); + } + + // Grab all the groups + $groups = Sentry::getGroupProvider()->createModel(); + //$users = Company::scopeCompanyables($users); + + if (Input::has('search')) { + $groups = $users->TextSearch(Input::get('search')); + } + + $order = Input::get('order') === 'asc' ? 'asc' : 'desc'; + + $allowed_columns = + [ + 'name','created_at' + ]; + + $sort = in_array($sort, $allowed_columns) ? $sort : 'name'; + $groups = $groups->orderBy($sort, $order); + + $groupsCount = $groups->count(); + $groups = $groups->skip($offset)->take($limit)->get(); + $rows = array(); + + foreach ($groups as $group) + { + $group_names = ''; + $inout = ''; + $actions = ''; + + $actions .= ' '; + + if (!Config::get('app.lock_passwords')) { + $actions .= ' '; + } else { + $actions .= ' '; + } + + $actions .= ''; + + $rows[] = array( + 'id' => $group->id, + 'name' => $group->name, + 'users' => $group->users->count(), + 'created_at' => $group->created_at->format('Y-m-d H:i:s'), + 'actions' => ($actions) ? $actions : '', + ); + } + + $data = array('total'=>$groupsCount, 'rows'=>$rows); + return $data; + } + } diff --git a/app/routes.php b/app/routes.php index 321a9e110d..6a7b35abb0 100755 --- a/app/routes.php +++ b/app/routes.php @@ -80,6 +80,11 @@ Route::get( 'list/{status?}', [ 'as' => 'api.users.list', 'uses' => 'UsersController@getDatatable' ] ); } ); + /*---Groups API---*/ + Route::group( [ 'prefix' => 'groups' ], function () { + Route::get( 'list', [ 'as' => 'api.groups.list', 'uses' => 'GroupsController@getDatatable' ] ); + } ); + /*---Licenses API---*/ Route::group( [ 'prefix' => 'licenses' ], function () { diff --git a/app/views/backend/groups/index.blade.php b/app/views/backend/groups/index.blade.php index 89acb7767e..6f7dccb5a2 100755 --- a/app/views/backend/groups/index.blade.php +++ b/app/views/backend/groups/index.blade.php @@ -18,41 +18,68 @@ +
+ + + + + + + + + + + +
@lang('general.id')@lang('admin/groups/table.name')@lang('admin/groups/table.users')@lang('general.created_at'){{ Lang::get('table.actions') }}
-
-
- - - - - - - - - - - @if ($groups->count() >= 1) - @foreach ($groups as $group) - - - - - - - @endforeach - @else - - - - @endif - -
@lang('admin/groups/table.name')@lang('admin/groups/table.users')@lang('general.created_at')@lang('table.actions')
{{ $group->name }}{{ $group->users()->count() }}{{ $group->created_at->diffForHumans() }} - - name) }}?" onClick="return false;"> -
@lang('general.no_results')
+@section('moar_scripts') + + + + + + + +@stop @stop