From e670ffe34905d5a0634ee17114ca17f7e17777f1 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 26 Oct 2022 00:16:06 -0700 Subject: [PATCH] Added Assets Assigned to tab Signed-off-by: snipe --- .../Controllers/Api/LocationsController.php | 11 ++-- .../Transformers/LocationsTransformer.php | 3 +- app/Presenters/LocationPresenter.php | 17 +++++-- resources/lang/en/admin/locations/message.php | 2 + resources/views/locations/view.blade.php | 51 ++++++++++++++++++- 5 files changed, 74 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/Api/LocationsController.php b/app/Http/Controllers/Api/LocationsController.php index 176033453e..2a6b19eefe 100644 --- a/app/Http/Controllers/Api/LocationsController.php +++ b/app/Http/Controllers/Api/LocationsController.php @@ -27,7 +27,7 @@ class LocationsController extends Controller $allowed_columns = [ 'id', 'name', 'address', 'address2', 'city', 'state', 'country', 'zip', 'created_at', 'updated_at', 'manager_id', 'image', - 'assigned_assets_count', 'users_count', 'assets_count', 'currency', 'ldap_ou', ]; + 'assigned_assets_count', 'users_count', 'assets_count','assigned_assets_count', 'assets_location_count', 'rtd_assets_count', 'currency', 'ldap_ou', ]; $locations = Location::with('parent', 'manager', 'children')->select([ 'locations.id', @@ -46,7 +46,8 @@ class LocationsController extends Controller 'locations.ldap_ou', 'locations.currency', ])->withCount('assignedAssets as assigned_assets_count') - ->withCount('assets as assets_count') + ->withCount('assets as assets_location_count') + ->withCount('rtd_assets as rtd_assets_count') ->withCount('users as users_count'); if ($request->filled('search')) { @@ -156,8 +157,10 @@ class LocationsController extends Controller 'locations.currency', ]) ->withCount('assignedAssets as assigned_assets_count') - ->withCount('assets as assets_count') - ->withCount('users as users_count')->findOrFail($id); + ->withCount('assets as assets_location_count') + ->withCount('rtd_assets as rtd_assets_count') + ->withCount('users as users_count') + ->findOrFail($id); return (new LocationsTransformer)->transformLocation($location); } diff --git a/app/Http/Transformers/LocationsTransformer.php b/app/Http/Transformers/LocationsTransformer.php index 78d8cc8096..8d6a1315cf 100644 --- a/app/Http/Transformers/LocationsTransformer.php +++ b/app/Http/Transformers/LocationsTransformer.php @@ -44,7 +44,8 @@ class LocationsTransformer 'country' => ($location->country) ? e($location->country) : null, 'zip' => ($location->zip) ? e($location->zip) : null, 'assigned_assets_count' => (int) $location->assigned_assets_count, - 'assets_count' => (int) $location->assets_count, + 'assets_location_count' => (int) $location->assets_location_count, + 'rtd_assets_count' => (int) $location->rtd_assets_count, 'users_count' => (int) $location->users_count, 'currency' => ($location->currency) ? e($location->currency) : null, 'ldap_ou' => ($location->ldap_ou) ? e($location->ldap_ou) : null, diff --git a/app/Presenters/LocationPresenter.php b/app/Presenters/LocationPresenter.php index 2501677bd9..892775edee 100644 --- a/app/Presenters/LocationPresenter.php +++ b/app/Presenters/LocationPresenter.php @@ -51,21 +51,32 @@ class LocationPresenter extends Presenter ], [ - 'field' => 'assets_count', + 'field' => 'assets_location_count', 'searchable' => false, 'sortable' => true, 'switchable' => true, - 'title' => trans('admin/locations/table.assets_rtd'), + 'title' => trans('admin/locations/message.current_location'), 'visible' => true, ], + + [ + 'field' => 'rtd_assets_count', + 'searchable' => false, + 'sortable' => true, + 'switchable' => true, + 'title' => trans('admin/hardware/form.default_location'), + 'visible' => false, + ], + [ 'field' => 'assigned_assets_count', 'searchable' => false, 'sortable' => true, 'switchable' => true, - 'title' => trans('admin/locations/table.assets_checkedout'), + 'title' => trans('admin/locations/message.assigned_assets'), 'visible' => true, ], + [ 'field' => 'users_count', 'searchable' => false, diff --git a/resources/lang/en/admin/locations/message.php b/resources/lang/en/admin/locations/message.php index 3ba1eed3b6..22c7fe8f70 100644 --- a/resources/lang/en/admin/locations/message.php +++ b/resources/lang/en/admin/locations/message.php @@ -6,6 +6,8 @@ return array( 'assoc_users' => 'This location is currently associated with at least one user and cannot be deleted. Please update your users to no longer reference this location and try again. ', 'assoc_assets' => 'This location is currently associated with at least one asset and cannot be deleted. Please update your assets to no longer reference this location and try again. ', 'assoc_child_loc' => 'This location is currently the parent of at least one child location and cannot be deleted. Please update your locations to no longer reference this location and try again. ', + 'assigned_assets' => 'Assigned Assets', + 'current_location' => 'Current Location', 'create' => array( diff --git a/resources/views/locations/view.blade.php b/resources/views/locations/view.blade.php index 1f7a84c913..a1c3320194 100644 --- a/resources/views/locations/view.blade.php +++ b/resources/views/locations/view.blade.php @@ -37,12 +37,13 @@ +
  • +
  • + + + + +
  • +
  • @@ -127,7 +140,7 @@
    -

    {{ trans('general.assets') }}

    +

    {{ trans('admin/locations/message.current_location') }}

    @include('partials.asset-bulk-actions') @@ -158,6 +171,40 @@
    +
    +

    + {{ trans('admin/locations/message.assigned_assets') }} +

    + +
    + @include('partials.asset-bulk-actions', ['id_divname' => 'AssignedAssetsBulkEditToolbar', 'id_formname' => 'assignedAssetsBulkForm', 'id_button' => 'AssignedbulkAssetEditButton']) + +
    + +
    +
    +

    {{ trans('admin/hardware/form.default_location') }}