diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index c498f09926..f32e6b8489 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Http\Requests\ImageUploadRequest; +use App\Models\Actionlog; use App\Models\Asset; use App\Models\Location; use App\Models\User; @@ -193,7 +194,13 @@ class LocationsController extends Controller */ public function show($id = null) : View | RedirectResponse { - $location = Location::find($id); + $location = Location::withCount('assignedAssets as assigned_assets_count') + ->withCount('assets as assets_count') + ->withCount('rtd_assets as rtd_assets_count') + ->withCount('children as children_count') + ->withCount('users as users_count') + ->withTrashed() + ->find($id); if (isset($location->id)) { return view('locations/view', compact('location')); @@ -249,6 +256,41 @@ class LocationsController extends Controller } + /** + * Restore a given Asset Model (mark as un-deleted) + * + * @author [A. Gianotto] [] + * @since [v1.0] + * @param int $id + */ + public function postRestore($id) : RedirectResponse + { + $this->authorize('create', Location::class); + + if ($location = Location::withTrashed()->find($id)) { + + if ($location->deleted_at == '') { + return redirect()->back()->with('error', trans('general.not_deleted', ['item_type' => trans('general.location')])); + } + + if ($location->restore()) { + $logaction = new Actionlog(); + $logaction->item_type = Location::class; + $logaction->item_id = $location->id; + $logaction->created_at = date('Y-m-d H:i:s'); + $logaction->user_id = auth()->id(); + $logaction->logaction('restore'); + + return redirect()->route('locations.index')->with('success', trans('admin/locations/message.restore.success')); + } + + // Check validation + return redirect()->back()->with('error', trans('general.could_not_restore', ['item_type' => trans('general.location'), 'error' => $location->getErrors()->first()])); + } + + return redirect()->back()->with('error', trans('admin/models/message.does_not_exist')); + + } public function print_all_assigned($id) : View | RedirectResponse { if ($location = Location::where('id', $id)->first()) { diff --git a/resources/lang/en-US/admin/locations/message.php b/resources/lang/en-US/admin/locations/message.php index 6226c71ab6..5ba6e5109c 100644 --- a/resources/lang/en-US/admin/locations/message.php +++ b/resources/lang/en-US/admin/locations/message.php @@ -20,6 +20,11 @@ return array( 'success' => 'Location updated successfully.' ), + 'restore' => array( + 'error' => 'Location was not restored, please try again', + 'success' => 'Location restored successfully.' + ), + 'delete' => array( 'confirm' => 'Are you sure you wish to delete this location?', 'error' => 'There was an issue deleting the location. Please try again.', diff --git a/resources/views/locations/view.blade.php b/resources/views/locations/view.blade.php index 2eb7a01d87..e59527e4d7 100644 --- a/resources/views/locations/view.blade.php +++ b/resources/views/locations/view.blade.php @@ -9,6 +9,10 @@ @parent @stop +@section('header_right') + + {{ trans('general.back') }} +@endsection {{-- Page content --}} @section('content') @@ -382,65 +386,113 @@
+ @can('update', $location) + @endcan + + @can('delete', $location) +
+ + @if ($location->deleted_at=='') + + @if ($location->isDeletable()) + + @else + + + {{ trans('general.delete') }} + + @endif + + @else +
+ @csrf + +
+ @endif +
+ @endcan + @if ($location->image!='') -
- {{ $location->name }} -
+
+ {{ $location->name }} +
@endif -
+ +
    - @if ($location->address!='') + @if ($location->address!='')
  • {{ $location->address }}
  • - @endif - @if ($location->address2!='') -
  • {{ $location->address2 }}
  • - @endif - @if (($location->city!='') || ($location->state!='') || ($location->zip!='')) -
  • {{ $location->city }} {{ $location->state }} {{ $location->zip }}
  • - @endif - @if ($location->manager) -
  • {{ trans('admin/users/table.manager') }}: {!! $location->manager->present()->nameUrl() !!}
  • - @endif - @if ($location->parent) -
  • {{ trans('admin/locations/table.parent') }}: {!! $location->parent->present()->nameUrl() !!}
  • - @endif - @if ($location->ldap_ou) -
  • {{ trans('admin/locations/table.ldap_ou') }}: {{ $location->ldap_ou }}
  • - @endif + @endif + @if ($location->address2!='') +
  • {{ $location->address2 }}
  • + @endif + @if (($location->city!='') || ($location->state!='') || ($location->zip!='')) +
  • {{ $location->city }} {{ $location->state }} {{ $location->zip }}
  • + @endif + @if ($location->manager) +
  • {{ trans('admin/users/table.manager') }}: {!! $location->manager->present()->nameUrl() !!}
  • + @endif + @if ($location->parent) +
  • {{ trans('admin/locations/table.parent') }}: {!! $location->parent->present()->nameUrl() !!}
  • + @endif + @if ($location->ldap_ou) +
  • {{ trans('admin/locations/table.ldap_ou') }}: {{ $location->ldap_ou }}
  • + @endif
- @if (($location->state!='') && ($location->country!='') && (config('services.google.maps_api_key'))) -
- Map -
- @endif + @if (($location->state!='') && ($location->country!='') && (config('services.google.maps_api_key'))) +
+ Map +
+ @endif -
- - - -
- -
+ + + @stop @section('moar_scripts') + + + @include ('partials.bootstrap-table', [ - 'exportFile' => 'locations-export', - 'search' => true - ]) +'exportFile' => 'locations-export', +'search' => true +]) @stop diff --git a/routes/web.php b/routes/web.php index f2534c5062..f3ba8350f2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -66,6 +66,11 @@ Route::group(['middleware' => 'auth'], function () { [LocationsController::class, 'postBulkDeleteStore'] )->name('locations.bulkdelete.store'); + Route::post( + '{location}/restore', + [LocationsController::class, 'postRestore'] + )->name('locations.restore'); + Route::get('{locationId}/clone', [LocationsController::class, 'getClone']