From 162b70d5a954752e9007e3e93ab7843a649e0e10 Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 29 Mar 2023 17:34:36 -0500 Subject: [PATCH 1/7] wireframed, needs a view and should work --- .../Controllers/Assets/BulkAssetsController.php | 16 ++++++++++++++++ resources/views/hardware/index.blade.php | 8 +++++--- .../views/partials/asset-bulk-actions.blade.php | 4 ++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 7f9e812ab..884996d22 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -56,6 +56,14 @@ class BulkAssetsController extends Controller }); return view('hardware/bulk-delete')->with('assets', $assets); + + case 'restore': + $assets = Asset::with('assignedTo', 'location')->find($asset_ids); + $assets->each(function ($asset) { + $this->authorize('restore', $asset); + }); + + return view('hardware/bulk-restore')->with('assets', $assets); case 'edit': return view('hardware/bulk') ->with('assets', $asset_ids) @@ -320,5 +328,13 @@ class BulkAssetsController extends Controller } catch (ModelNotFoundException $e) { return redirect()->route('hardware.bulkcheckout.show')->with('error', $e->getErrors()); } + + } + public function restore(Request $request) { + $assetIds = $request->get('ids'); + foreach ($assetIds as $key => $assetId) { + $asset = Asset::withTrashed()->find($assetId); + $asset->restore(); + } } } diff --git a/resources/views/hardware/index.blade.php b/resources/views/hardware/index.blade.php index a73b37f2c..6f1a4944d 100755 --- a/resources/views/hardware/index.blade.php +++ b/resources/views/hardware/index.blade.php @@ -62,14 +62,16 @@
+ + - @if (Request::get('status')!='Deleted') + {{-- @if (Request::get('status')!='Deleted') --}} - @include('partials.asset-bulk-actions') + @include('partials.asset-bulk-actions', ['status' => Request::get('status')]) - @endif + {{-- @endif --}} From e4c76f454c6a5a419af18c7d6643ceb478fd0a54 Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 29 Mar 2023 18:24:56 -0500 Subject: [PATCH 2/7] this is good, just needs translations done in view --- .../Assets/BulkAssetsController.php | 7 ++- resources/lang/en/admin/hardware/form.php | 3 + .../views/hardware/bulk-restore.blade.php | 62 +++++++++++++++++++ routes/web/hardware.php | 7 ++- 4 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 resources/views/hardware/bulk-restore.blade.php diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 884996d22..efa4078da 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -49,6 +49,7 @@ class BulkAssetsController extends Controller ->with('settings', Setting::getSettings()) ->with('bulkedit', true) ->with('count', 0); + case 'delete': $assets = Asset::with('assignedTo', 'location')->find($asset_ids); $assets->each(function ($asset) { @@ -58,12 +59,13 @@ class BulkAssetsController extends Controller return view('hardware/bulk-delete')->with('assets', $assets); case 'restore': - $assets = Asset::with('assignedTo', 'location')->find($asset_ids); + $assets = Asset::withTrashed()->find($asset_ids); $assets->each(function ($asset) { - $this->authorize('restore', $asset); + $this->authorize('delete', $asset); }); return view('hardware/bulk-restore')->with('assets', $assets); + case 'edit': return view('hardware/bulk') ->with('assets', $asset_ids) @@ -336,5 +338,6 @@ class BulkAssetsController extends Controller $asset = Asset::withTrashed()->find($assetId); $asset->restore(); } + return redirect()->route('hardware.index')->with('success', 'Assets Restored'); } } diff --git a/resources/lang/en/admin/hardware/form.php b/resources/lang/en/admin/hardware/form.php index 22aac61d0..789feb74f 100644 --- a/resources/lang/en/admin/hardware/form.php +++ b/resources/lang/en/admin/hardware/form.php @@ -2,8 +2,11 @@ return [ 'bulk_delete' => 'Confirm Bulk Delete Assets', + 'bulk_restore' => 'Confirm Bulk Restore Assets', 'bulk_delete_help' => 'Review the assets for bulk deletion below. Once deleted, these assets can be restored, but they will no longer be associated with any users they are currently assigned to.', + 'bulk_restore_help' => 'Review the assets for bulk deletion below. Once deleted, these assets can be restored, but they will no longer be associated with any users they are currently assigned to.', 'bulk_delete_warn' => 'You are about to delete :asset_count assets.', + 'bulk_restore_warn' => 'You are about to restore :asset_count assets.', 'bulk_update' => 'Bulk Update Assets', 'bulk_update_help' => 'This form allows you to update multiple assets at once. Only fill in the fields you need to change. Any fields left blank will remain unchanged. ', 'bulk_update_warn' => 'You are about to edit the properties of a single asset.|You are about to edit the properties of :asset_count assets.', diff --git a/resources/views/hardware/bulk-restore.blade.php b/resources/views/hardware/bulk-restore.blade.php new file mode 100644 index 000000000..663cd8102 --- /dev/null +++ b/resources/views/hardware/bulk-restore.blade.php @@ -0,0 +1,62 @@ +@extends('layouts/default') + +{{-- Page title --}} +@section('title') +{{ trans('admin/hardware/form.bulk_delete') }} +@parent +@stop + +@section('header_right') + + {{ trans('general.back') }} +@stop + +{{-- Page content --}} +@section('content') +
+ +
+

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

+
+ {{csrf_field()}} +
+
+

{{ trans('admin/hardware/form.bulk_restore_warn', ['asset_count' => count($assets)]) }}

+
+ +
+
+ + + + + + + + + + @foreach ($assets as $asset) + + + + + + + @endforeach + +
{{ trans('admin/hardware/table.id') }}{{ trans('admin/hardware/table.name') }}{{ trans('admin/hardware/table.location')}}
{{ $asset->id }}{{ $asset->present()->name() }} + @if ($asset->location) + {{ $asset->location->name }} + @endif +
+
+ + +
+ + + +@stop diff --git a/routes/web/hardware.php b/routes/web/hardware.php index 09811d17d..690d8e0d1 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -160,6 +160,11 @@ Route::group( [BulkAssetsController::class, 'destroy'] )->name('hardware/bulkdelete'); + Route::post( + 'bulkrestore', + [BulkAssetsController::class, 'restore'] + )->name('hardware/bulkrestore'); + Route::post( 'bulksave', [BulkAssetsController::class, 'update'] @@ -181,4 +186,4 @@ Route::resource('hardware', 'middleware' => ['auth'], 'parameters' => ['asset' => 'asset_id' ], -]); \ No newline at end of file +]); From d033733fc01f3143338b0cd32e7b42779f6cbfab Mon Sep 17 00:00:00 2001 From: slong753 Date: Wed, 29 Mar 2023 18:30:39 -0500 Subject: [PATCH 3/7] oops, remove a couple things --- resources/lang/en/admin/hardware/form.php | 3 --- resources/views/hardware/index.blade.php | 8 -------- 2 files changed, 11 deletions(-) diff --git a/resources/lang/en/admin/hardware/form.php b/resources/lang/en/admin/hardware/form.php index 789feb74f..22aac61d0 100644 --- a/resources/lang/en/admin/hardware/form.php +++ b/resources/lang/en/admin/hardware/form.php @@ -2,11 +2,8 @@ return [ 'bulk_delete' => 'Confirm Bulk Delete Assets', - 'bulk_restore' => 'Confirm Bulk Restore Assets', 'bulk_delete_help' => 'Review the assets for bulk deletion below. Once deleted, these assets can be restored, but they will no longer be associated with any users they are currently assigned to.', - 'bulk_restore_help' => 'Review the assets for bulk deletion below. Once deleted, these assets can be restored, but they will no longer be associated with any users they are currently assigned to.', 'bulk_delete_warn' => 'You are about to delete :asset_count assets.', - 'bulk_restore_warn' => 'You are about to restore :asset_count assets.', 'bulk_update' => 'Bulk Update Assets', 'bulk_update_help' => 'This form allows you to update multiple assets at once. Only fill in the fields you need to change. Any fields left blank will remain unchanged. ', 'bulk_update_warn' => 'You are about to edit the properties of a single asset.|You are about to edit the properties of :asset_count assets.', diff --git a/resources/views/hardware/index.blade.php b/resources/views/hardware/index.blade.php index 6f1a4944d..a9a0dba58 100755 --- a/resources/views/hardware/index.blade.php +++ b/resources/views/hardware/index.blade.php @@ -63,16 +63,8 @@
- - - {{-- @if (Request::get('status')!='Deleted') --}} - - - @include('partials.asset-bulk-actions', ['status' => Request::get('status')]) - {{-- @endif --}} - Date: Wed, 29 Mar 2023 19:53:04 -0500 Subject: [PATCH 4/7] fix permissions stuff + optional parameter --- resources/views/partials/asset-bulk-actions.blade.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/views/partials/asset-bulk-actions.blade.php b/resources/views/partials/asset-bulk-actions.blade.php index 02e2b6b4b..c57e232a1 100644 --- a/resources/views/partials/asset-bulk-actions.blade.php +++ b/resources/views/partials/asset-bulk-actions.blade.php @@ -13,8 +13,10 @@