From 05b1374d1d1bf4ebcf82f9d886ab0c463a4f936a Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Mon, 3 Jun 2024 10:36:18 -0400 Subject: [PATCH] Reworked how test results get submitted --- src/Controllers/ResultController.php | 23 +---------- src/Models/Benchmark.php | 4 ++ src/Models/Component.php | 6 ++- src/Models/Result.php | 10 ++++- src/routes.php | 4 +- views/result/add.twig | 62 ---------------------------- views/result/list.twig | 34 --------------- views/test/view.twig | 36 +++++++++++++++- 8 files changed, 56 insertions(+), 123 deletions(-) delete mode 100644 views/result/add.twig delete mode 100644 views/result/list.twig diff --git a/src/Controllers/ResultController.php b/src/Controllers/ResultController.php index ac9fe1a..f064da6 100644 --- a/src/Controllers/ResultController.php +++ b/src/Controllers/ResultController.php @@ -11,24 +11,6 @@ use BitGoblin\Colossus\Models\Test; class ResultController extends Controller { - public function getList(Request $request, Response $response): Response { - $results = Result::orderByDesc('updated_at')->get(); - - $view = Twig::fromRequest($request); - return $view->render($response, 'result/list.twig', [ - 'results' => $results, - ]); - } - - public function getAdd(Request $request, Response $response): Response { - $tests = Test::all(); - - $view = Twig::fromRequest($request); - return $view->render($response, 'result/add.twig', [ - 'tests' => $tests, - ]); - } - public function postAdd(Request $request, Response $response): Response { $params = (array)$request->getParsedBody(); @@ -36,10 +18,9 @@ class ResultController extends Controller { $result->test_id = $params['result_test']; $result->component = $params['result_component']; $result->benchmark = $params['result_benchmark']; - $result->type = $params['result_type']; $result->average = $params['result_avg']; - $result->minimum = $params['result_min']; - $result->maximum = $params['result_max']; + $result->minimum = $params['result_min'] ?? null; + $result->maximum = $params['result_max'] ?? null; $result->save(); diff --git a/src/Models/Benchmark.php b/src/Models/Benchmark.php index ee0e9f0..df064da 100644 --- a/src/Models/Benchmark.php +++ b/src/Models/Benchmark.php @@ -16,4 +16,8 @@ class Benchmark extends Model { return $this->belongsToMany(Test::class); } + public function results() { + return $this->hasMany(Result::class): + } + } diff --git a/src/Models/Component.php b/src/Models/Component.php index 96edf1c..02bdb46 100644 --- a/src/Models/Component.php +++ b/src/Models/Component.php @@ -15,4 +15,8 @@ class Component extends Model { return $this->hasMany(Test::class); } -} \ No newline at end of file + public function results() { + return $this->hasMany(Result::class): + } + +} diff --git a/src/Models/Result.php b/src/Models/Result.php index 9388bfa..cae3f6d 100644 --- a/src/Models/Result.php +++ b/src/Models/Result.php @@ -17,4 +17,12 @@ class Result extends Model { return $this->belongsTo(Test::class); } -} \ No newline at end of file + public function component() { + return $this->belongsTo(Component::class): + } + + public function benchmark() { + return $this->belongsTo(Benchmark::class); + } + +} diff --git a/src/routes.php b/src/routes.php index 8e91e80..57df991 100644 --- a/src/routes.php +++ b/src/routes.php @@ -28,7 +28,5 @@ $app->group('/test', function(RouteCollectorProxy $group) { }); $app->group('/result', function(RouteCollectorProxy $group) { - $group->get('', '\\BitGoblin\\Colossus\\Controllers\\ResultController:getList')->setName('result.list'); - $group->get('/add', '\\BitGoblin\\Colossus\\Controllers\\ResultController:getAdd')->setName('result.add'); - $group->post('/add', '\\BitGoblin\\Colossus\\Controllers\\ResultController:postAdd'); + $group->post('/add', '\\BitGoblin\\Colossus\\Controllers\\ResultController:postAdd')->setName('result.add'); }); diff --git a/views/result/add.twig b/views/result/add.twig deleted file mode 100644 index 2039679..0000000 --- a/views/result/add.twig +++ /dev/null @@ -1,62 +0,0 @@ -{% extends 'layout.twig' %} - -{% block title %}Add Benchmark Result{% endblock %} - -{% block content %} - -
-
-

Add new benchmark result

-
-
- -
-
-
-
-
- - -
-
- - -
-
- - -
-
- -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
-
- -{% endblock %} diff --git a/views/result/list.twig b/views/result/list.twig deleted file mode 100644 index 5ff4560..0000000 --- a/views/result/list.twig +++ /dev/null @@ -1,34 +0,0 @@ -{% extends 'layout.twig' %} - -{% block title %}List of Results{% endblock %} - -{% block content %} -

Results list...

- - - - - - - - - - - - - - - {% for r in results %} - - - - - - - - - - {% endfor %} - -
Hardware nameBenchmarkResult typeAvg.Min.Max.Last updated
{{ r.component }}{{ r.benchmark }}{{ r.type | capitalize }}{{ r.average }}{{ r.minimum ? r.minimum : 'N/a' }}{{ r.maximum ? r.maximum : 'N/a' }}{{ r.updated_at | date("F jS \\a\\t g:ia") }}
-{% endblock %} diff --git a/views/test/view.twig b/views/test/view.twig index e3255cb..7316876 100644 --- a/views/test/view.twig +++ b/views/test/view.twig @@ -17,10 +17,44 @@
+
+
+
+
+
+ +
+ +
+ +
+
+ +
+
+ +
+ +
+ +
+
+ + + +
+
+
+ +
+

Test results:

-

Add new result

{% if test.results | length > 0 %}