mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-13 17:14:10 -08:00
Added manufacturer sorting on models
This commit is contained in:
parent
2c0df6159f
commit
98e0ecbd88
|
@ -29,21 +29,31 @@ class AssetModelsController extends Controller
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('view', AssetModel::class);
|
$this->authorize('view', AssetModel::class);
|
||||||
$allowed_columns = ['id','image','name','model_number','eol','notes','created_at'];
|
$allowed_columns = ['id','image','name','model_number','eol','notes','created_at','manufacturer'];
|
||||||
|
|
||||||
$assetmodels = AssetModel::select(['id','image','name','model_number','eol','notes','created_at','category_id','manufacturer_id','depreciation_id','fieldset_id'])
|
$assetmodels = AssetModel::select(['models.id','models.image','models.name','model_number','eol','models.notes','models.created_at','category_id','manufacturer_id','depreciation_id','fieldset_id'])
|
||||||
->with('category','depreciation', 'manufacturer','fieldset')
|
->with('category','depreciation', 'manufacturer','fieldset')
|
||||||
->withCount('assets');
|
->withCount('assets');
|
||||||
|
|
||||||
if ($request->has('search')) {
|
if ($request->has('search')) {
|
||||||
$assetmodels = $assetmodels->TextSearch($request->input('search'));
|
$assetmodels->TextSearch($request->input('search'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$offset = $request->input('offset', 0);
|
$offset = $request->input('offset', 0);
|
||||||
$limit = $request->input('limit', 50);
|
$limit = $request->input('limit', 50);
|
||||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
$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') : 'models.created_at';
|
||||||
|
|
||||||
|
switch ($sort) {
|
||||||
|
case 'manufacturer':
|
||||||
|
$assetmodels->OrderManufacturer($order);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
$assetmodels->orderBy($sort, $order);
|
$assetmodels->orderBy($sort, $order);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$total = $assetmodels->count();
|
$total = $assetmodels->count();
|
||||||
$assetmodels = $assetmodels->skip($offset)->take($limit)->get();
|
$assetmodels = $assetmodels->skip($offset)->take($limit)->get();
|
||||||
|
|
|
@ -168,4 +168,19 @@ class AssetModel extends SnipeModel
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query builder scope to order on manufacturer
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||||
|
* @param text $order Order
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||||
|
*/
|
||||||
|
public function scopeOrderManufacturer($query, $order)
|
||||||
|
{
|
||||||
|
return $query->leftJoin('manufacturers', 'models.manufacturer_id', '=', 'manufacturers.id')->orderBy('manufacturers.name', $order);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,7 @@
|
||||||
|
|
||||||
{{-- Page title --}}
|
{{-- Page title --}}
|
||||||
@section('header_right')
|
@section('header_right')
|
||||||
@if(Input::get('status')=='Deleted')
|
|
||||||
<a href="{{ url('hardware/models') }}" class="btn btn-default pull-right" style="margin-right:5px;"><i class="fa fa-trash"></i> {{ trans('admin/models/general.view_models') }}</a>
|
|
||||||
@else
|
|
||||||
<a href="{{ route('models.create') }}" class="btn btn-primary pull-right">
|
|
||||||
{{ trans('general.create') }}</a>
|
|
||||||
<a href="{{ url('hardware/models?status=Deleted') }}" class="btn btn-default pull-right" style="margin-right:5px;"><i class="fa fa-trash"></i> {{ trans('admin/models/general.view_deleted') }}</a>
|
<a href="{{ url('hardware/models?status=Deleted') }}" class="btn btn-default pull-right" style="margin-right:5px;"><i class="fa fa-trash"></i> {{ trans('admin/models/general.view_deleted') }}</a>
|
||||||
@endif
|
|
||||||
@stop
|
@stop
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +33,7 @@
|
||||||
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
|
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
|
||||||
<th data-sortable="true" data-field="name" data-formatter="modelsLinkFormatter">{{ trans('general.name') }}</th>
|
<th data-sortable="true" data-field="name" data-formatter="modelsLinkFormatter">{{ trans('general.name') }}</th>
|
||||||
<th data-sortable="true" data-field="image" data-formatter="imageFormatter" data-visible="false">{{ trans('admin/hardware/table.image') }}</th>
|
<th data-sortable="true" data-field="image" data-formatter="imageFormatter" data-visible="false">{{ trans('admin/hardware/table.image') }}</th>
|
||||||
<th data-sortable="false" data-field="manufacturer" data-formatter="manufacturersLinkObjFormatter">{{ trans('general.manufacturer') }}</th>
|
<th data-sortable="true" data-field="manufacturer" data-formatter="manufacturersLinkObjFormatter">{{ trans('general.manufacturer') }}</th>
|
||||||
|
|
||||||
<th data-sortable="true" data-field="model_number">{{ trans('admin/models/table.modelnumber') }}</th>
|
<th data-sortable="true" data-field="model_number">{{ trans('admin/models/table.modelnumber') }}</th>
|
||||||
<th data-sortable="false" data-field="assets_count">{{ trans('admin/models/table.numassets') }}</th>
|
<th data-sortable="false" data-field="assets_count">{{ trans('admin/models/table.numassets') }}</th>
|
||||||
|
|
Loading…
Reference in a new issue