From 154e71de74792cb539dcbe24de0d492ecb8007b2 Mon Sep 17 00:00:00 2001 From: akemidx Date: Tue, 7 Nov 2023 17:43:51 -0500 Subject: [PATCH 01/14] shifting wrap around logic back into 0-265 --- app/Helpers/Helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index c2ccda6c84..98f40de5b8 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -349,7 +349,7 @@ class Helper $total_colors = count($colors); if ($index >= $total_colors) { - $index = $index - $total_colors; + $index = $index - $total_colors - 1; } return $colors[$index]; From 3f8b63e053b7ff0f7ec661c1b230b084c264127b Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 8 Nov 2023 14:40:02 +0000 Subject: [PATCH 02/14] Add linked text Signed-off-by: snipe --- resources/lang/en/admin/hardware/message.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lang/en/admin/hardware/message.php b/resources/lang/en/admin/hardware/message.php index 04be92a754..056692998e 100644 --- a/resources/lang/en/admin/hardware/message.php +++ b/resources/lang/en/admin/hardware/message.php @@ -11,6 +11,7 @@ return [ 'create' => [ 'error' => 'Asset was not created, please try again. :(', 'success' => 'Asset created successfully. :)', + 'success_linked' => 'Asset with tag :tag was created successfully. Click here to view.', ], 'update' => [ From 08153d418f89703501915a35ed1f6004262673ac Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 8 Nov 2023 14:40:18 +0000 Subject: [PATCH 03/14] Use new alert box and linked string Signed-off-by: snipe --- app/Http/Controllers/Assets/AssetsController.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 8a12d744ae..28d7906cd7 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -204,12 +204,8 @@ class AssetsController extends Controller } if ($success) { - // Redirect to the asset listing page - $minutes = 518400; - // dd( $_POST['options']); - // Cookie::queue(Cookie::make('optional_info', json_decode($_POST['options']), $minutes)); return redirect()->route('hardware.index') - ->with('success', trans('admin/hardware/message.create.success')); + ->with('success-unescaped', trans('admin/hardware/message.create.success_linked', ['link' => route('hardware.show', $asset->id), 'id', 'tag' => $asset->asset_tag])); } From ef10f2e50e862504180c5debb6b99854ef62689b Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 8 Nov 2023 14:40:38 +0000 Subject: [PATCH 04/14] Use more correct route in redirect Signed-off-by: snipe --- .../Controllers/Components/ComponentCheckinController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Components/ComponentCheckinController.php b/app/Http/Controllers/Components/ComponentCheckinController.php index 49199aa6d2..9f4724e353 100644 --- a/app/Http/Controllers/Components/ComponentCheckinController.php +++ b/app/Http/Controllers/Components/ComponentCheckinController.php @@ -96,8 +96,8 @@ class ComponentCheckinController extends Controller $asset = Asset::find($component_assets->asset_id); event(new CheckoutableCheckedIn($component, $asset, Auth::user(), $request->input('note'), Carbon::now())); - if($backto == 'asset'){ - return redirect()->route('hardware.view', $asset->id)->with('success', + if ($backto == 'asset'){ + return redirect()->route('hardware.show', $asset->id)->with('success', trans('admin/components/message.checkin.success')); } From d2bf71327baaad8dd9831692e3fef28701bf01b6 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 8 Nov 2023 14:40:56 +0000 Subject: [PATCH 05/14] Redirect /asset_tag/view to /asset_tag Signed-off-by: snipe --- routes/web/hardware.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/routes/web/hardware.php b/routes/web/hardware.php index 1643e5794e..934712d7e4 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -122,9 +122,9 @@ Route::group( [AssetCheckinController::class, 'store'] )->name('hardware.checkin.store'); - Route::get('{assetId}/view', - [AssetsController::class, 'show'] - )->name('hardware.view'); + Route::get('{assetId}/view', function ($assetId) { + return redirect()->route('hardware.show', ['hardware' => $assetId]); + }); Route::get('{assetId}/qr_code', [AssetsController::class, 'getQrCode'] @@ -178,13 +178,17 @@ Route::group( Route::post('bulkcheckout', [BulkAssetsController::class, 'storeCheckout'] )->name('hardware.bulkcheckout.store'); + }); Route::resource('hardware', AssetsController::class, [ 'middleware' => ['auth'], - 'parameters' => ['asset' => 'asset_id' + 'parameters' => ['asset' => 'asset_id', + 'names' => [ + 'show' => 'view', + ], ], ]); From a24d21e68390fee864d3bab0379230a02d93281a Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 8 Nov 2023 14:41:05 +0000 Subject: [PATCH 06/14] Added new unescaped alert box Signed-off-by: snipe --- resources/views/notifications.blade.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/resources/views/notifications.blade.php b/resources/views/notifications.blade.php index 9dbb547515..0205e3e10f 100755 --- a/resources/views/notifications.blade.php +++ b/resources/views/notifications.blade.php @@ -35,6 +35,18 @@ @endif +@if ($message = Session::get('success-unescaped')) +
+
+ + + {{ trans('general.notification_success') }}: + {!! $message !!} +
+
+@endif + + @if ($assets = Session::get('assets')) @foreach ($assets as $asset)
From 6da0671143f3f83be6b0fc4e3d40a399cc9a7f51 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 8 Nov 2023 14:44:09 +0000 Subject: [PATCH 07/14] Added comment Signed-off-by: snipe --- routes/web/hardware.php | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/web/hardware.php b/routes/web/hardware.php index 934712d7e4..d29b2cd836 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -122,6 +122,7 @@ Route::group( [AssetCheckinController::class, 'store'] )->name('hardware.checkin.store'); + // Redirect old legacy /asset_id/view urls to the resource route version Route::get('{assetId}/view', function ($assetId) { return redirect()->route('hardware.show', ['hardware' => $assetId]); }); From 495521b70ebb5e4fbdcc3905a059fadcdfd08e20 Mon Sep 17 00:00:00 2001 From: akemidx Date: Wed, 8 Nov 2023 12:51:51 -0500 Subject: [PATCH 08/14] adjusting for less than 0 possibility --- app/Helpers/Helper.php | 4 ++++ tests/Feature/DefaultColorKeyTest.php | 21 +++++++++++++++++++++ tests/Feature/Reports/CustomReportTest.php | 1 + 3 files changed, 26 insertions(+) create mode 100644 tests/Feature/DefaultColorKeyTest.php diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 98f40de5b8..cd790ff40f 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -350,6 +350,10 @@ class Helper if ($index >= $total_colors) { $index = $index - $total_colors - 1; + + if($index < 0) { + $index = 0; + } } return $colors[$index]; diff --git a/tests/Feature/DefaultColorKeyTest.php b/tests/Feature/DefaultColorKeyTest.php new file mode 100644 index 0000000000..fdabd0db14 --- /dev/null +++ b/tests/Feature/DefaultColorKeyTest.php @@ -0,0 +1,21 @@ +hasAssets(1)->count(255)->create(); + + $this->defaultChartColors($index); + + $this->assertArrayHasKey('index', ($index)[0]); + + + } +} diff --git a/tests/Feature/Reports/CustomReportTest.php b/tests/Feature/Reports/CustomReportTest.php index a1a269a4ab..dd3199212e 100644 --- a/tests/Feature/Reports/CustomReportTest.php +++ b/tests/Feature/Reports/CustomReportTest.php @@ -11,6 +11,7 @@ use PHPUnit\Framework\Assert; use Tests\Support\InteractsWithSettings; use Tests\TestCase; + class CustomReportTest extends TestCase { use InteractsWithSettings; From 9cc89911f7213b34ba78c1e7bb4dc6107fe86dff Mon Sep 17 00:00:00 2001 From: akemidx Date: Wed, 8 Nov 2023 13:29:32 -0500 Subject: [PATCH 09/14] possibilitieeeeeeeeessss --- app/Helpers/Helper.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index cd790ff40f..0fcee31575 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -354,6 +354,9 @@ class Helper if($index < 0) { $index = 0; } + elseif($index > 255) { + $index = 255; + } } return $colors[$index]; From 2051ac785d92dfcf2e7f7246771d102e5ee4fb8f Mon Sep 17 00:00:00 2001 From: akemidx Date: Wed, 8 Nov 2023 13:44:46 -0500 Subject: [PATCH 10/14] adding in error logging and code comments --- app/Helpers/Helper.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 0fcee31575..3c5a0e9f11 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -349,13 +349,18 @@ class Helper $total_colors = count($colors); if ($index >= $total_colors) { + + \Log::error('Status label count is '.$index.' and exceeds the allowed count of 256.'); + //patch fix for array key overflow (color count starts at 1, array starts at 0) $index = $index - $total_colors - 1; + //constraints to keep result in 0-265 range. This should never be needed, but if something happens + //to create this many status labels and it DOES happen, this will keep it from failing at least. if($index < 0) { $index = 0; } - elseif($index > 255) { - $index = 255; + elseif($index > 265) { + $index = 265; } } From 4382adce85352516b09f957020ae5a7e3781cb62 Mon Sep 17 00:00:00 2001 From: akemidx Date: Wed, 8 Nov 2023 15:29:29 -0500 Subject: [PATCH 11/14] typo in error log message --- app/Helpers/Helper.php | 2 +- tests/Feature/DefaultColorKeyTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 3c5a0e9f11..6039457637 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -350,7 +350,7 @@ class Helper if ($index >= $total_colors) { - \Log::error('Status label count is '.$index.' and exceeds the allowed count of 256.'); + \Log::error('Status label count is '.$index.' and exceeds the allowed count of 266.'); //patch fix for array key overflow (color count starts at 1, array starts at 0) $index = $index - $total_colors - 1; diff --git a/tests/Feature/DefaultColorKeyTest.php b/tests/Feature/DefaultColorKeyTest.php index fdabd0db14..3fab03b7f6 100644 --- a/tests/Feature/DefaultColorKeyTest.php +++ b/tests/Feature/DefaultColorKeyTest.php @@ -2,8 +2,8 @@ namespace Tests\Feature; -use Tests\TestCase; use App\Models\Statuslabel; +use Tests\TestCase; use App\Models\Asset; class DefaultColorKeyTest extends TestCase From 49136a4d67c9d0434ae51c3820b294f24590a864 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 8 Nov 2023 12:35:42 -0800 Subject: [PATCH 12/14] Add tests for color helper --- app/Helpers/Helper.php | 12 ++++++++---- tests/Feature/DefaultColorKeyTest.php | 21 --------------------- tests/Unit/Helpers/HelperTest.php | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 25 deletions(-) delete mode 100644 tests/Feature/DefaultColorKeyTest.php create mode 100644 tests/Unit/Helpers/HelperTest.php diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 6039457637..800a2491d4 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -73,10 +73,14 @@ class Helper * * @author [A. Gianotto] [] * @since [v3.3] - * @return array + * @return string */ - public static function defaultChartColors($index = 0) + public static function defaultChartColors(int $index = 0) { + if ($index < 0) { + $index = 0; + } + $colors = [ '#008941', '#FF4A46', @@ -359,8 +363,8 @@ class Helper if($index < 0) { $index = 0; } - elseif($index > 265) { - $index = 265; + elseif($index >($total_colors - 1)) { + $index = $total_colors - 1; } } diff --git a/tests/Feature/DefaultColorKeyTest.php b/tests/Feature/DefaultColorKeyTest.php deleted file mode 100644 index 3fab03b7f6..0000000000 --- a/tests/Feature/DefaultColorKeyTest.php +++ /dev/null @@ -1,21 +0,0 @@ -hasAssets(1)->count(255)->create(); - - $this->defaultChartColors($index); - - $this->assertArrayHasKey('index', ($index)[0]); - - - } -} diff --git a/tests/Unit/Helpers/HelperTest.php b/tests/Unit/Helpers/HelperTest.php new file mode 100644 index 0000000000..0b5fba986c --- /dev/null +++ b/tests/Unit/Helpers/HelperTest.php @@ -0,0 +1,19 @@ +assertIsString(Helper::defaultChartColors(1000)); + } + + public function testDefaultChartColorsMethodHandlesNegativeNumbers() + { + $this->assertIsString(Helper::defaultChartColors(-1)); + } +} From 9bff2d0bbf62e06cbdf409f29c7987d06b256657 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 9 Nov 2023 21:47:29 +0000 Subject: [PATCH 13/14] Fixed indenting? Signed-off-by: snipe --- routes/web/hardware.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/routes/web/hardware.php b/routes/web/hardware.php index d29b2cd836..dc0ba43fa0 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -186,11 +186,8 @@ Route::resource('hardware', AssetsController::class, [ 'middleware' => ['auth'], - 'parameters' => ['asset' => 'asset_id', - 'names' => [ - 'show' => 'view', - ], - ], + 'parameters' => ['asset' => 'asset_id'], + 'names' => ['show' => 'view'], ]); Route::get('ht/{any?}', From 495df737fcfe66e233ca975469a4816958cf6501 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 13 Nov 2023 16:39:35 +0000 Subject: [PATCH 14/14] Unfixed indenting :( Signed-off-by: snipe --- routes/web/hardware.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/routes/web/hardware.php b/routes/web/hardware.php index dc0ba43fa0..d4f2892281 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -186,8 +186,11 @@ Route::resource('hardware', AssetsController::class, [ 'middleware' => ['auth'], - 'parameters' => ['asset' => 'asset_id'], - 'names' => ['show' => 'view'], + 'parameters' => ['asset' => 'asset_id', + 'names' => [ + 'show' => 'view', + ], + ], ]); Route::get('ht/{any?}',