mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 05:04:07 -08:00
Fix location view display. Migrate to api controller methods and fix missing bits to make this happen. Show manager on the location view page.
This commit is contained in:
parent
f0d78091d2
commit
dfea47a272
|
@ -40,8 +40,8 @@ class UsersController extends Controller
|
|||
'users.deleted_at',
|
||||
'users.department_id',
|
||||
'users.activated'
|
||||
])->with('manager', 'groups', 'userloc', 'company', 'department','throttle','assets','licenses','accessories','consumables')
|
||||
->withCount('assets','licenses','accessories','consumables');
|
||||
])->with('manager', 'groups', 'userloc', 'company', 'department', 'throttle', 'assets', 'licenses', 'accessories', 'consumables')
|
||||
->withCount('assets', 'licenses', 'accessories', 'consumables');
|
||||
$users = Company::scopeCompanyables($users);
|
||||
|
||||
|
||||
|
@ -50,11 +50,15 @@ class UsersController extends Controller
|
|||
}
|
||||
|
||||
if ($request->has('company_id')) {
|
||||
$users = $users->where('company_id','=',$request->input('company_id'));
|
||||
$users = $users->where('company_id', '=', $request->input('company_id'));
|
||||
}
|
||||
|
||||
if ($request->has('department_id')) {
|
||||
$users = $users->where('department_id','=',$request->input('department_id'));
|
||||
$users = $users->where('department_id', '=', $request->input('department_id'));
|
||||
}
|
||||
|
||||
if ($request->has('location_id')) {
|
||||
$users = $users->where('location_id', '=', $request->input('location_id'));
|
||||
}
|
||||
|
||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||
|
|
|
@ -238,8 +238,6 @@ class LocationsController extends Controller
|
|||
* the content for the locations detail page.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @see LocationsController::getDataViewUsers() method that returns JSON for location users
|
||||
* @see LocationsController::getDataViewAssets() method that returns JSON for location assets
|
||||
* @param int $locationId
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
|
@ -258,78 +256,4 @@ class LocationsController extends Controller
|
|||
return redirect()->route('locations.index')->with('error', $error);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a JSON response that contains the users association with the
|
||||
* selected location, to be used by the location detail view.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @see LocationsController::getView() method that creates the display view
|
||||
* @param $locationID
|
||||
* @return array
|
||||
* @internal param int $locationId
|
||||
* @since [v1.8]
|
||||
*/
|
||||
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 ($users as $user) {
|
||||
$rows[] = array(
|
||||
'name' => (string)link_to_route('users.show', e($user->present()->fullName()), ['user'=>$user->id])
|
||||
);
|
||||
}
|
||||
|
||||
$data = array('total' => $users->count(), 'rows' => $rows);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a JSON response that contains the assets association with the
|
||||
* 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
|
||||
* @since [v1.8]
|
||||
* @return array
|
||||
*/
|
||||
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 ($assets as $asset) {
|
||||
$rows[] = [
|
||||
'name' => (string)link_to_route('hardware.show', e($asset->present()->name()), ['hardware' => $asset->id]),
|
||||
'asset_tag' => e($asset->asset_tag),
|
||||
'serial' => e($asset->serial),
|
||||
'model' => e($asset->model->name),
|
||||
];
|
||||
}
|
||||
|
||||
$data = array('total' => $assets->count(), 'rows' => $rows);
|
||||
return $data;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -272,16 +272,16 @@ class Asset extends Depreciable
|
|||
**/
|
||||
public function assetLoc()
|
||||
{
|
||||
if ($this->assignedTo) {
|
||||
return $this->assignedTo->userloc();
|
||||
}
|
||||
|
||||
if (!empty($this->assignedType())) {
|
||||
if ($this->assignedType() == self::ASSET) {
|
||||
return $this->assignedTo->assetloc(); // Recurse until we have a final location
|
||||
} elseif ($this->assignedType() == self::LOCATION) {
|
||||
}
|
||||
if ($this->assignedType() == self::LOCATION) {
|
||||
return $this->assignedTo();
|
||||
}
|
||||
if ($this->assignedType() == self::USER) {
|
||||
return $this->assignedTo->userLoc();
|
||||
}
|
||||
}
|
||||
return $this->defaultLoc();
|
||||
}
|
||||
|
|
|
@ -3,8 +3,11 @@
|
|||
{{-- Page title --}}
|
||||
@section('title')
|
||||
|
||||
{{ trans('general.location') }}:
|
||||
{{ $location->name }}
|
||||
{{ trans('general.location') }}
|
||||
@if ($location->manager)
|
||||
<div class="h6"> {!! trans('admin/users/table.manager') . ': ' . $location->manager->present()->nameUrl() !!}</div>
|
||||
@endif
|
||||
@parent
|
||||
@stop
|
||||
|
||||
|
@ -26,13 +29,13 @@
|
|||
name="location_users"
|
||||
id="table-users"
|
||||
class="table table-striped snipe-table"
|
||||
data-url="{{route('api.locations.viewusers', $location->id)}}"
|
||||
data-url="{{route('api.users.index', ['location_id' => $location->id])}}"
|
||||
data-cookie="true"
|
||||
data-click-to-select="true"
|
||||
data-cookie-id-table="location_usersDetailTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-searchable="false" data-sortable="false" data-field="name">{{ trans('general.user') }}</th>
|
||||
<th data-searchable="false" data-sortable="false" data-formatter="usersLinkFormatter" data-field="name">{{ trans('general.user') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
@ -54,7 +57,7 @@
|
|||
<table
|
||||
name="location_assets"
|
||||
id="table-assets"
|
||||
data-url="{{route('api.locations.viewassets', $location->id)}}"
|
||||
data-url="{{route('api.assets.index', ['location_id' => $location->id])}}"
|
||||
class="table table-striped snipe-table"
|
||||
data-cookie="true"
|
||||
data-click-to-select="true"
|
||||
|
@ -62,7 +65,7 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th data-searchable="false" data-sortable="false" data-field="name">{{ trans('general.name') }}</th>
|
||||
<th data-searchable="false" data-sortable="false" data-field="model">{{ trans('admin/hardware/form.model') }}</th>
|
||||
<th data-searchable="false" data-sortable="false" data-formatter="modelsLinkObjFormatter" data-field="model">{{ trans('admin/hardware/form.model') }}</th>
|
||||
<th data-searchable="false" data-sortable="false" data-field="asset_tag">{{ trans('admin/hardware/form.tag') }}</th>
|
||||
<th data-searchable="false" data-sortable="false" data-field="serial">{{ trans('admin/hardware/form.serial') }}</th>
|
||||
</tr>
|
||||
|
|
|
@ -294,21 +294,6 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
|
|||
); // Locations resource
|
||||
|
||||
Route::group(['prefix' => 'locations'], function () {
|
||||
|
||||
Route::get('{location}/users',
|
||||
[
|
||||
'as'=>'api.locations.viewusers',
|
||||
'uses'=>'LocationsController@getDataViewUsers'
|
||||
]
|
||||
);
|
||||
|
||||
Route::get('{location}/assets',
|
||||
[
|
||||
'as'=>'api.locations.viewassets',
|
||||
'uses'=>'LocationsController@getDataViewAssets'
|
||||
]
|
||||
);
|
||||
|
||||
// Do we actually still need this, now that we have an API?
|
||||
Route::get('{location}/check',
|
||||
[
|
||||
|
|
Loading…
Reference in a new issue