Passed hardware components and benchmarks to create test view

This commit is contained in:
Gregory Ballantine 2024-05-29 08:57:52 -04:00
parent dea08d15dd
commit 6cb2ac0263
3 changed files with 42 additions and 4 deletions

View File

@ -5,10 +5,36 @@
<form class="twelve columns" action="/test/create" method="POST">
<div class="row">
<label for="test_name">
Test name:
<input id="test_name" class="u-full-width" type="text" name="test_name" placeholder="My hardware benchmarking test">
</label>
<div class="columns three">
<label for="test_hardware">
Hardware Component:
<select id="test_hardware" class="u-full-width" name="test_hardware">
{{ range $hw := .Hardware }}
<option value="{{ $hw.ID }}">{{ $hw.Name }}</option>
{{ end }}
</select>
</label>
</div>
<div class="columns nine">
<label for="test_name">
Test name:
<input id="test_name" class="u-full-width" type="text" name="test_name" placeholder="My hardware benchmarking test">
</label>
</div>
</div>
<div class="row">
<div class="columns twelve">
<label for="test_benchmarks">
Benchmarks to Test:
<select id="test_benchmarks" class="u-full-width" name="test_benchmarks" multiple>
{{ range $bm := .Benchmarks }}
<option value="{{ $bm.ID }}">{{ $bm.Name }}</option>
{{ end }}
</select>
</label>
</div>
</div>
<div class="row">

View File

@ -2,6 +2,7 @@ package forms
type TestForm struct {
Name string `form:"test_name" validate:"required"`
Description string `form:"test_description"`
Hardware int `form:"test_hardware" validate:"required"`
Benchmarks []string `form:"test_benchmarks" validate:"required"`
}

View File

@ -38,6 +38,16 @@ func TestGetView(c flamego.Context, t template.Template, data template.Data) {
}
func TestGetCreate(t template.Template, data template.Data) {
// add hardware components to template
var hardware []models.Hardware
models.DB.Find(&hardware)
data["hardware"] = hardware
// add benchmarks to template
var benchmarks []models.Benchmark
models.DB.Find(&benchmarks)
data["benchmarks"] = benchmarks
data["title"] = "Create a Test"
t.HTML(http.StatusOK, "test/create")
}
@ -56,6 +66,7 @@ func TestPostCreate(c flamego.Context, form forms.TestForm, errs binding.Errors)
test := models.Test{
Name: form.Name,
Description: form.Description,
HardwareID: form.Hardware,
}