mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-12 16:44:08 -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 App\Models\Location;
|
||||||
use Redirect;
|
use Redirect;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\Asset;
|
||||||
use DB;
|
use DB;
|
||||||
use Str;
|
use Str;
|
||||||
use Validator;
|
use Validator;
|
||||||
|
@ -368,15 +370,22 @@ class LocationsController extends Controller
|
||||||
public function getDataViewUsers($locationID)
|
public function getDataViewUsers($locationID)
|
||||||
{
|
{
|
||||||
$location = Location::find($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();
|
$rows = array();
|
||||||
|
|
||||||
foreach ($location->users as $user) {
|
foreach ($users as $user) {
|
||||||
$rows[] = array(
|
$rows[] = array(
|
||||||
'name' => (string)link_to('/admin/users/'.$user->id.'/view', e($user->fullName()))
|
'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;
|
return $data;
|
||||||
}
|
}
|
||||||
|
@ -387,27 +396,36 @@ class LocationsController extends Controller
|
||||||
* selected location, to be used by the location detail view.
|
* selected location, to be used by the location detail view.
|
||||||
*
|
*
|
||||||
* @todo This is broken for accessories and consumables.
|
* @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>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @see LocationsController::getView() method that creates the display view
|
* @see LocationsController::getView() method that creates the display view
|
||||||
* @param int $locationId
|
* @param int $locationID
|
||||||
* @since [v1.8]
|
* @since [v1.8]
|
||||||
* @return View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function getDataViewAssets($locationID)
|
public function getDataViewAssets($locationID)
|
||||||
{
|
{
|
||||||
$location = Location::find($locationID)->load('assignedassets.model');
|
$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();
|
$rows = array();
|
||||||
|
|
||||||
foreach ($location->assignedassets as $asset) {
|
foreach ($assets as $asset) {
|
||||||
$rows[] = array(
|
$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),
|
'asset_tag' => e($asset->asset_tag),
|
||||||
'serial' => e($asset->serial),
|
'serial' => e($asset->serial),
|
||||||
'model' => e($asset->model->name),
|
'model' => e($asset->model->name),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = array('total' => $location->assignedassets->count(), 'rows' => $rows);
|
$data = array('total' => $assets->count(), 'rows' => $rows);
|
||||||
return $data;
|
return $data;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,8 +191,8 @@ class UsersController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get this user groups
|
// Get this user groups
|
||||||
//$userGroups = $user->groups()->lists('group_id', 'name');
|
$userGroups = $user->groups()->lists('group_id', 'name');
|
||||||
$userGroups = null;
|
//$userGroups = null;
|
||||||
|
|
||||||
// Get this user permissions
|
// Get this user permissions
|
||||||
$userPermissions = null;
|
$userPermissions = null;
|
||||||
|
|
|
@ -499,13 +499,38 @@ class Asset extends Depreciable
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Query builder scope for RTD assets
|
/**
|
||||||
*
|
* 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)
|
||||||
|
{
|
||||||
|
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)
|
public function scopeRTD($query)
|
||||||
{
|
{
|
||||||
|
@ -583,12 +608,12 @@ class Asset extends Depreciable
|
||||||
{
|
{
|
||||||
|
|
||||||
return $query->where('requestable', '=', 1)
|
return $query->where('requestable', '=', 1)
|
||||||
->whereHas('assetstatus', function ($query) {
|
->whereHas('assetstatus', function ($query) {
|
||||||
|
|
||||||
$query->where('deployable', '=', 1)
|
$query->where('deployable', '=', 1)
|
||||||
->where('pending', '=', 0)
|
->where('pending', '=', 0)
|
||||||
->where('archived', '=', 0);
|
->where('archived', '=', 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="box box-default">
|
<div class="box box-default">
|
||||||
|
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
|
@ -96,7 +96,7 @@
|
||||||
undefinedText: '',
|
undefinedText: '',
|
||||||
iconsPrefix: 'fa',
|
iconsPrefix: 'fa',
|
||||||
showRefresh: true,
|
showRefresh: true,
|
||||||
search: false,
|
search: true,
|
||||||
pageSize: {{ \App\Models\Setting::getSettings()->per_page }},
|
pageSize: {{ \App\Models\Setting::getSettings()->per_page }},
|
||||||
pagination: true,
|
pagination: true,
|
||||||
sidePagination: 'server',
|
sidePagination: 'server',
|
||||||
|
@ -128,7 +128,7 @@
|
||||||
undefinedText: '',
|
undefinedText: '',
|
||||||
iconsPrefix: 'fa',
|
iconsPrefix: 'fa',
|
||||||
showRefresh: true,
|
showRefresh: true,
|
||||||
search: false,
|
search: true,
|
||||||
pageSize: {{ \App\Models\Setting::getSettings()->per_page }},
|
pageSize: {{ \App\Models\Setting::getSettings()->per_page }},
|
||||||
pagination: true,
|
pagination: true,
|
||||||
sidePagination: 'server',
|
sidePagination: 'server',
|
||||||
|
|
Loading…
Reference in a new issue