From dac877f18432eb7f3fc68b60bf7cc148ddf1c412 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 1 Mar 2023 13:51:35 -0800 Subject: [PATCH 1/6] Added location clone Signed-off-by: snipe --- app/Http/Controllers/LocationsController.php | 29 +++++++++++++++++++ .../Transformers/LocationsTransformer.php | 3 +- routes/web.php | 20 +++++++++---- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index 9524abf6e..25a500b56 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -227,6 +227,35 @@ class LocationsController extends Controller } + + /** + * Returns a view that presents a form to clone a location. + * + * @author [A. Gianotto] [] + * @param int $licenseId + * @since [v6.0.14] + * @return View + */ + public function getClone($licenseId = null) + { + // Check if the asset exists + if (is_null($location_to_clone = Location::find($licenseId))) { + // Redirect to the asset management page + return redirect()->route('licenses.index')->with('error', trans('admin/locations/message.does_not_exist')); + } + + $this->authorize('create', $location_to_clone); + + $location = clone $location_to_clone; + $location->id = null; + $location->name = null; + $location->image = null; + + return view('locations/edit') + ->with('item', $location); + } + + public function print_all_assigned($id) { if ($location = Location::where('id', $id)->first()) { diff --git a/app/Http/Transformers/LocationsTransformer.php b/app/Http/Transformers/LocationsTransformer.php index a55c41b35..22eade5d6 100644 --- a/app/Http/Transformers/LocationsTransformer.php +++ b/app/Http/Transformers/LocationsTransformer.php @@ -4,7 +4,7 @@ namespace App\Http\Transformers; use App\Helpers\Helper; use App\Models\Location; -use Gate; +use Illuminate\Support\Facades\Gate; use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Facades\Storage; @@ -63,6 +63,7 @@ class LocationsTransformer $permissions_array['available_actions'] = [ 'update' => Gate::allows('update', Location::class) ? true : false, 'delete' => $location->isDeletable(), + 'clone' => (Gate::allows('create', Location::class) && ($location->deleted_at == '')), ]; $array += $permissions_array; diff --git a/routes/web.php b/routes/web.php index 4c52918f8..18b7f9a99 100644 --- a/routes/web.php +++ b/routes/web.php @@ -40,12 +40,9 @@ Route::group(['middleware' => 'auth'], function () { 'parameters' => ['category' => 'category_id'], ]); - /* - * Locations - */ - Route::resource('locations', LocationsController::class, [ - 'parameters' => ['location' => 'location_id'], - ]); + Route::get('locations/{locationId}/clone', + [LocationsController::class, 'getClone'] + )->name('clone/license'); Route::get( 'locations/{locationId}/printassigned', @@ -57,6 +54,17 @@ Route::group(['middleware' => 'auth'], function () { [LocationsController::class, 'print_all_assigned'] )->name('locations.print_all_assigned'); + /* + * Locations + */ + Route::resource('locations', LocationsController::class, [ + 'parameters' => ['location' => 'location_id'], + ]); + + + + + /* * Manufacturers */ From 473553c464fa61f008206aa33085d058d4c2bc64 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 1 Mar 2023 14:01:40 -0800 Subject: [PATCH 2/6] Moved gate Signed-off-by: snipe --- app/Http/Controllers/LocationsController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index 25a500b56..adbe173c6 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -236,16 +236,16 @@ class LocationsController extends Controller * @since [v6.0.14] * @return View */ - public function getClone($licenseId = null) + public function getClone($locationId = null) { + $this->authorize('create', Location::class); + // Check if the asset exists - if (is_null($location_to_clone = Location::find($licenseId))) { + if (is_null($location_to_clone = Location::find($locationId))) { // Redirect to the asset management page return redirect()->route('licenses.index')->with('error', trans('admin/locations/message.does_not_exist')); } - $this->authorize('create', $location_to_clone); - $location = clone $location_to_clone; $location->id = null; $location->name = null; From 84a14918bb519afac3e7550a7b447792f9de119e Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 1 Mar 2023 14:03:33 -0800 Subject: [PATCH 3/6] Updated comments Signed-off-by: snipe --- app/Http/Controllers/LocationsController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index adbe173c6..73066365d 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -232,7 +232,7 @@ class LocationsController extends Controller * Returns a view that presents a form to clone a location. * * @author [A. Gianotto] [] - * @param int $licenseId + * @param int $locationId * @since [v6.0.14] * @return View */ @@ -247,6 +247,8 @@ class LocationsController extends Controller } $location = clone $location_to_clone; + + // unset these values $location->id = null; $location->name = null; $location->image = null; From 9b522006f353426966843514d807d205a69038aa Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 1 Mar 2023 14:05:53 -0800 Subject: [PATCH 4/6] Usew route group for locations Signed-off-by: snipe --- routes/web.php | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/routes/web.php b/routes/web.php index 18b7f9a99..cc358c910 100644 --- a/routes/web.php +++ b/routes/web.php @@ -40,23 +40,29 @@ Route::group(['middleware' => 'auth'], function () { 'parameters' => ['category' => 'category_id'], ]); - Route::get('locations/{locationId}/clone', - [LocationsController::class, 'getClone'] - )->name('clone/license'); - Route::get( - 'locations/{locationId}/printassigned', - [LocationsController::class, 'print_assigned'] - )->name('locations.print_assigned'); - - Route::get( - 'locations/{locationId}/printallassigned', - [LocationsController::class, 'print_all_assigned'] - )->name('locations.print_all_assigned'); /* - * Locations - */ + * Locations + */ + + Route::group(['prefix' => 'locations', 'middleware' => ['auth']], function () { + + Route::get('{locationId}/clone', + [LocationsController::class, 'getClone'] + )->name('clone/license'); + + Route::get( + '{locationId}/printassigned', + [LocationsController::class, 'print_assigned'] + )->name('locations.print_assigned'); + + Route::get( + '{locationId}/printallassigned', + [LocationsController::class, 'print_all_assigned'] + )->name('locations.print_all_assigned'); + }); + Route::resource('locations', LocationsController::class, [ 'parameters' => ['location' => 'location_id'], ]); From b8231f420b11d96998ca629374fa445ed633e834 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 1 Mar 2023 14:12:33 -0800 Subject: [PATCH 5/6] Remove name from blanking paroperties Signed-off-by: snipe --- app/Http/Controllers/LocationsController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index 73066365d..39b73a979 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -250,7 +250,6 @@ class LocationsController extends Controller // unset these values $location->id = null; - $location->name = null; $location->image = null; return view('locations/edit') From 778787db3c69a6c59ce63dff8526281b0548222b Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 1 Mar 2023 15:36:01 -0800 Subject: [PATCH 6/6] Rip out jquery for location parent Signed-off-by: snipe --- resources/views/locations/edit.blade.php | 47 ------------------------ 1 file changed, 47 deletions(-) diff --git a/resources/views/locations/edit.blade.php b/resources/views/locations/edit.blade.php index 0c93c83a8..10d0f59bb 100755 --- a/resources/views/locations/edit.blade.php +++ b/resources/views/locations/edit.blade.php @@ -65,50 +65,3 @@ @include ('partials.forms.edit.image-upload') @stop -@if (!$item->id) -@section('moar_scripts') - -@stop -@endif