Use main assets API to pull view pages for assets listings

This commit is contained in:
snipe 2017-02-03 19:34:24 -08:00
parent a69090c91c
commit 1e2a23e955
4 changed files with 80 additions and 60 deletions

View file

@ -84,12 +84,20 @@ class AssetsController extends Controller
$assets->TextSearch($request->input('search'));
}
if ($request->has('model_id')) {
$assets->InModelList([$request->input('model_id')]);
}
if ($request->has('category_id')) {
$assets->InCategory($request->input('category_id'));
}
$request->has('order_number') ? $assets = $assets->where('order_number', '=', e($request->get('order_number'))) : '';
$offset = request('offset', 0);
$limit = $request->input('limit', 50);
$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') : 'assets.created_at';
$assets->orderBy($sort, $order);
switch ($status) {

View file

@ -465,9 +465,9 @@ class Asset extends Depreciable
/**
* Query builder scope for hardware
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeHardware($query)
@ -479,9 +479,9 @@ class Asset extends Depreciable
/**
* Query builder scope for pending assets
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopePending($query)
@ -499,9 +499,9 @@ class Asset extends Depreciable
/**
* Query builder scope for pending assets
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeAssetsByLocation($query, $location)
@ -523,9 +523,9 @@ class Asset extends Depreciable
/**
* Query builder scope for RTD assets
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeRTD($query)
@ -543,9 +543,9 @@ class Asset extends Depreciable
/**
* Query builder scope for Undeployable assets
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeUndeployable($query)
@ -562,9 +562,9 @@ class Asset extends Depreciable
/**
* Query builder scope for non-Archived assets
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeNotArchived($query)
@ -579,9 +579,9 @@ class Asset extends Depreciable
/**
* Query builder scope for Archived assets
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeArchived($query)
@ -598,9 +598,9 @@ class Asset extends Depreciable
/**
* Query builder scope for Deployed assets
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeDeployed($query)
@ -612,9 +612,9 @@ class Asset extends Depreciable
/**
* Query builder scope for Requestable assets
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeRequestableAssets($query)
@ -633,9 +633,9 @@ class Asset extends Depreciable
/**
* Query builder scope for Deleted assets
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeDeleted($query)
@ -662,9 +662,9 @@ class Asset extends Depreciable
/**
* Query builder scope to get not-yet-accepted assets
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeNotYetAccepted($query)
{
@ -674,9 +674,9 @@ class Asset extends Depreciable
/**
* Query builder scope to get rejected assets
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeRejected($query)
{
@ -700,10 +700,10 @@ class Asset extends Depreciable
/**
* Query builder scope to search on text for complex Bootstrap Tables API
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $search Search term
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeTextSearch($query, $search)
{
@ -765,10 +765,10 @@ class Asset extends Depreciable
/**
* Query builder scope to order on model
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderModels($query, $order)
{
@ -778,10 +778,10 @@ class Asset extends Depreciable
/**
* Query builder scope to order on model number
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderModelNumber($query, $order)
{
@ -792,10 +792,10 @@ class Asset extends Depreciable
/**
* Query builder scope to order on assigned user
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderAssigned($query, $order)
{
@ -805,10 +805,10 @@ class Asset extends Depreciable
/**
* Query builder scope to order on status
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderStatus($query, $order)
{
@ -818,24 +818,39 @@ class Asset extends Depreciable
/**
* Query builder scope to order on company
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderCompany($query, $order)
{
return $query->leftJoin('companies', 'assets.company_id', '=', 'companies.id')->orderBy('companies.name', $order);
}
/**
* Query builder scope to order on category
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return Illuminate\Database\Query\Builder Modified query builder
*/
/**
* Query builder scope to return results of a category
*
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeInCategory($query, $category_id)
{
return $query->join('models', 'assets.model_id', '=', 'models.id')
->join('categories', 'models.category_id', '=', 'categories.id')->where('models.category_id','=',$category_id);
}
/**
* Query builder scope to order on category
*
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderCategory($query, $order)
{
return $query->join('models', 'assets.model_id', '=', 'models.id')
@ -847,10 +862,10 @@ class Asset extends Depreciable
/**
* Query builder scope to order on manufacturer
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return Illuminate\Database\Query\Builder Modified query builder
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderManufacturer($query, $order)
{
@ -862,12 +877,10 @@ class Asset extends Depreciable
/**
* Query builder scope to order on location
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return Illuminate\Database\Query\Builder Modified query builder
* TODO: Extend this method out for checked out assets as well. Right now it
* only checks the location name related to rtd_location_id
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderLocation($query, $order)
{

View file

@ -30,11 +30,10 @@
name="category_assets"
class="snipe-table"
id="table"
data-url="{{ route('api.categories.'.$category->category_type.'.show', [$category->id, $category->category_type]) }}"
data-url="{{ ($category->category_type=='asset') ? route('api.assets.index',['category_id'=> $category->id]) : route('api'.$category->category_type.'index', ['category_id'=> $category->id]) }}
data-cookie="true"
data-click-to-select="true"
data-cookie-id-table="categoryAssetsTable"
>
data-cookie-id-table="categoryAssetsTable">
<thead>
<tr>
<th data-searchable="false" data-sortable="false" data-field="company" data-visible="false">
@ -43,10 +42,10 @@
<th data-searchable="false" data-sortable="false" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
<th data-searchable="false" data-sortable="false" data-field="name">{{ trans('general.name') }}</th>
@if ($category->category_type=='asset')
<th data-searchable="false" data-sortable="false" data-field="model">{{ trans('admin/hardware/form.model') }}</th>
<th data-searchable="false" data-sortable="false" data-field="asset_tag">{{ trans('general.asset_tag') }}</th>
<th data-searchable="false" data-sortable="false" data-field="serial">{{ trans('admin/hardware/form.serial') }}</th>
<th data-searchable="false" data-sortable="false" data-field="assigned_to">{{ trans('general.user') }}</th>
<th data-searchable="false" data-sortable="false" data-field="model" data-formatter="modelsLinkObjFormatter">{{ trans('admin/hardware/form.model') }}</th>
<th data-searchable="false" data-sortable="false" data-field="asset_tag" data-formatter="hardwareLinkFormatter">{{ trans('general.asset_tag') }}</th>
<th data-searchable="false" data-sortable="false" data-field="serial" data-formatter="hardwareLinkFormatter">{{ trans('admin/hardware/form.serial') }}</th>
<th data-searchable="false" data-sortable="false" data-field="assigned_to" data-formatter="usersLinkFormatter">{{ trans('general.user') }}</th>
<th data-searchable="false" data-sortable="false" data-field="change" data-switchable="false">{{ trans('admin/hardware/table.change') }}</th>
@endif
<th data-searchable="false" data-sortable="false" data-field="actions" data-switchable="false">{{ trans('table.actions') }}</th>

View file

@ -44,7 +44,7 @@
name="modelassets"
id="table"
class="snipe-table"
data-url="{{route('api.models.assets', $model->id)}}"
data-url="{{ route('api.assets.index',['model_id'=> $model->id]) }}"
data-cookie="true"
data-click-to-select="true"
data-cookie-id-table="modeldetailsViewTable">
@ -56,7 +56,7 @@
<th data-sortable="true" data-field="name" data-searchable="true" data-formatter="hardwareLinkFormatter">{{ trans('general.name') }}</th>
<th data-sortable="true" data-field="asset_tag" data-formatter="hardwareLinkFormatter">{{ trans('general.asset_tag') }}</th>
<th data-sortable="true" data-field="serial" data-formatter="hardwareLinkFormatter">{{ trans('admin/hardware/table.serial') }}</th>
<th data-sortable="false" data-field="assigned_to" data-formatter="usersLinkObjFormatter">{{ trans('general.user') }}</th>
<th data-sortable="false" data-field="assigned_to" data-formatter="usersLinkFormatter">{{ trans('general.user') }}</th>
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="actions">{{ trans('table.actions') }}</th>
</tr>
</thead>