Skip to content

A free open source IT asset/license management system

Added location restore

snipe229d8b9bf573
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] [<[email protected]>]
+ * @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')
+<a href="{{ route('locations.index') }}" class="btn btn-primary" style="margin-right: 10px;">
+ {{ trans('general.back') }}</a>
+@endsection
{{-- Page content --}}
@section('content')
@@ -382,65 +386,113 @@
<div class="col-md-3">
+ @can('update', $location)
<div class="col-md-12">
- <a href="{{ route('locations.edit', ['location' => $location->id]) }}" style="width: 100%;" class="btn btn-sm btn-primary pull-left">{{ trans('admin/locations/table.update') }} </a>
+ <a href="{{ route('locations.edit', ['location' => $location->id]) }}" style="width: 100%;" class="btn btn-sm btn-warning btn-social">
+ <x-icon type="edit" />
+ {{ trans('admin/locations/table.update') }}
+ </a>
</div>
+ @endcan
+
<div class="col-md-12" style="padding-top: 5px;">
- <a href="{{ route('locations.print_assigned', ['locationId' => $location->id]) }}" style="width: 100%;" class="btn btn-sm btn-default pull-left">{{ trans('admin/locations/table.print_assigned') }} </a>
+ <a href="{{ route('locations.print_assigned', ['locationId' => $location->id]) }}" style="width: 100%;" class="btn btn-sm btn-primary btn-social hidden-print">
+ <x-icon type="print" />
+ {{ trans('admin/locations/table.print_assigned') }}
+ </a>
</div>
<div class="col-md-12" style="padding-top: 5px; padding-bottom: 20px;">
- <a href="{{ route('locations.print_all_assigned', ['locationId' => $location->id]) }}" style="width: 100%;" class="btn btn-sm btn-default pull-left">{{ trans('admin/locations/table.print_all_assigned') }} </a>
+ <a href="{{ route('locations.print_all_assigned', ['locationId' => $location->id]) }}" style="width: 100%;" class="btn btn-sm btn-primary btn-social hidden-print">
+ <x-icon type="print" />
+ {{ trans('admin/locations/table.print_all_assigned') }}
+ </a>
</div>
+ @can('delete', $location)
+ <div class="col-md-12 hidden-print" style="padding-top: 10px;">
+
+ @if ($location->deleted_at=='')
+
+ @if ($location->isDeletable())
+ <button class="btn btn-sm btn-block btn-danger btn-social delete-location" data-toggle="modal" data-title="{{ trans('general.delete') }}" data-content="{{ trans('general.sure_to_delete_var', ['item' => $location->name]) }}" data-target="#dataConfirmModal">
+ <x-icon type="delete" />
+ {{ trans('general.delete') }}
+ </button>
+ @else
+ <a href="#" class="btn btn-block btn-sm btn-danger btn-social hidden-print disabled" data-tooltip="true" data-placement="top" data-title="{{ trans('general.cannot_be_deleted') }}">
+ <x-icon type="delete" />
+ {{ trans('general.delete') }}
+ </a>
+ @endif
+
+ @else
+ <form method="POST" action="{{ route('locations.restore', ['location' => $location->id]) }}">
+ @csrf
+ <button class="btn btn-sm btn-block btn-warning btn-social delete-asset">
+ <x-icon type="restore" />
+ {{ trans('general.restore') }}
+ </button>
+ </form>
+ @endif
+ </div>
+ @endcan
+
@if ($location->image!='')
- <div class="col-md-12 text-center" style="padding-bottom: 20px;">
- <img src="{{ Storage::disk('public')->url('locations/'.e($location->image)) }}" class="img-responsive img-thumbnail" style="width:100%" alt="{{ $location->name }}">
- </div>
+ <div class="col-md-12 text-center" style="padding-bottom: 20px;">
+ <img src="{{ Storage::disk('public')->url('locations/'.e($location->image)) }}" class="img-responsive img-thumbnail" style="width:100%" alt="{{ $location->name }}">
+ </div>
@endif
- <div class="col-md-12">
+
+ <div class="col-md-12">
<ul class="list-unstyled" style="line-height: 25px; padding-bottom: 20px;">
- @if ($location->address!='')
+ @if ($location->address!='')
<li>{{ $location->address }}</li>
- @endif
- @if ($location->address2!='')
- <li>{{ $location->address2 }}</li>
- @endif
- @if (($location->city!='') || ($location->state!='') || ($location->zip!=''))
- <li>{{ $location->city }} {{ $location->state }} {{ $location->zip }}</li>
- @endif
- @if ($location->manager)
- <li>{{ trans('admin/users/table.manager') }}: {!! $location->manager->present()->nameUrl() !!}</li>
- @endif
- @if ($location->parent)
- <li>{{ trans('admin/locations/table.parent') }}: {!! $location->parent->present()->nameUrl() !!}</li>
- @endif
- @if ($location->ldap_ou)
- <li>{{ trans('admin/locations/table.ldap_ou') }}: {{ $location->ldap_ou }}</li>
- @endif
- </ul>
-
- @if (($location->state!='') && ($location->country!='') && (config('services.google.maps_api_key')))
- <div class="col-md-12 text-center">
- <img src="https://maps.googleapis.com/maps/api/staticmap?markers={{ urlencode($location->address.','.$location->city.' '.$location->state.' '.$location->country.' '.$location->zip) }}&size=700x500&maptype=roadmap&key={{ config('services.google.maps_api_key') }}" class="img-thumbnail" style="width:100%" alt="Map">
- </div>
@endif
+ @if ($location->address2!='')
+ <li>{{ $location->address2 }}</li>
+ @endif
+ @if (($location->city!='') || ($location->state!='') || ($location->zip!=''))
+ <li>{{ $location->city }} {{ $location->state }} {{ $location->zip }}</li>
+ @endif
+ @if ($location->manager)
+ <li>{{ trans('admin/users/table.manager') }}: {!! $location->manager->present()->nameUrl() !!}</li>
+ @endif
+ @if ($location->parent)
+ <li>{{ trans('admin/locations/table.parent') }}: {!! $location->parent->present()->nameUrl() !!}</li>
+ @endif
+ @if ($location->ldap_ou)
+ <li>{{ trans('admin/locations/table.ldap_ou') }}: {{ $location->ldap_ou }}</li>
+ @endif
+ </ul>
- </div>
-
-
-
- </div>
+ @if (($location->state!='') && ($location->country!='') && (config('services.google.maps_api_key')))
+ <div class="col-md-12 text-center">
+ <img src="https://maps.googleapis.com/maps/api/staticmap?markers={{ urlencode($location->address.','.$location->city.' '.$location->state.' '.$location->country.' '.$location->zip) }}&size=700x500&maptype=roadmap&key={{ config('services.google.maps_api_key') }}" class="img-thumbnail" style="width:100%" alt="Map">
+ </div>
+ @endif
- </div>
+</div>
+</div>
</div>
+
@stop
@section('moar_scripts')
+
+ <script>
+ $('#dataConfirmModal').on('show.bs.modal', function (event) {
+ var content = $(event.relatedTarget).data('content');
+ var title = $(event.relatedTarget).data('title');
+ $(this).find(".modal-body").text(content);
+ $(this).find(".modal-header").text(title);
+ });
+ </script>
+
@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']