Merge pull request #14740 from Godmartinz/redirect_back_to_asset
Added Redirect options to asset check in/out
This commit is contained in:
commit
aadee068b3
9 changed files with 124 additions and 23 deletions
|
@ -1463,4 +1463,38 @@ class Helper
|
||||||
return $new_locale; // better that you have some weird locale that doesn't fit into our mappings anywhere than 'void'
|
return $new_locale; // better that you have some weird locale that doesn't fit into our mappings anywhere than 'void'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static public function getRedirectOption($request, $id, $table, $asset_id = null)
|
||||||
|
{
|
||||||
|
|
||||||
|
$redirect_option = Session::get('redirect_option');
|
||||||
|
$checkout_to_type = Session::get('checkout_to_type');
|
||||||
|
|
||||||
|
//return to index
|
||||||
|
if ($redirect_option == '0') {
|
||||||
|
switch ($table) {
|
||||||
|
case "Assets":
|
||||||
|
return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.checkout.success'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//return to thing being assigned
|
||||||
|
if ($redirect_option == '1') {
|
||||||
|
switch ($table) {
|
||||||
|
case "Assets":
|
||||||
|
return redirect()->route('hardware.show', $id ? $id : $asset_id)->with('success', trans('admin/hardware/message.checkout.success'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//return to thing being assigned to
|
||||||
|
if ($redirect_option == '2') {
|
||||||
|
switch ($checkout_to_type) {
|
||||||
|
case 'user':
|
||||||
|
return redirect()->route('users.show', $request->assigned_user)->with('success', trans('admin/hardware/message.checkout.success'));
|
||||||
|
case 'location':
|
||||||
|
return redirect()->route('locations.show', $request->assigned_location)->with('success', trans('admin/hardware/message.checkout.success'));
|
||||||
|
case '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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ use App\Models\LicenseSeat;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Redirect;
|
use Illuminate\Support\Facades\Redirect;
|
||||||
|
use Illuminate\Support\Facades\Session;
|
||||||
use Illuminate\Support\Facades\View;
|
use Illuminate\Support\Facades\View;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ class AssetCheckinController extends Controller
|
||||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.already_checked_in'));
|
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');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -123,15 +124,12 @@ class AssetCheckinController extends Controller
|
||||||
$acceptance->delete();
|
$acceptance->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Session::put('redirect_option', $request->get('redirect_option'));
|
||||||
// Was the asset updated?
|
// Was the asset updated?
|
||||||
if ($asset->save()) {
|
if ($asset->save()) {
|
||||||
|
|
||||||
event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note'), $checkin_at, $originalValues));
|
event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note'), $checkin_at, $originalValues));
|
||||||
|
return Helper::getRedirectOption($asset, $assetId, 'Assets');
|
||||||
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'));
|
|
||||||
}
|
}
|
||||||
// Redirect to the asset management page with error
|
// Redirect to the asset management page with error
|
||||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.error').$asset->getErrors());
|
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.error').$asset->getErrors());
|
||||||
|
|
|
@ -10,6 +10,7 @@ use App\Http\Requests\AssetCheckoutRequest;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Session;
|
||||||
|
|
||||||
class AssetCheckoutController extends Controller
|
class AssetCheckoutController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -35,7 +36,8 @@ class AssetCheckoutController extends Controller
|
||||||
|
|
||||||
if ($asset->availableForCheckout()) {
|
if ($asset->availableForCheckout()) {
|
||||||
return view('hardware/checkout', compact('asset'))
|
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'));
|
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkout.not_available'));
|
||||||
|
@ -98,10 +100,11 @@ class AssetCheckoutController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, $request->get('note'), $request->get('name'))) {
|
Session::put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);
|
||||||
return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.checkout.success'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, $request->get('note'), $request->get('name'))) {
|
||||||
|
return Helper::getRedirectOption($request, $assetId, 'Assets');
|
||||||
|
}
|
||||||
// Redirect to the asset management page with error
|
// Redirect to the asset management page with error
|
||||||
return redirect()->to("hardware/$assetId/checkout")->with('error', trans('admin/hardware/message.checkout.error').$asset->getErrors());
|
return redirect()->to("hardware/$assetId/checkout")->with('error', trans('admin/hardware/message.checkout.error').$asset->getErrors());
|
||||||
} catch (ModelNotFoundException $e) {
|
} catch (ModelNotFoundException $e) {
|
||||||
|
|
|
@ -39,6 +39,9 @@ return [
|
||||||
'order' => 'Order Number',
|
'order' => 'Order Number',
|
||||||
'qr' => 'QR Code',
|
'qr' => 'QR Code',
|
||||||
'requestable' => 'Users may request this asset',
|
'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',
|
'select_statustype' => 'Select Status Type',
|
||||||
'serial' => 'Serial',
|
'serial' => 'Serial',
|
||||||
'status' => 'Status',
|
'status' => 'Status',
|
||||||
|
|
|
@ -101,10 +101,7 @@
|
||||||
{!! $errors->first('note', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
|
{!! $errors->first('note', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-footer">
|
@include ('partials.forms.redirect_submit_options', ['route' => 'hardware.index', 'table_name' => $table_name, 'type'=> $asset->model->name, 'checkin' => true])
|
||||||
<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>
|
|
||||||
</form>
|
</form>
|
||||||
</div> <!--/.col-md-12-->
|
</div> <!--/.col-md-12-->
|
||||||
</div> <!--/.box-body-->
|
</div> <!--/.box-body-->
|
||||||
|
|
|
@ -141,10 +141,7 @@
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
</div> <!--/.box-body-->
|
</div> <!--/.box-body-->
|
||||||
<div class="box-footer">
|
@include ('partials.forms.redirect_submit_options', ['route' => 'hardware.index', 'table_name' => $table_name, 'type'=> $asset->model->name, 'checkin' => false])
|
||||||
<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>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div> <!--/.col-md-7-->
|
</div> <!--/.col-md-7-->
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
<div class="box-footer">
|
||||||
|
<a class="btn btn-link" href="{{ route($route) }}">{{ trans('button.cancel') }}</a>
|
||||||
|
<button type="submit" class="btn btn-primary pull-right"><i class="fas fa-check icon-white" aria-hidden="true"></i> {{$checkin ? trans('general.checkin') : trans('general.checkout') }}</button>
|
||||||
|
<div class="btn-group pull-right" style="margin-right:5px;">
|
||||||
|
<select class="redirect-options form-control" name="redirect_option">
|
||||||
|
<option {{(Session::get('redirect_option')=="0" || (Session::get('redirect_option')=="2" && $checkin)) ? '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' => $type])}}</option>
|
||||||
|
<option {{(Session::get('redirect_option')=="2" && !$checkin) ? 'selected' : ''}} value="2" >{{trans('admin/hardware/form.redirect_to_checked_out_to')}}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div> <!-- /.box-->
|
|
@ -51,14 +51,13 @@ class AssetCheckinTest extends TestCase
|
||||||
|
|
||||||
$this->actingAs(User::factory()->checkinAssets()->create())
|
$this->actingAs(User::factory()->checkinAssets()->create())
|
||||||
->post(
|
->post(
|
||||||
route('hardware.checkin.store', ['assetId' => $asset->id, 'backto' => 'user']),
|
route('hardware.checkin.store', ['assetId' => $asset->id]),
|
||||||
[
|
[
|
||||||
'name' => 'Changed Name',
|
'name' => 'Changed Name',
|
||||||
'status_id' => $status->id,
|
'status_id' => $status->id,
|
||||||
'location_id' => $location->id,
|
'location_id' => $location->id,
|
||||||
],
|
],
|
||||||
)
|
);
|
||||||
->assertRedirect(route('users.show', $user));
|
|
||||||
|
|
||||||
$this->assertNull($asset->refresh()->assignedTo);
|
$this->assertNull($asset->refresh()->assignedTo);
|
||||||
$this->assertNull($asset->expected_checkin);
|
$this->assertNull($asset->expected_checkin);
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
namespace Tests\Unit\Helpers;
|
namespace Tests\Unit\Helpers;
|
||||||
|
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Support\Facades\Redirect;
|
||||||
|
use Illuminate\Support\Facades\Session;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class HelperTest extends TestCase
|
class HelperTest extends TestCase
|
||||||
|
@ -25,4 +28,60 @@ class HelperTest extends TestCase
|
||||||
$this->settings->set(['digit_separator' => '1.234,56']);
|
$this->settings->set(['digit_separator' => '1.234,56']);
|
||||||
$this->assertSame(12.34, Helper::ParseCurrency('12,34'));
|
$this->assertSame(12.34, Helper::ParseCurrency('12,34'));
|
||||||
}
|
}
|
||||||
|
public function testGetRedirectOptionMethod()
|
||||||
|
{
|
||||||
|
$test_data = [
|
||||||
|
'Option 2: redirect for user assigned to ' => [
|
||||||
|
'request' =>(object) ['assigned_user' => 22],
|
||||||
|
'id' => 1,
|
||||||
|
'checkout_to_type' => 'user',
|
||||||
|
'redirect_option' => 2,
|
||||||
|
'table' => 'Assets',
|
||||||
|
'route' => route('users.show', 22),
|
||||||
|
],
|
||||||
|
'Option 2: redirect location assigned to ' => [
|
||||||
|
'request' =>(object) ['assigned_location' => 10],
|
||||||
|
'id' => 2,
|
||||||
|
'checkout_to_type' => 'location',
|
||||||
|
'redirect_option' => 2,
|
||||||
|
'table' => 'Locations',
|
||||||
|
'route' => route('locations.show', 10),
|
||||||
|
],
|
||||||
|
'Option 2: redirect back to asset assigned to ' => [
|
||||||
|
'request' =>(object) ['assigned_asset' => 101],
|
||||||
|
'id' => 3,
|
||||||
|
'checkout_to_type' => 'asset',
|
||||||
|
'redirect_option' => 2,
|
||||||
|
'table' => 'Assets',
|
||||||
|
'route' => route('hardware.show', 101),
|
||||||
|
],
|
||||||
|
'Option 1: redirect back to asset ' => [
|
||||||
|
'request' =>(object) ['assigned_asset' => null],
|
||||||
|
'id' => 999,
|
||||||
|
'checkout_to_type' => null,
|
||||||
|
'redirect_option' => 1,
|
||||||
|
'table' => 'Assets',
|
||||||
|
'route' => route('hardware.show', 999),
|
||||||
|
],
|
||||||
|
'Option 0: redirect back to index ' => [
|
||||||
|
'request' =>(object) ['assigned_asset' => null],
|
||||||
|
'id' => null,
|
||||||
|
'checkout_to_type' => null,
|
||||||
|
'redirect_option' => 0,
|
||||||
|
'table' => 'Assets',
|
||||||
|
'route' => route('hardware.index'),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($test_data as $scenario => $data ) {
|
||||||
|
|
||||||
|
Session::put('redirect_option', $data['redirect_option']);
|
||||||
|
Session::put('checkout_to_type', $data['checkout_to_type']);
|
||||||
|
|
||||||
|
$redirect = Helper::getRedirectOption($data['request'],$data['id'], $data['table']);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(RedirectResponse::class, $redirect);
|
||||||
|
$this->assertEquals($data['route'], $redirect->getTargetUrl(), $scenario.'failed.');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue