From 6e67d58a8b33a1dd5f739179d1bbc833496c5c24 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Wed, 25 Jun 2025 17:24:31 -0400 Subject: [PATCH] Updated the reports page to use the new API endpoints --- assets/scripts/bedabin.coffee | 16 +++++++----- src/Controllers/ApiController.php | 3 ++- src/Controllers/ResultController.php | 37 ---------------------------- src/routes.php | 4 --- views/test/view.twig | 2 +- 5 files changed, 13 insertions(+), 49 deletions(-) delete mode 100644 src/Controllers/ResultController.php diff --git a/assets/scripts/bedabin.coffee b/assets/scripts/bedabin.coffee index 844c584..82aaf04 100644 --- a/assets/scripts/bedabin.coffee +++ b/assets/scripts/bedabin.coffee @@ -1,15 +1,19 @@ $ -> console.log('ready.') - $('#report-benchmarks').on('change', -> - url = '/api/benchmark/' + $('#report-benchmarks').val() + '/tests' - $.get(url, (data) -> + $('#report-benchmarks').on 'change', -> + try + benchmarkSearchParams = new URLSearchParams + benchmark_id: $('#report-benchmarks').val() + benchmarkRes = await fetch("/api/v1/benchmark/tests?#{benchmarkSearchParams}") + benchmarkData = await benchmarkRes.json() + # clear old contents from the selector $('#report-tests').empty() # add new elements to the selector - addOption(test) for test in data - ) - ) + addOption(test) for test in benchmarkData + catch error + console.error 'An error occurred while fetching benchmark results.', error addOption = (test) -> $('#report-tests').append( diff --git a/src/Controllers/ApiController.php b/src/Controllers/ApiController.php index e6313c9..b4c874b 100644 --- a/src/Controllers/ApiController.php +++ b/src/Controllers/ApiController.php @@ -22,7 +22,8 @@ class ApiController extends Controller { } public function getBenchmarkTests(Request $request, Response $response, array $args): Response { - $benchmark = Benchmark::where('id', $args['benchmark_id'])->first(); + $urlParams = $request->getQueryParams(); + $benchmark = Benchmark::where('id', $urlParams['benchmark_id'])->first(); $payload = json_encode($benchmark->tests); diff --git a/src/Controllers/ResultController.php b/src/Controllers/ResultController.php deleted file mode 100644 index 5560959..0000000 --- a/src/Controllers/ResultController.php +++ /dev/null @@ -1,37 +0,0 @@ -getParsedBody(); - - $result = new Result; - $result->test_id = $params['result_test']; - $result->component_id = $params['result_component']; - $result->benchmark_id = $params['result_benchmark']; - $result->average = $params['result_avg']; - $result->minimum = $params['result_min'] ?? null; - $result->maximum = $params['result_max'] ?? null; - - $result->save(); - - // redirect the user back to the home page - $routeContext = RouteContext::fromRequest($request); - $routeParser = $routeContext->getRouteParser(); - return $response - ->withHeader('Location', $routeParser->urlFor('test.view', [ - 'test_id' => $result->test_id - ])) - ->withStatus(302); - } - -} diff --git a/src/routes.php b/src/routes.php index 6be25b0..2ad3df7 100644 --- a/src/routes.php +++ b/src/routes.php @@ -27,10 +27,6 @@ $app->group('/test', function(RouteCollectorProxy $group) { $group->get('/{test_id}', '\\BitGoblin\\Colossus\\Controllers\\TestController:getView')->setName('test.view'); }); -$app->group('/result', function(RouteCollectorProxy $group) { - $group->post('/add', '\\BitGoblin\\Colossus\\Controllers\\ResultController:postAdd')->setName('result.add'); -}); - $app->group('/reports', function(RouteCollectorProxy $group) { $group->get('/generate', '\\BitGoblin\\Colossus\Controllers\ReportController:getGenerate')->setName('reports.generate'); }); diff --git a/views/test/view.twig b/views/test/view.twig index f676a2e..48f7e7e 100644 --- a/views/test/view.twig +++ b/views/test/view.twig @@ -14,7 +14,7 @@
-
+