diff --git a/assets/styles/nardah.scss b/assets/styles/nardah.scss index b50560f..1900231 100644 --- a/assets/styles/nardah.scss +++ b/assets/styles/nardah.scss @@ -14,5 +14,17 @@ $shadow-heavy: rgba(0, 0, 0, 0.25) 0px 54px 55px, rgba(0, 0, 0, 0.12) 0px -12px } body{ + background: rgb(240, 235, 248); font-size: 18px; } + +table{ + border: 1px solid #eee; +} + +#main-wrapper{ + padding: 1.5rem 2rem; + background: white; + border: 1px solid #bbb; + border-radius: 8px; +} diff --git a/src/Controllers/TestController.php b/src/Controllers/TestController.php index 5ad7a67..e711846 100644 --- a/src/Controllers/TestController.php +++ b/src/Controllers/TestController.php @@ -64,4 +64,49 @@ class TestController extends Controller { ->withStatus(302); } + public function getEdit(Request $request, Response $response, array $args): Response { + $test = Test::where('id', $args['test_id'])->first(); + $benchmarks = Benchmark::all(); + $components = Component::all(); + + $view = Twig::fromRequest($request); + return $view->render($response, 'test/edit.twig', [ + 'test' => $test, + 'benchmarks' => $benchmarks, + 'components' => $components, + ]); + } + + public function postEdit(Request $request, Response $response, array $args): Response { + $params = (array)$request->getParsedBody(); + + $test = Test::where('id', $args['test_id'])->first(); + $test->title = $params['test_title']; + $test->description = $params['test_description']; + $test->component_id = $params['test_component']; + + $test->save(); + + // attach benchmarks to test that aren't already attached + foreach ($params['test_benchmarks'] as $b) { + if (!$test->isBenchmarkSelected($b)) { + $test->benchmarks()->attach($b); + } + } + + // remove benchmarks are not in the list + foreach ($test->benchmarks as $b) { + if (!in_array($b->id, $params['test_benchmarks'])) { + $test->benchmarks()->detach($b); + } + } + + // 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' => $test->id ])) + ->withStatus(302); + } + } diff --git a/src/Models/Test.php b/src/Models/Test.php index 0887a20..ff95d46 100644 --- a/src/Models/Test.php +++ b/src/Models/Test.php @@ -24,6 +24,12 @@ class Test extends Model { return $this->belongsTo(Component::class); } + public function isBenchmarkSelected($benchmarkId) { + return $this->benchmarks() + ->where('benchmarks.id', $benchmarkId) + ->exists(); + } + public function benchmarkResults() { $data = []; diff --git a/src/routes.php b/src/routes.php index 8338fdc..dc2e77c 100644 --- a/src/routes.php +++ b/src/routes.php @@ -36,7 +36,13 @@ $app->group('/test', function(RouteCollectorProxy $group) { $group->get('', '\\BitGoblin\\Colossus\\Controllers\\TestController:getList')->setName('test.list'); $group->get('/add', '\\BitGoblin\\Colossus\\Controllers\\TestController:getAdd')->setName('test.add'); $group->post('/add', '\\BitGoblin\\Colossus\\Controllers\\TestController:postAdd'); - $group->get('/{test_id}', '\\BitGoblin\\Colossus\\Controllers\\TestController:getView')->setName('test.view'); + + $group->group('/{test_id}', function(RouteCollectorProxy $test) { + $test->get('', '\\BitGoblin\\Colossus\\Controllers\\TestController:getView')->setName('test.view'); + + $test->get('/edit', '\\BitGoblin\\Colossus\\Controllers\\TestController:getEdit')->setName('test.edit'); + $test->post('/edit', '\\BitGoblin\\Colossus\\Controllers\\TestController:postEdit'); + }); }); $app->group('/reports', function(RouteCollectorProxy $group) { diff --git a/views/test/edit.twig b/views/test/edit.twig new file mode 100644 index 0000000..0ec3b7b --- /dev/null +++ b/views/test/edit.twig @@ -0,0 +1,55 @@ +{% extends 'layout.twig' %} + +{% block title %}Editing: {{ test.title }}{% endblock %} + +{% block content %} + +