From 76968f7d48a4558105cc52231726475e626f0a2b Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 28 Oct 2015 03:23:55 -0700 Subject: [PATCH] Fixes asset model table sorting --- app/config/version.php | 4 +- app/controllers/admin/ModelsController.php | 60 +++++++++++++++++++--- app/views/backend/models/view.blade.php | 7 +-- 3 files changed, 59 insertions(+), 12 deletions(-) diff --git a/app/config/version.php b/app/config/version.php index f73a70612120..d755447b753c 100644 --- a/app/config/version.php +++ b/app/config/version.php @@ -1,5 +1,5 @@ 'v2.0-352', - 'hash_version' => 'v2.0-352-g09bcb13', + 'app_version' => 'v2.0-353', + 'hash_version' => 'v2.0-353-gb6f4080', ); \ No newline at end of file diff --git a/app/controllers/admin/ModelsController.php b/app/controllers/admin/ModelsController.php index 27faaadfac5f..46a1965d8d7b 100755 --- a/app/controllers/admin/ModelsController.php +++ b/app/controllers/admin/ModelsController.php @@ -15,6 +15,7 @@ use Validator; use View; use Datatable; +use Asset; //use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\JsonResponse; @@ -317,7 +318,7 @@ public function getRestore($modelId = null) /** - * Get the asset information to present to the model view page + * Get the model information to present to the model view page * * @param int $assetId * @return View @@ -339,7 +340,14 @@ public function getView($modelId = null) } - public function getClone($modelId = null) + /** + * Get the clone page to clone a model + * + * @param int $modelId + * @return View + **/ + + public function getClone($modelId = null) { // Check if the model exists if (is_null($model_to_clone = Model::find($modelId))) { @@ -364,6 +372,14 @@ public function getClone($modelId = null) } + + /** + * Get the JSON response for the bootstrap table list view + * + * @param string $status + * @return JSON + **/ + public function getDatatable($status = null) { $models = Model::orderBy('created_at', 'DESC')->with('category','assets','depreciation'); @@ -422,16 +438,45 @@ public function getDatatable($status = null) } + /** + * Get the asset information to present to the model view page + * + * @param int $modelID + * @return View + **/ public function getDataView($modelID) { - $model = Model::withTrashed()->find($modelID); - $modelassets = $model->assets; + $assets = Asset::where('model_id','=',$modelID)->withTrashed(); + + if (Input::has('search')) { + $assets = $assets->TextSearch(Input::get('search')); + } + + if (Input::has('offset')) { + $offset = e(Input::get('offset')); + } else { + $offset = 0; + } + + if (Input::has('limit')) { + $limit = e(Input::get('limit')); + } else { + $limit = 50; + } + + + $allowed_columns = ['name', 'serial','asset_tag']; + $order = Input::get('order') === 'asc' ? 'asc' : 'desc'; + $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at'; + + $assets = $assets->orderBy($sort, $order); - $modelassetsCount = $modelassets->Count(); + $assetsCount = $assets->count(); + $assets = $assets->skip($offset)->take($limit)->get(); $rows = array(); - foreach ($modelassets as $asset) { + foreach ($assets as $asset) { if (($asset->assigned_to !='') && ($asset->assigned_to > 0)) { $actions = ''.Lang::get('general.checkin').''; } else { @@ -439,6 +484,7 @@ public function getDataView($modelID) } $rows[] = array( + 'id' => $asset->id, 'name' => link_to('/hardware/'.$asset->id.'/view', $asset->showAssetName()), 'asset_tag' => link_to('hardware/'.$asset->id.'/view', $asset->asset_tag), 'serial' => $asset->serial, @@ -447,7 +493,7 @@ public function getDataView($modelID) ); } - $data = array('total' => $modelassetsCount, 'rows' => $rows); + $data = array('total' => $assetsCount, 'rows' => $rows); return $data; } diff --git a/app/views/backend/models/view.blade.php b/app/views/backend/models/view.blade.php index 1669918317c8..6c6af0ee7bb7 100755 --- a/app/views/backend/models/view.blade.php +++ b/app/views/backend/models/view.blade.php @@ -58,14 +58,15 @@ data-url="{{route('api.models.view', $model->id)}}" data-cookie="true" data-click-to-select="true" - data-cookie-id-table="modelDetailViewTable"> + data-cookie-id-table="modeldetailsViewTable"> - {{Lang::get('general.name')}} + {{Lang::get('general.id')}} + {{Lang::get('general.name')}} {{Lang::get('general.asset_tag')}} {{Lang::get('admin/hardware/table.serial')}} - {{Lang::get('general.user')}} + {{Lang::get('general.user')}} {{ Lang::get('table.actions') }}