Fixes #1955 - searching within locations

This commit is contained in:
snipe 2016-04-19 20:23:04 -07:00
parent 4efc30c63e
commit c39e27cc5e
4 changed files with 66 additions and 23 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -499,6 +499,31 @@ class Asset extends Depreciable
});
}
/**
* 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
*

View file

@ -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',