Modified some views, routes and models to work with the new many-to-many for tests and benchmarks

This commit is contained in:
Gregory Ballantine 2024-06-03 08:32:37 -04:00
parent 15377da52d
commit f27490e192
6 changed files with 21 additions and 14 deletions

View File

@ -47,9 +47,13 @@ class TestController extends Controller {
$test = new Test;
$test->title = $params['test_title'];
$test->description = $params['test_description'];
$test->benchmark_id = $params['test_benchmark'];
$test->component_id = $params['test_component'];
// attach benchmarks to test
foreach ($params['test_benchmarks'] as $b) {
$test->benchmarks()->attach($b);
}
$test->save();
// redirect the user back to the home page

View File

@ -13,7 +13,7 @@ class Benchmark extends Model {
];
public function tests() {
return $this->hasMany(Test::class);
return $this->belongsToMany(Test::class);
}
}

View File

@ -17,7 +17,7 @@ class Test extends Model {
}
public function benchmark() {
return $this->belongsTo(Benchmark::class);
return $this->belongsToMany(Benchmark::class);
}
public function component() {

View File

@ -23,8 +23,8 @@
<div class="four columns">
<label>
Benchmark:
<select class="u-full-width" name="test_benchmark">
Benchmarks:
<select class="u-full-width" name="test_benchmarks" multiple>
{% for b in benchmarks %}
<option value="{{ b.id }}">{{ b.name }}</option>
{% endfor %}

View File

@ -10,9 +10,8 @@
<thead>
<tr>
<th>Test title</th>
<th>Benchmark</th>
<th>Hardware</th>
<th># of Results</th>
<th># of benchmarks</th>
<th>Last updated</th>
</tr>
</thead>
@ -20,9 +19,8 @@
{% for t in tests %}
<tr>
<td><a href="{{ url_for('test.view', { test_id: t.id }) }}">{{ t.title }}</a></td>
<td>{{ t.benchmark.name }}</td>
<td>{{ t.component.name }}</td>
<td>{{ t.results | length }}</td>
<td>{{ t.benchmarks() | length }}</td>
<td>{{ t.updated_at | date("F jS \\a\\t g:ia") }}</td>
</tr>
{% endfor %}

View File

@ -7,6 +7,11 @@
<div class="twelve columns">
<h1>{{ test.title }}</h1>
<p>{{ test.description }}</p>
<ul>
{% for b in test.benchmarks %}
<li>{{ b.name }}</li>
{% endfor %}
</ul>
</div>
</div>
@ -33,8 +38,8 @@
{% for r in test.results %}
<tr>
<td>{{ test.component().name }}</td>
<td>{{ test.benchmark().name }}</td>
<td>{{ test.scoring | capitalize }}</td>
<td>{{ r.benchmark().name }}</td>
<td>{{ r.benchmark().scoring | capitalize }}</td>
<td>{{ r.average }}</td>
<td>{{ r.minimum ? r.minimum : 'N/a' }}</td>
<td>{{ r.maximum ? r.maximum : 'N/a' }}</td>
@ -43,7 +48,7 @@
</tbody>
</table>
{% else %}
<p>There are no results associated with this.</p>
<p>There are no results associated with this test.</p>
{% endif %}
</div>
</div>