From dc418a70331bc351e110e64febdb67f1b73972d4 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 14 May 2024 14:09:54 -0700 Subject: [PATCH] need to make variables names uniform --- app/Helpers/Helper.php | 33 ++-- .../Licenses/LicenseCheckoutController.php | 13 +- resources/views/licenses/checkout.blade.php | 177 +++++++++--------- .../forms/redirect_submit_options.blade.php | 13 ++ 4 files changed, 130 insertions(+), 106 deletions(-) create mode 100644 resources/views/partials/forms/redirect_submit_options.blade.php diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index b839b287e1..ff67985091 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -1461,27 +1461,34 @@ class Helper } - static public function getRedirectOption($request, $assetId) - { + static public function getRedirectOption($request, $Id, $table) + { dd($request); $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')); + switch ($table) { + case "Assets": + return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.checkout.success')); + case "Licenses": + return redirect()->route('licenses.index')->with('success', trans('admin/hardware/message.checkout.success')); + } } if ($redirect_option == '1') { - return redirect()->route('hardware.show', $assetId)->with('success', trans('admin/hardware/message.checkout.success')); + switch ($table) { + case "Assets": + return redirect()->route('hardware.show', $Id)->with('success', trans('admin/hardware/message.checkout.success')); + case "Licenses": + return redirect()->route('licenses.show', $Id)->with('success', trans('admin/hardware/message.checkout.success')); + } } if ($redirect_option == '2') { - - if ($checkout_to_type == 'user') { - return redirect()->route('users.show', $request->assigned_user)->with('success', trans('admin/hardware/message.checkout.success')); - } - 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') { + 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')); } } diff --git a/app/Http/Controllers/Licenses/LicenseCheckoutController.php b/app/Http/Controllers/Licenses/LicenseCheckoutController.php index d61a1ad819..aa2a32e692 100644 --- a/app/Http/Controllers/Licenses/LicenseCheckoutController.php +++ b/app/Http/Controllers/Licenses/LicenseCheckoutController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Licenses; use App\Events\CheckoutableCheckedOut; +use App\Helpers\Helper; use App\Http\Controllers\Controller; use App\Http\Requests\LicenseCheckoutRequest; use App\Models\Accessory; @@ -11,6 +12,7 @@ use App\Models\License; use App\Models\LicenseSeat; use App\Models\User; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Session; class LicenseCheckoutController extends Controller { @@ -41,7 +43,7 @@ class LicenseCheckoutController extends Controller } // Return the checkout view - return view('licenses/checkout', compact('license')); + return view('licenses/checkout', compact('license'))->with('table_name' , 'Licenses'); } // Invalid category @@ -77,11 +79,15 @@ class LicenseCheckoutController extends Controller $licenseSeat = $this->findLicenseSeatToCheckout($license, $seatId); $licenseSeat->user_id = Auth::id(); $licenseSeat->notes = $request->input('notes'); - $checkoutMethod = 'checkoutTo'.ucwords(request('checkout_to_type')); + $redirect_option = $request->get('redirect_option'); + Session::put('checkout_to_type', $request->input('checkout_to_type')); + if($redirect_option != Session::get('redirect_option')) { + Session::put(['redirect_option' => $redirect_option]); + } if ($this->$checkoutMethod($licenseSeat)) { - return redirect()->route('licenses.index')->with('success', trans('admin/licenses/message.checkout.success')); + return Helper::getRedirectOption($request, $licenseId, 'Licenses'); } return redirect()->route('licenses.index')->with('error', trans('Something went wrong handling this checkout.')); @@ -112,7 +118,6 @@ class LicenseCheckoutController extends Controller return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.asset_does_not_exist')); } $licenseSeat->asset_id = request('asset_id'); - // Override asset's assigned user if available if ($target->checkedOutToUser()) { $licenseSeat->assigned_to = $target->assigned_to; diff --git a/resources/views/licenses/checkout.blade.php b/resources/views/licenses/checkout.blade.php index e85c677420..3bf6350739 100755 --- a/resources/views/licenses/checkout.blade.php +++ b/resources/views/licenses/checkout.blade.php @@ -2,8 +2,8 @@ {{-- Page title --}} @section('title') - {{ trans('admin/licenses/general.checkout') }} -@parent + {{ trans('admin/licenses/general.checkout') }} + @parent @stop @section('header_right') @@ -13,105 +13,104 @@ {{-- Page content --}} @section('content') -
+
-
-
- {{csrf_field()}} +
+ + {{csrf_field()}} -
-
-

{{ $license->name }} ({{ trans('admin/licenses/message.seats_available', ['seat_count' => $license->availCount()->count()]) }})

-
-
- - - -
- -
-

{{ $license->name }}

-
+
+
+

{{ $license->name }} + ({{ trans('admin/licenses/message.seats_available', ['seat_count' => $license->availCount()->count()]) }} + )

- -
- -
-

{{ $license->category->name }}

+
+ + + +
+ +
+

{{ $license->name }}

+
-
- - -
- -
-

- @can('viewKeys', $license) - {{ $license->serial }} - @else - ------------ - @endcan -

+ +
+ +
+

{{ $license->category->name }}

+
-
- @include ('partials.forms.checkout-selector', ['user_select' => 'true','asset_select' => 'true', 'location_select' => 'false']) - - @include ('partials.forms.edit.user-select', ['translated_name' => trans('general.user'), 'fieldname' => 'assigned_to', 'required'=>'true']) - - @include ('partials.forms.edit.asset-select', ['translated_name' => trans('admin/licenses/form.asset'), 'fieldname' => 'asset_id', 'style' => 'display:none;']) - - - -
- -
- - {!! $errors->first('note', '') !!} + +
+ +
+

+ @can('viewKeys', $license) + {{ $license->serial }} + @else + ------------ + @endcan +

+
-
-
+ + @include ('partials.forms.checkout-selector', ['user_select' => 'true','asset_select' => 'true', 'location_select' => 'false']) + + @include ('partials.forms.edit.user-select', ['translated_name' => trans('general.user'), 'fieldname' => 'assigned_to', 'required'=>'true']) + + @include ('partials.forms.edit.asset-select', ['translated_name' => trans('admin/licenses/form.asset'), 'fieldname' => 'asset_id', 'style' => 'display:none;']) - @if ($license->requireAcceptance() || $license->getEula() || ($snipeSettings->webhook_endpoint!='')) -
-
-
- - @if ($license->requireAcceptance()) - - {{ trans('admin/categories/general.required_acceptance') }} -
- @endif - - @if ($license->getEula()) - - {{ trans('admin/categories/general.required_eula') }} -
- @endif - - @if (($license->category) && ($license->category->checkin_email)) - - {{ trans('admin/categories/general.checkin_email_notification') }} -
- @endif - - @if ($snipeSettings->webhook_endpoint!='') - - {{ trans('general.webhook_msg_note') }} - @endif + +
+ +
+ + {!! $errors->first('note', '') !!}
- @endif - -
- -
-
+ + @if ($license->requireAcceptance() || $license->getEula() || ($snipeSettings->webhook_endpoint!='')) +
+
+
+ + @if ($license->requireAcceptance()) + + {{ trans('admin/categories/general.required_acceptance') }} +
+ @endif + + @if ($license->getEula()) + + {{ trans('admin/categories/general.required_eula') }} +
+ @endif + + @if (($license->category) && ($license->category->checkin_email)) + + {{ trans('admin/categories/general.checkin_email_notification') }} +
+ @endif + + @if ($snipeSettings->webhook_endpoint!='') + + {{ trans('general.webhook_msg_note') }} + @endif +
+
+
+ @endif + @include ('partials.forms.redirect_submit_options', ['translated_name' => trans('admin/licenses/form.asset'), 'table_name' => $table_name, 'type' => $license->name]) + +
+
@stop diff --git a/resources/views/partials/forms/redirect_submit_options.blade.php b/resources/views/partials/forms/redirect_submit_options.blade.php new file mode 100644 index 0000000000..0b98933254 --- /dev/null +++ b/resources/views/partials/forms/redirect_submit_options.blade.php @@ -0,0 +1,13 @@ + +
\ No newline at end of file