mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Fixed #6027 - added model to asset maintenances listing
This commit is contained in:
parent
6f8680efa6
commit
9168979d9e
|
@ -34,10 +34,10 @@ class AssetMaintenancesController extends Controller
|
|||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$maintenances = AssetMaintenance::with('asset', 'supplier', 'asset.company', 'admin');
|
||||
$maintenances = AssetMaintenance::with('asset', 'asset.model','asset.location', 'supplier', 'asset.company', 'admin');
|
||||
|
||||
if (Input::has('search')) {
|
||||
$maintenances = $maintenances->TextSearch(e($request->input('search')));
|
||||
if ($request->filled('search')) {
|
||||
$maintenances = $maintenances->TextSearch($request->input('search'));
|
||||
}
|
||||
|
||||
if ($request->filled('asset_id')) {
|
||||
|
|
|
@ -28,6 +28,10 @@ class AssetMaintenancesTransformer
|
|||
'asset_tag'=> e($assetmaintenance->asset->asset_tag)
|
||||
|
||||
] : null,
|
||||
'model' => ($assetmaintenance->asset->model) ? [
|
||||
'id' => (int) $assetmaintenance->asset->model->id,
|
||||
'name'=> ($assetmaintenance->asset->model->name) ? e($assetmaintenance->asset->model->name).' '.e($assetmaintenance->asset->model->model_number) : null
|
||||
] : null,
|
||||
'title' => ($assetmaintenance->title) ? e($assetmaintenance->title) : null,
|
||||
'location' => (($assetmaintenance->asset) && ($assetmaintenance->asset->location)) ? [
|
||||
'id' => (int) $assetmaintenance->asset->location->id,
|
||||
|
|
|
@ -48,7 +48,10 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchableRelations = [];
|
||||
protected $searchableRelations = [
|
||||
'asset' => ['name', 'asset_tag'],
|
||||
'asset.model' => ['name', 'model_number'],
|
||||
];
|
||||
|
||||
|
||||
public function getCompanyableParents()
|
||||
|
@ -152,6 +155,7 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
|||
->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* -----------------------------------------------
|
||||
* BEGIN QUERY SCOPES
|
||||
|
@ -162,10 +166,10 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
|||
/**
|
||||
* Query builder scope to order on admin user
|
||||
*
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
public function scopeOrderAdmin($query, $order)
|
||||
{
|
||||
|
@ -177,10 +181,10 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
|||
/**
|
||||
* Query builder scope to order on asset tag
|
||||
*
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
public function scopeOrderByTag($query, $order)
|
||||
{
|
||||
|
@ -191,14 +195,16 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
|||
/**
|
||||
* Query builder scope to order on asset tag
|
||||
*
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
public function scopeOrderByAssetName($query, $order)
|
||||
{
|
||||
return $query->leftJoin('assets', 'asset_maintenances.asset_id', '=', 'assets.id')
|
||||
->orderBy('assets.name', $order);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ trait Searchable {
|
|||
/**
|
||||
* Performs a search on the model, using the provided search terms
|
||||
*
|
||||
* @param Illuminate\Database\Eloquent\Builder $query The query to start the search on
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query The query to start the search on
|
||||
* @param string $search
|
||||
* @return Illuminate\Database\Eloquent\Builder A query with added "where" clauses
|
||||
* @return \Illuminate\Database\Eloquent\Builder A query with added "where" clauses
|
||||
*/
|
||||
public function scopeTextSearch($query, $search)
|
||||
{
|
||||
|
|
|
@ -46,6 +46,14 @@ class AssetMaintenancesPresenter extends Presenter
|
|||
"title" => trans('admin/hardware/table.asset_tag'),
|
||||
"formatter" => "assetTagLinkFormatter"
|
||||
], [
|
||||
"field" => "model",
|
||||
"searchable" => true,
|
||||
"sortable" => true,
|
||||
"switchable" => true,
|
||||
"title" => trans('admin/hardware/form.model'),
|
||||
"visible" => false,
|
||||
"formatter" => "modelsLinkObjFormatter"
|
||||
],[
|
||||
"field" => "supplier",
|
||||
"searchable" => true,
|
||||
"sortable" => true,
|
||||
|
|
Loading…
Reference in a new issue