mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Improved use of de-normed locations fields
This commit is contained in:
parent
4eee7f8d97
commit
7f1b962e56
|
@ -21,8 +21,10 @@ class LocationsController extends Controller
|
|||
public function index(Request $request)
|
||||
{
|
||||
$this->authorize('view', Location::class);
|
||||
$allowed_columns = ['id','name','address','address2','city','state','country','zip','created_at',
|
||||
'updated_at','parent_id', 'manager_id','image'];
|
||||
$allowed_columns = [
|
||||
'id','name','address','address2','city','state','country','zip','created_at',
|
||||
'updated_at','parent_id', 'manager_id','image',
|
||||
'rtd_assets_count','users_count','assets_count'];
|
||||
|
||||
$locations = Location::with('parent', 'manager', 'childLocations')->select([
|
||||
'locations.id',
|
||||
|
@ -39,8 +41,7 @@ class LocationsController extends Controller
|
|||
'locations.updated_at',
|
||||
'locations.image',
|
||||
'locations.currency'
|
||||
])->withCount('locationAssets')
|
||||
->withCount('assignedAssets')
|
||||
])->withCount('rtd_assets')
|
||||
->withCount('assets')
|
||||
->withCount('users');
|
||||
|
||||
|
|
|
@ -39,8 +39,9 @@ class LocationsTransformer
|
|||
'state' => e($location->state),
|
||||
'country' => e($location->country),
|
||||
'zip' => e($location->zip),
|
||||
'assets_checkedout' => $location->location_assets_count,
|
||||
'assets_default' => $location->assigned_assets_count,
|
||||
'assets_count' => (int) $location->assets_count,
|
||||
'rtd_assets_count' => (int) $location->rtd_assets_count,
|
||||
'users_count' => (int) $location->users_count,
|
||||
|
||||
'created_at' => Helper::getFormattedDateObject($location->created_at, 'datetime'),
|
||||
'updated_at' => Helper::getFormattedDateObject($location->updated_at, 'datetime'),
|
||||
|
|
|
@ -54,10 +54,10 @@ class Location extends SnipeModel
|
|||
|
||||
public function assets()
|
||||
{
|
||||
return $this->hasManyThrough('\App\Models\Asset', '\App\Models\User', 'location_id', 'assigned_to', 'id')->where("assets.assigned_type",User::class);
|
||||
return $this->hasMany('\App\Models\Asset', 'location_id');
|
||||
}
|
||||
|
||||
public function locationAssets()
|
||||
public function rtd_assets()
|
||||
{
|
||||
/* This used to have an ...->orHas() clause that referred to
|
||||
assignedAssets, and that was probably incorrect, as well as
|
||||
|
@ -88,6 +88,7 @@ class Location extends SnipeModel
|
|||
return $this->hasMany('\App\Models\Location', 'parent_id');
|
||||
}
|
||||
|
||||
// I don't think we need this anymore since we de-normed location_id in assets?
|
||||
public function assignedAssets()
|
||||
{
|
||||
return $this->morphMany('App\Models\Asset', 'assigned', 'assigned_type', 'assigned_to')->withTrashed();
|
||||
|
|
|
@ -31,8 +31,9 @@
|
|||
<th data-sortable="true" data-formatter="locationsLinkFormatter" data-field="name" data-searchable="true">{{ trans('admin/locations/table.name') }}</th>
|
||||
<th data-sortable="true" data-field="image" data-visible="false" data-formatter="imageFormatter">{{ trans('general.image') }}</th>
|
||||
<th data-sortable="true" data-field="parent" data-formatter="locationsLinkObjFormatter">{{ trans('admin/locations/table.parent') }}</th>
|
||||
<th data-searchable="false" data-sortable="false" data-field="assets_default">{{ trans('admin/locations/table.assets_rtd') }}</th>
|
||||
<th data-searchable="false" data-sortable="false" data-field="assets_checkedout">{{ trans('admin/locations/table.assets_checkedout') }}</th>
|
||||
<th data-searchable="false" data-sortable="true" data-field="rtd_assets_count">{{ trans('admin/locations/table.assets_rtd') }}</th>
|
||||
<th data-searchable="false" data-sortable="true" data-field="assets_count">{{ trans('admin/locations/table.assets_checkedout') }}</th>
|
||||
<th data-searchable="false" data-sortable="true" data-field="users_count">{{ trans('general.people') }}</th>
|
||||
<th data-searchable="true" data-sortable="true" data-field="currency">{{ trans('general.currency') }}</th>
|
||||
<th data-searchable="true" data-sortable="true" data-field="address">{{ trans('admin/locations/table.address') }}</th>
|
||||
<th data-searchable="true" data-sortable="true" data-field="city">{{ trans('admin/locations/table.city') }}
|
||||
|
|
Loading…
Reference in a new issue