Skip to content

Commit

Permalink
Fixes asset model table sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Oct 28, 2015
1 parent 5436d54 commit 76968f7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/config/version.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
return array (
'app_version' => 'v2.0-352',
'hash_version' => 'v2.0-352-g09bcb13',
'app_version' => 'v2.0-353',
'hash_version' => 'v2.0-353-gb6f4080',
);
60 changes: 53 additions & 7 deletions app/controllers/admin/ModelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Validator;
use View;
use Datatable;
use Asset;

//use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -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
Expand All @@ -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))) {
Expand All @@ -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');
Expand Down Expand Up @@ -422,23 +438,53 @@ 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 = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm">'.Lang::get('general.checkin').'</a>';
} else {
$actions = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm">'.Lang::get('general.checkout').'</a>';
}

$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,
Expand All @@ -447,7 +493,7 @@ public function getDataView($modelID)
);
}

$data = array('total' => $modelassetsCount, 'rows' => $rows);
$data = array('total' => $assetsCount, 'rows' => $rows);

return $data;
}
Expand Down
7 changes: 4 additions & 3 deletions app/views/backend/models/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<thead>
<tr>

<th data-sortable="true" data-field="name">{{Lang::get('general.name')}}</th>
<th data-sortable="true" data-field="id" data-searchable="false" data-visible="false">{{Lang::get('general.id')}}</th>
<th data-sortable="true" data-field="name" data-searchable="true">{{Lang::get('general.name')}}</th>
<th data-sortable="true" data-field="asset_tag">{{Lang::get('general.asset_tag')}}</th>
<th data-sortable="true" data-field="serial">{{Lang::get('admin/hardware/table.serial')}}</th>
<th data-sortable="true" data-field="assigned_to">{{Lang::get('general.user')}}</th>
<th data-sortable="false" data-field="assigned_to">{{Lang::get('general.user')}}</th>
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="actions">{{ Lang::get('table.actions') }}</th>
</tr>
</thead>
Expand Down

0 comments on commit 76968f7

Please sign in to comment.