mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Fixes #1955 - searching within locations
This commit is contained in:
parent
4efc30c63e
commit
c39e27cc5e
|
@ -6,6 +6,8 @@ use Lang;
|
|||
use App\Models\Location;
|
||||
use Redirect;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Models\Asset;
|
||||
use DB;
|
||||
use Str;
|
||||
use Validator;
|
||||
|
@ -368,15 +370,22 @@ class LocationsController extends Controller
|
|||
public function getDataViewUsers($locationID)
|
||||
{
|
||||
$location = Location::find($locationID);
|
||||
$users = User::where('location_id','=',$location->id);
|
||||
|
||||
if (Input::has('search')) {
|
||||
$users = $users->TextSearch(e(Input::get('search')));
|
||||
}
|
||||
|
||||
$users = $users->get();
|
||||
$rows = array();
|
||||
|
||||
foreach ($location->users as $user) {
|
||||
foreach ($users as $user) {
|
||||
$rows[] = array(
|
||||
'name' => (string)link_to('/admin/users/'.$user->id.'/view', e($user->fullName()))
|
||||
);
|
||||
}
|
||||
|
||||
$data = array('total' => $location->users->count(), 'rows' => $rows);
|
||||
$data = array('total' => $users->count(), 'rows' => $rows);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
@ -387,27 +396,36 @@ class LocationsController extends Controller
|
|||
* selected location, to be used by the location detail view.
|
||||
*
|
||||
* @todo This is broken for accessories and consumables.
|
||||
* @todo This is a very naive implementation. Should clean this up with query scopes.
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @see LocationsController::getView() method that creates the display view
|
||||
* @param int $locationId
|
||||
* @param int $locationID
|
||||
* @since [v1.8]
|
||||
* @return View
|
||||
*/
|
||||
public function getDataViewAssets($locationID)
|
||||
{
|
||||
$location = Location::find($locationID)->load('assignedassets.model');
|
||||
$assets = Asset::AssetsByLocation($location);
|
||||
|
||||
if (Input::has('search')) {
|
||||
$assets = $assets->TextSearch(e(Input::get('search')));
|
||||
}
|
||||
|
||||
$assets = $assets->get();
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach ($location->assignedassets as $asset) {
|
||||
foreach ($assets as $asset) {
|
||||
$rows[] = array(
|
||||
'name' => (string)link_to('/hardware/'.$asset->id.'/view', e($asset->showAssetName())),
|
||||
'name' => (string)link_to(config('app.url').'/hardware/'.$asset->id.'/view', e($asset->showAssetName())),
|
||||
'asset_tag' => e($asset->asset_tag),
|
||||
'serial' => e($asset->serial),
|
||||
'model' => e($asset->model->name),
|
||||
);
|
||||
}
|
||||
|
||||
$data = array('total' => $location->assignedassets->count(), 'rows' => $rows);
|
||||
$data = array('total' => $assets->count(), 'rows' => $rows);
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
|
|
@ -191,8 +191,8 @@ class UsersController extends Controller
|
|||
}
|
||||
|
||||
// Get this user groups
|
||||
//$userGroups = $user->groups()->lists('group_id', 'name');
|
||||
$userGroups = null;
|
||||
$userGroups = $user->groups()->lists('group_id', 'name');
|
||||
//$userGroups = null;
|
||||
|
||||
// Get this user permissions
|
||||
$userPermissions = null;
|
||||
|
|
|
@ -499,13 +499,38 @@ class Asset extends Depreciable
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope for RTD assets
|
||||
*
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
*
|
||||
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
|
||||
/**
|
||||
* Query builder scope for pending assets
|
||||
*
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
*
|
||||
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
|
||||
public function scopeAssetsByLocation($query, $location)
|
||||
{
|
||||
return $query->where(function ($query) use ($location)
|
||||
{
|
||||
$query->whereHas('assigneduser', function ($query) use ($location)
|
||||
{
|
||||
$query->where('users.location_id', '=', $location->id);
|
||||
})->orWhere(function ($query) use ($location)
|
||||
{
|
||||
$query->where('assets.rtd_location_id', '=', $location->id);
|
||||
$query->whereNull('assets.assigned_to');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Query builder scope for RTD assets
|
||||
*
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
*
|
||||
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
|
||||
public function scopeRTD($query)
|
||||
{
|
||||
|
@ -583,12 +608,12 @@ class Asset extends Depreciable
|
|||
{
|
||||
|
||||
return $query->where('requestable', '=', 1)
|
||||
->whereHas('assetstatus', function ($query) {
|
||||
->whereHas('assetstatus', function ($query) {
|
||||
|
||||
$query->where('deployable', '=', 1)
|
||||
->where('pending', '=', 0)
|
||||
->where('archived', '=', 0);
|
||||
});
|
||||
$query->where('deployable', '=', 1)
|
||||
->where('pending', '=', 0)
|
||||
->where('archived', '=', 0);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="box box-default">
|
||||
|
||||
|
||||
<div class="box-body">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
@ -96,7 +96,7 @@
|
|||
undefinedText: '',
|
||||
iconsPrefix: 'fa',
|
||||
showRefresh: true,
|
||||
search: false,
|
||||
search: true,
|
||||
pageSize: {{ \App\Models\Setting::getSettings()->per_page }},
|
||||
pagination: true,
|
||||
sidePagination: 'server',
|
||||
|
@ -128,7 +128,7 @@
|
|||
undefinedText: '',
|
||||
iconsPrefix: 'fa',
|
||||
showRefresh: true,
|
||||
search: false,
|
||||
search: true,
|
||||
pageSize: {{ \App\Models\Setting::getSettings()->per_page }},
|
||||
pagination: true,
|
||||
sidePagination: 'server',
|
||||
|
|
Loading…
Reference in a new issue