Re-worked test views and routes for new DB schema

This commit is contained in:
Gregory Ballantine 2023-10-07 21:45:21 -06:00
parent 3349d42985
commit 987ecde7c7
3 changed files with 45 additions and 15 deletions

View File

@ -6,6 +6,8 @@ use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Routing\RouteContext;
use Slim\Views\Twig;
use BitGoblin\Colossus\Models\Benchmark;
use BitGoblin\Colossus\Models\Component;
use BitGoblin\Colossus\Models\Test;
class TestController extends Controller {
@ -29,16 +31,23 @@ class TestController extends Controller {
}
public function getAdd(Request $request, Response $response): Response {
$benchmarks = Benchmark::all();
$components = Component::all();
$view = Twig::fromRequest($request);
return $view->render($response, 'test/add.twig');
return $view->render($response, 'test/add.twig', [
'benchmarks' => $benchmarks,
'components' => $components,
]);
}
public function postAdd(Request $request, Response $response): Response {
$params = (array)$request->getParsedBody();
$test = new Test;
$test->name = $params['test_name'];
$test->description = $params['test_description'];
$test->date_tag = $params['test_date_tag'];
$test->benchmark_id = $params['test_benchmark'];
$test->component_id = $params['test_component'];
$test->save();

View File

@ -14,16 +14,33 @@
<div class="twelve columns">
<form action="{{ url_for('test.add') }}" method="POST" class="u-full-width">
<div class="row">
<div class="twelve columns">
<label for="test_name">Test name:</label>
<input type="text" id="test_name" class="u-full-width" name="test_name">
<div class="two columns">
<label>
Date Tag:
<input class="u-full-width" type="text" name="test_date_tag" placeholder="(XY/AB)">
</label>
</div>
</div>
<div class="row">
<div class="twelve columns">
<label for="test_description">Description</label>
<textarea class="u-full-width" name="test_description" id="test_description" placeholder="Describe this test..."></textarea>
<div class="five columns">
<label>
Benchmark:
<select class="u-full-width" name="test_benchmark">
{% for b in benchmarks %}
<option value="{{ b.id }}">{{ b.name }}</option>
{% endfor %}
</select>
</label>
</div>
<div class="five columns">
<label>
Hardware component:
<select class="u-full-width" name="test_component">
{% for c in components %}
<option value="{{ c.id }}">{{ c.name }}</option>
{% endfor %}
</select>
</label>
</div>
</div>

View File

@ -9,16 +9,20 @@
<table class="u-full-width">
<thead>
<tr>
<th>Test name</th>
<th>Description</th>
<th>Test Date</th>
<th>Benchmark</th>
<th>Hardware</th>
<th># of Results</th>
<th>Last updated</th>
</tr>
</thead>
<tbody>
{% for t in tests %}
<tr>
<td><a href="{{ url_for('test.view', { test_id: t.id }) }}">{{ t.name }}</a></td>
<td>{{ t.description | slice(0, 100) }}</td>
<td><a href="{{ url_for('test.view', { test_id: t.id }) }}">{{ t.date_tag }}</a></td>
<td>{{ t.benchmark.name }}</td>
<td>{{ t.component.name }}</td>
<td>{{ t.results | length }}</td>
<td>{{ t.updated_at | date("F jS \\a\\t g:ia") }}</td>
</tr>
{% endfor %}