From 3349d42985255f2f40af026318ea4e98c5485fd7 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Sat, 7 Oct 2023 11:45:11 -0600 Subject: [PATCH] Added routes and views for adding and listing benchmarks and components --- src/Controllers/BenchmarkController.php | 9 +++++ src/Controllers/ComponentController.php | 11 +++++- src/routes.php | 10 +++-- views/benchmark/add.twig | 46 +++++++++++++++++++++++ views/component/add.twig | 38 +++++++++++++++++++ views/component/view.twig | 50 +++++++++++++++++++++++++ 6 files changed, 159 insertions(+), 5 deletions(-) create mode 100644 views/benchmark/add.twig create mode 100644 views/component/add.twig diff --git a/src/Controllers/BenchmarkController.php b/src/Controllers/BenchmarkController.php index 2f14736..634c009 100644 --- a/src/Controllers/BenchmarkController.php +++ b/src/Controllers/BenchmarkController.php @@ -10,6 +10,15 @@ use BitGoblin\Colossus\Models\Benchmark; class BenchmarkController extends Controller { + public function getIndex(Request $request, Response $response): Response { + // redirect the user back to the home page + $routeContext = RouteContext::fromRequest($request); + $routeParser = $routeContext->getRouteParser(); + return $response + ->withHeader('Location', $routeParser->urlFor('benchmark.list')) + ->withStatus(302); + } + public function getList(Request $request, Response $response): Response { $benchmarks = Benchmark::orderByDesc('updated_at')->get(); diff --git a/src/Controllers/ComponentController.php b/src/Controllers/ComponentController.php index 41683b5..0036576 100644 --- a/src/Controllers/ComponentController.php +++ b/src/Controllers/ComponentController.php @@ -10,6 +10,15 @@ use BitGoblin\Colossus\Models\Component; class ComponentController extends Controller { + public function getIndex(Request $request, Response $response): Response { + // redirect the user back to the home page + $routeContext = RouteContext::fromRequest($request); + $routeParser = $routeContext->getRouteParser(); + return $response + ->withHeader('Location', $routeParser->urlFor('component.list')) + ->withStatus(302); + } + public function getList(Request $request, Response $response): Response { $components = Component::orderByDesc('updated_at')->get(); @@ -38,7 +47,7 @@ class ComponentController extends Controller { $component = new Component; $component->name = $params['component_name']; - $component->type = $params['component_description']; + $component->type = $params['component_type']; $component->save(); diff --git a/src/routes.php b/src/routes.php index 81f00c5..8e91e80 100644 --- a/src/routes.php +++ b/src/routes.php @@ -5,17 +5,19 @@ use Slim\Routing\RouteCollectorProxy; $app->get('/', '\\BitGoblin\\Colossus\\Controllers\\HomeController:getIndex')->setName('dashboard'); $app->group('/benchmark', function(RouteCollectorProxy $group) { - $group->get('', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getList')->setName('benchmark.list'); + $group->get('', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getIndex')->setName('benchmark.index'); + $group->get('/list', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getList')->setName('benchmark.list'); $group->get('/add', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getAdd')->setName('benchmark.add'); $group->post('/add', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:postAdd'); - $group->get('/{test_id}', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getView')->setName('benchmark.view'); + $group->get('/{benchmark_id}', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getView')->setName('benchmark.view'); }); $app->group('/component', function(RouteCollectorProxy $group) { - $group->get('', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getList')->setName('component.list'); + $group->get('', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getIndex')->setName('component.index'); + $group->get('/list', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getList')->setName('component.list'); $group->get('/add', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getAdd')->setName('component.add'); $group->post('/add', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:postAdd'); - $group->get('/{test_id}', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getView')->setName('component.view'); + $group->get('/{component_id}', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getView')->setName('component.view'); }); $app->group('/test', function(RouteCollectorProxy $group) { diff --git a/views/benchmark/add.twig b/views/benchmark/add.twig new file mode 100644 index 0000000..02b86b4 --- /dev/null +++ b/views/benchmark/add.twig @@ -0,0 +1,46 @@ +{% extends 'layout.twig' %} + +{% block title %}Add New Benchmark{% endblock %} + +{% block content %} + +
+
+

Add new benchmark

+
+
+ +
+
+
+
+
+ + +
+ +
+ +
+
+ +
+
+ + +
+
+ + +
+
+
+ +{% endblock %} diff --git a/views/component/add.twig b/views/component/add.twig new file mode 100644 index 0000000..53008c5 --- /dev/null +++ b/views/component/add.twig @@ -0,0 +1,38 @@ +{% extends 'layout.twig' %} + +{% block title %}Add New Component{% endblock %} + +{% block content %} + +
+
+

Add new component

+
+
+ +
+
+
+
+
+ + +
+ +
+ +
+
+ + +
+
+
+ +{% endblock %} diff --git a/views/component/view.twig b/views/component/view.twig index e69de29..9fac01b 100644 --- a/views/component/view.twig +++ b/views/component/view.twig @@ -0,0 +1,50 @@ +{% extends 'layout.twig' %} + +{% block title %}Component: {{ component.name }}{% endblock %} + +{% block content %} +
+
+

{{ component.name }}

+

{{ component.type }}

+
+
+ +
+ +
+
+

Test results:

+

Add new result

+ + {% if test.results | length > 0 %} + + + + + + + + + + + + + {% for r in test.results %} + + + + + + + + + {% endfor %} + +
ComponentBenchmarkScoringAvg.Min.Max.
{{ r.component }}{{ r.benchmark }}{{ r.type | capitalize }}{{ r.average }}{{ r.minimum ? r.minimum : 'N/a' }}{{ r.maximum ? r.maximum : 'N/a' }}
+ {% else %} +

There are no results associated with this.

+ {% endif %} +
+
+{% endblock %}