diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 1bab31243e..906c2edef2 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -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'; diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index c1e45a574a..e542a8eb6c 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -238,8 +238,6 @@ class LocationsController extends Controller * the content for the locations detail page. * * @author [A. Gianotto] [] - * @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] [] - * @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] [] - * @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; - - } } diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 6260d7a2af..d64ce611e9 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -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(); } diff --git a/resources/views/locations/view.blade.php b/resources/views/locations/view.blade.php index e4f92fe44d..a98523728f 100644 --- a/resources/views/locations/view.blade.php +++ b/resources/views/locations/view.blade.php @@ -3,8 +3,11 @@ {{-- Page title --}} @section('title') + {{ trans('general.location') }}: {{ $location->name }} - {{ trans('general.location') }} + @if ($location->manager) +
{!! trans('admin/users/table.manager') . ': ' . $location->manager->present()->nameUrl() !!}
+ @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"> - {{ trans('general.user') }} + {{ trans('general.user') }} @@ -54,7 +57,7 @@ - + diff --git a/routes/api.php b/routes/api.php index ea53f913b5..45264e4df0 100644 --- a/routes/api.php +++ b/routes/api.php @@ -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', [
{{ trans('general.name') }}{{ trans('admin/hardware/form.model') }}{{ trans('admin/hardware/form.model') }} {{ trans('admin/hardware/form.tag') }} {{ trans('admin/hardware/form.serial') }}