A free open source IT asset/license management system
adds dynamic redirects to Assets
Godfrey M15cc4345abbf
diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.phpindex 8687be1e7e..b839b287e1 100644--- a/app/Helpers/Helper.php+++ b/app/Helpers/Helper.php@@ -1464,6 +1464,7 @@ class Helperstatic public function getRedirectOption($request, $assetId){$redirect_option = session::get('redirect_option');+ $checkout_to_type = session::get('checkout_to_type');if ($redirect_option == '0') {return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.checkout.success'));@@ -1472,15 +1473,18 @@ class Helperreturn redirect()->route('hardware.show', $assetId)->with('success', trans('admin/hardware/message.checkout.success'));}if ($redirect_option == '2') {- if ($request->assigned_location != null) {++ if ($checkout_to_type == 'user') {return redirect()->route('users.show', $request->assigned_user)->with('success', trans('admin/hardware/message.checkout.success'));}- }- if ($redirect_option == '3') {- if ($request->assigned_location != null) {+ if ($checkout_to_type == 'location') {return redirect()->route('locations.show', $request->assigned_location)->with('success', trans('admin/hardware/message.checkout.success'));}+ if ($checkout_to_type == 'asset') {+ return redirect()->route('hardware.show', $request->assigned_asset)->with('success', trans('admin/hardware/message.checkout.success'));+ }}+ return redirect()->back()->with('error', trans('admin/hardware/message.checkout.error'));}}diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.phpindex 30ffd8bba2..0be355c7a4 100644--- a/app/Http/Controllers/Assets/AssetCheckinController.php+++ b/app/Http/Controllers/Assets/AssetCheckinController.php@@ -45,7 +45,7 @@ class AssetCheckinController extends Controllerreturn redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.already_checked_in'));}- return view('hardware/checkin', compact('asset'))->with('statusLabel_list', Helper::statusLabelList())->with('backto', $backto);+ return view('hardware/checkin', compact('asset'))->with('statusLabel_list', Helper::statusLabelList())->with('backto', $backto)->with('table_name', 'Assets');}/**@@ -125,12 +125,7 @@ class AssetCheckinController extends Controller// Was the asset updated?if ($asset->save()) {event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note'), $checkin_at, $originalValues));-- if ((isset($user)) && ($backto == 'user')) {- return redirect()->route('users.show', $user->id)->with('success', trans('admin/hardware/message.checkin.success'));- }-- return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.checkin.success'));+ return Helper::getRedirectOption($request, $assetId);}// Redirect to the asset management page with errorreturn redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.error').$asset->getErrors());diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.phpindex e5f069c411..8e54474a4d 100644--- a/app/Http/Controllers/Assets/AssetCheckoutController.php+++ b/app/Http/Controllers/Assets/AssetCheckoutController.php@@ -36,7 +36,8 @@ class AssetCheckoutController extends Controllerif ($asset->availableForCheckout()) {return view('hardware/checkout', compact('asset'))- ->with('statusLabel_list', Helper::deployableStatusLabelList());+ ->with('statusLabel_list', Helper::deployableStatusLabelList())+ ->with('table_name', 'Assets');}return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkout.not_available'));@@ -100,7 +101,7 @@ class AssetCheckoutController extends Controller}$redirect_option = $request->get('redirect_option');if($redirect_option != Session::get('redirect_option')) {- Session::put('redirect_option', $redirect_option);+ Session::put(['redirect_option' => $redirect_option, 'checkout_to_type' => $request->get('checkout_to_type')]);}if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, $request->get('note'), $request->get('name'))) {diff --git a/resources/lang/en-US/admin/hardware/form.php b/resources/lang/en-US/admin/hardware/form.phpindex a7aba0813c..edec543637 100644--- a/resources/lang/en-US/admin/hardware/form.php+++ b/resources/lang/en-US/admin/hardware/form.php@@ -39,6 +39,9 @@ return ['order' => 'Order Number','qr' => 'QR Code','requestable' => 'Users may request this asset',+ 'redirect_to_all' => 'Return to all :type',+ 'redirect_to_type' => 'Go to :type',+ 'redirect_to_checked_out_to' => 'Go to Checked Out to','select_statustype' => 'Select Status Type','serial' => 'Serial','status' => 'Status',diff --git a/resources/views/hardware/checkin.blade.php b/resources/views/hardware/checkin.blade.phpindex dd6237b1bd..7651f22e2b 100755--- a/resources/views/hardware/checkin.blade.php+++ b/resources/views/hardware/checkin.blade.php@@ -104,6 +104,12 @@<div class="box-footer"><a class="btn btn-link" href="{{ URL::previous() }}"> {{ trans('button.cancel') }}</a><button type="submit" class="btn btn-primary pull-right"><i class="fas fa-check icon-white" aria-hidden="true"></i> {{ trans('general.checkin') }}</button>+ <div class="btn-group pull-right">+ <select class="redirect-options form-control" name="redirect_option">+ <option {{Session::get('redirect_option')=="0" ? 'selected' : ''}} value="0">{{trans('admin/hardware/form.redirect_to_all', ['type' => $table_name])}}</option>+ <option {{Session::get('redirect_option')=="1" ? 'selected' : ''}} value="1">{{trans('admin/hardware/form.redirect_to_type', ['type' => $asset->model->name])}}</option>+ </select>+ </div></div></form></div> <!--/.col-md-12-->diff --git a/resources/views/hardware/checkout.blade.php b/resources/views/hardware/checkout.blade.phpindex c731fa88ae..a67c19b473 100755--- a/resources/views/hardware/checkout.blade.php+++ b/resources/views/hardware/checkout.blade.php@@ -145,15 +145,11 @@<a class="btn btn-link" href="{{ URL::previous() }}"> {{ trans('button.cancel') }}</a><button type="submit" class="btn btn-primary pull-right"><i class="fas fa-check icon-white" aria-hidden="true"></i> {{ trans('general.checkout') }}</button><div class="btn-group pull-right">- <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">- <select class="redirect-options js-states form-control" name="redirect_option">- <option value="0">Return to all Assets</option>- <option value="1">Go to Asset</option>- <option value="2">Go to User</option>- <option value="3">Go to Location</option>+ <select class="redirect-options form-control" name="redirect_option">+ <option {{Session::get('redirect_option')=="0" ? 'selected' : ''}} value="0">{{trans('admin/hardware/form.redirect_to_all', ['type' => $table_name])}}</option>+ <option {{Session::get('redirect_option')=="1" ? 'selected' : ''}} value="1">{{trans('admin/hardware/form.redirect_to_type', ['type' => $asset->model->name])}}</option>+ <option {{Session::get('redirect_option')=="2" ? 'selected' : ''}} value="2">{{trans('admin/hardware/form.redirect_to_checked_out_to')}}</option></select>- </button>-</div></div></form>