From 9168979d9edb142a3acea853708f7c1ddd03db99 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 1 Aug 2018 18:24:52 -0700 Subject: [PATCH] Fixed #6027 - added model to asset maintenances listing --- .../Api/AssetMaintenancesController.php | 6 ++--- .../AssetMaintenancesTransformer.php | 4 +++ app/Models/AssetMaintenance.php | 26 ++++++++++++------- app/Models/Traits/Searchable.php | 4 +-- app/Presenters/AssetMaintenancesPresenter.php | 8 ++++++ 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/Api/AssetMaintenancesController.php b/app/Http/Controllers/Api/AssetMaintenancesController.php index 55e6b1b632..e292ac11af 100644 --- a/app/Http/Controllers/Api/AssetMaintenancesController.php +++ b/app/Http/Controllers/Api/AssetMaintenancesController.php @@ -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')) { diff --git a/app/Http/Transformers/AssetMaintenancesTransformer.php b/app/Http/Transformers/AssetMaintenancesTransformer.php index df2e751ea2..f3c4d35453 100644 --- a/app/Http/Transformers/AssetMaintenancesTransformer.php +++ b/app/Http/Transformers/AssetMaintenancesTransformer.php @@ -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, diff --git a/app/Models/AssetMaintenance.php b/app/Models/AssetMaintenance.php index 020bf2777c..b2791fe956 100644 --- a/app/Models/AssetMaintenance.php +++ b/app/Models/AssetMaintenance.php @@ -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); } + + } diff --git a/app/Models/Traits/Searchable.php b/app/Models/Traits/Searchable.php index 96e88f7cb5..e43081e557 100644 --- a/app/Models/Traits/Searchable.php +++ b/app/Models/Traits/Searchable.php @@ -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) { diff --git a/app/Presenters/AssetMaintenancesPresenter.php b/app/Presenters/AssetMaintenancesPresenter.php index 452253b900..f2671f040f 100644 --- a/app/Presenters/AssetMaintenancesPresenter.php +++ b/app/Presenters/AssetMaintenancesPresenter.php @@ -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,