diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 0e519251ad..4aede02a81 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -11,6 +11,7 @@ use App\Models\Setting; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Session; class BulkAssetsController extends Controller { @@ -30,9 +31,17 @@ class BulkAssetsController extends Controller $this->authorize('update', Asset::class); if (! $request->filled('ids')) { - return redirect()->back()->with('error', 'No assets selected'); + return redirect()->back()->with('error', trans('admin/hardware/message.update.no_assets_selected')); + } + // Figure out where we need to send the user after the update is complete, and store that in the session + $bulk_back_url = request()->headers->get('referer'); + session(['bulk_back_url' => $bulk_back_url]); + + \Log::debug('Back to url: '.$bulk_back_url); + + $asset_ids = array_values(array_unique($request->input('ids'))); @@ -73,10 +82,15 @@ class BulkAssetsController extends Controller { $this->authorize('update', Asset::class); - \Log::debug($request->input('ids')); + // Get the back url from the session and then destroy the session + $bulk_back_url = route('hardware'); + if ($request->session()->has('bulk_back_url')) { + $bulk_back_url = $request->session()->pull('bulk_back_url'); + } + if (! $request->filled('ids') || count($request->input('ids')) <= 0) { - return redirect()->route('hardware.index')->with('warning', trans('No assets selected, so nothing was updated.')); + return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.update.no_assets_selected')); } $assets = array_keys($request->input('ids')); @@ -147,11 +161,13 @@ class BulkAssetsController extends Controller ->update($this->update_array); } // endforeach - return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.update.success')); - // no values given, nothing to update + return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success')); + + } - return redirect()->route('hardware.index')->with('warning', trans('admin/hardware/message.update.nothing_updated')); + // no values given, nothing to update + return redirect($bulk_back_url)->with('warning', trans('admin/hardware/message.update.nothing_updated')); } /** @@ -188,6 +204,11 @@ class BulkAssetsController extends Controller { $this->authorize('delete', Asset::class); + $bulk_back_url = route('hardware'); + if ($request->session()->has('bulk_back_url')) { + $bulk_back_url = $request->session()->pull('bulk_back_url'); + } + if ($request->filled('ids')) { $assets = Asset::find($request->get('ids')); foreach ($assets as $asset) { @@ -199,11 +220,11 @@ class BulkAssetsController extends Controller ->update($update_array); } // endforeach - return redirect()->to('hardware')->with('success', trans('admin/hardware/message.delete.success')); + return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.delete.success')); // no values given, nothing to update } - return redirect()->to('hardware')->with('info', trans('admin/hardware/message.delete.nothing_updated')); + return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.delete.nothing_updated')); } /** @@ -224,6 +245,9 @@ class BulkAssetsController extends Controller */ public function storeCheckout(Request $request) { + + $this->authorize('checkout', Asset::class); + try { $admin = Auth::user(); diff --git a/app/Presenters/AssetAuditPresenter.php b/app/Presenters/AssetAuditPresenter.php index 96cf89b841..4129ea9fd3 100644 --- a/app/Presenters/AssetAuditPresenter.php +++ b/app/Presenters/AssetAuditPresenter.php @@ -17,6 +17,10 @@ class AssetAuditPresenter extends Presenter public static function dataTableLayout() { $layout = [ + [ + 'field' => 'checkbox', + 'checkbox' => true, + ], [ 'field' => 'id', 'searchable' => false, diff --git a/resources/lang/am/admin/hardware/message.php b/resources/lang/am/admin/hardware/message.php index 8c8e323a73..1d8fb1874b 100644 --- a/resources/lang/am/admin/hardware/message.php +++ b/resources/lang/am/admin/hardware/message.php @@ -14,9 +14,10 @@ return [ ], 'update' => [ - 'error' => 'Asset was not updated, please try again', - 'success' => 'Asset updated successfully.', - 'nothing_updated' => 'No fields were selected, so nothing was updated.', + 'error' => 'Asset was not updated, please try again', + 'success' => 'Asset updated successfully.', + 'nothing_updated' => 'No fields were selected, so nothing was updated.', + 'no_assets_selected' => 'No assets were selected, so nothing was updated.', ], 'restore' => [ diff --git a/resources/lang/en/admin/hardware/message.php b/resources/lang/en/admin/hardware/message.php index 8c8e323a73..d2214ce00c 100644 --- a/resources/lang/en/admin/hardware/message.php +++ b/resources/lang/en/admin/hardware/message.php @@ -17,6 +17,7 @@ return [ 'error' => 'Asset was not updated, please try again', 'success' => 'Asset updated successfully.', 'nothing_updated' => 'No fields were selected, so nothing was updated.', + 'no_assets_selected' => 'No assets were selected, so nothing was updated.', ], 'restore' => [ diff --git a/resources/views/categories/view.blade.php b/resources/views/categories/view.blade.php index 304ccbe92b..2cf0960c9b 100644 --- a/resources/views/categories/view.blade.php +++ b/resources/views/categories/view.blade.php @@ -28,6 +28,9 @@