mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-24 04:03:34 -08:00
Allows sorting by number of assets, etc in category
This commit is contained in:
parent
f6a38e848a
commit
54000ff69f
|
@ -20,7 +20,7 @@ class CategoriesController extends Controller
|
|||
public function index(Request $request)
|
||||
{
|
||||
$this->authorize('view', Category::class);
|
||||
$allowed_columns = ['id', 'name','category_type','use_default_eula','eula_text', 'require_acceptance','checkin_email'];
|
||||
$allowed_columns = ['id', 'name','category_type','use_default_eula','eula_text', 'require_acceptance','checkin_email', 'assets_count', 'accessories_count', 'consumables_count', 'components_count'];
|
||||
|
||||
$categories = Category::select(['id', 'created_at', 'updated_at', 'name','category_type','use_default_eula','eula_text', 'require_acceptance','checkin_email'])
|
||||
->withCount('assets', 'accessories', 'consumables', 'components');
|
||||
|
@ -32,7 +32,7 @@ class CategoriesController extends Controller
|
|||
$offset = $request->input('offset', 0);
|
||||
$limit = $request->input('limit', 50);
|
||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
|
||||
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'assets_count';
|
||||
$categories->orderBy($sort, $order);
|
||||
|
||||
$total = $categories->count();
|
||||
|
|
|
@ -41,25 +41,25 @@ class CategoryPresenter extends Presenter
|
|||
], [
|
||||
"field" => "assets_count",
|
||||
"searchable" => false,
|
||||
"sortable" => false,
|
||||
"sortable" => true,
|
||||
"title" => trans('general.assets'),
|
||||
"visible" => true
|
||||
], [
|
||||
"field" => "accessories_count",
|
||||
"searchable" => false,
|
||||
"sortable" => false,
|
||||
"sortable" => true,
|
||||
"title" => trans('general.accessories'),
|
||||
"visible" => true
|
||||
], [
|
||||
"field" => "consumables_count",
|
||||
"searchable" => false,
|
||||
"sortable" => false,
|
||||
"sortable" => true,
|
||||
"title" => trans('general.consumables'),
|
||||
"visible" => true
|
||||
], [
|
||||
"field" => "components_count",
|
||||
"searchable" => false,
|
||||
"sortable" => false,
|
||||
"sortable" => true,
|
||||
"title" => trans('general.components'),
|
||||
"visible" => true
|
||||
], [
|
||||
|
|
Loading…
Reference in a new issue