diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index c2ccda6c84..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', @@ -349,7 +353,19 @@ class Helper $total_colors = count($colors); if ($index >= $total_colors) { - $index = $index - $total_colors; + + \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; + + //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 >($total_colors - 1)) { + $index = $total_colors - 1; + } } return $colors[$index]; 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])); } 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')); } 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' => [ 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)
diff --git a/routes/web/hardware.php b/routes/web/hardware.php index 1643e5794e..d4f2892281 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -122,9 +122,10 @@ Route::group( [AssetCheckinController::class, 'store'] )->name('hardware.checkin.store'); - Route::get('{assetId}/view', - [AssetsController::class, 'show'] - )->name('hardware.view'); + // 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]); + }); Route::get('{assetId}/qr_code', [AssetsController::class, 'getQrCode'] @@ -178,13 +179,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', + ], ], ]); 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; 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)); + } +}