adds dynamic redirects to Assets

This commit is contained in:
Godfrey M 2024-05-14 13:25:52 -07:00
parent c94a7613ca
commit 15cc4345ab
6 changed files with 26 additions and 21 deletions

View file

@ -1464,6 +1464,7 @@ class Helper
static 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 Helper
return 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'));
}
}

View file

@ -45,7 +45,7 @@ class AssetCheckinController extends Controller
return 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 error
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.error').$asset->getErrors());

View file

@ -36,7 +36,8 @@ class AssetCheckoutController extends Controller
if ($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'))) {

View file

@ -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',

View file

@ -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-->

View file

@ -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>