Added ability to edit tests and hardware
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
34
templates/hardware/edit.tmpl
Normal file
34
templates/hardware/edit.tmpl
Normal file
@@ -0,0 +1,34 @@
|
||||
{{ template "header" . }}
|
||||
|
||||
<div class="row">
|
||||
<h2>Add new hardware</h2>
|
||||
|
||||
<form class="twelve columns" action="/hardware/{{ .hardware.ID }}/edit" method="POST">
|
||||
<div class="row">
|
||||
<div class="nine columns">
|
||||
<label for="hardware_name">
|
||||
Hardware name:
|
||||
<input id="hardware_name" class="u-full-width" type="text" name="hardware_name" placeholder="EVGA RTX 3080 Ti" value="{{ .hardware.Name }}">
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="three columns">
|
||||
<label for="hardware_type">
|
||||
Hardware type:
|
||||
<select id="hardware_type" class="u-full-width" name="hardware_type">
|
||||
<option value="cpu" {{ if eq .hardware.Type "cpu" }}selected{{ end }}>Processor</option>
|
||||
<option value="mem" {{ if eq .hardware.Type "mem" }}selected{{ end }}>Memory</option>
|
||||
<option value="gpu" {{ if eq .hardware.Type "gpu" }}selected{{ end }}>Graphics Card</option>
|
||||
<option value="ssd" {{ if eq .hardware.Type "ssd" }}selected{{ end }}>Solid State Drive</option>
|
||||
<option value="hdd" {{ if eq .hardware.Type "hdd" }}selected{{ end }}>Hard Drive</option>
|
||||
<option value="nic" {{ if eq .hardware.Type "nic" }}selected{{ end }}>Network Card</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input class="button-primary u-full-width" type="submit" value="Submit">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{{ template "footer" . }}
|
@@ -3,6 +3,8 @@
|
||||
<div class="row">
|
||||
<h2>{{ .hardware.Name }}</h2>
|
||||
|
||||
<span><a href="/hardware/{{ .hardware.ID }}/edit">Edit</a></span>
|
||||
|
||||
<p>{{ .hardware.Type }}</p>
|
||||
|
||||
<hr>
|
||||
|
@@ -3,11 +3,15 @@
|
||||
<div class="row">
|
||||
<h2>{{ .test.Name }}</h2>
|
||||
|
||||
<p>Hardware tested: <a href="/hardware/{{ .test.Hardware.ID }}">{{ .test.Hardware.Name }}</a></p>
|
||||
<span><a href="/test/{{ .test.ID }}/edit">Edit</a></span>
|
||||
|
||||
<p>{{ .test.Description }}</p>
|
||||
|
||||
<h4>Benchmarks used:</h4>
|
||||
<h4>Test Info:</h4>
|
||||
|
||||
<p>Hardware tested: <a href="/hardware/{{ .test.Hardware.ID }}">{{ .test.Hardware.Name }}</a></p>
|
||||
|
||||
<p>Benchmarks used:</p>
|
||||
|
||||
<ul>
|
||||
{{ range $bm := .test.Benchmarks }}
|
||||
|
@@ -24,6 +24,9 @@ func RegisterRoutes(f *flamego.Flame) {
|
||||
f.Post("/create", binding.Form(forms.HardwareForm{}), routes.HardwarePostCreate)
|
||||
|
||||
f.Get("/{hardware_id}", routes.HardwareGetView)
|
||||
|
||||
f.Get("/{hardware_id}/edit", routes.HardwareGetEdit)
|
||||
f.Post("/{hardware_id}/edit", binding.Form(forms.HardwareForm{}), routes.HardwarePostEdit)
|
||||
})
|
||||
|
||||
// benchmark routes
|
||||
|
@@ -63,3 +63,43 @@ func HardwarePostCreate(c flamego.Context, form forms.HardwareForm, errs binding
|
||||
|
||||
c.Redirect(fmt.Sprintf("/hardware/%d", hardware.ID))
|
||||
}
|
||||
|
||||
func HardwareGetEdit(c flamego.Context, t template.Template, data template.Data) {
|
||||
// find hardware ID from request
|
||||
hardwareID := c.Param("hardware_id")
|
||||
|
||||
// find hardware from DB
|
||||
var hardware models.Hardware
|
||||
models.DB.Preload("Tests.Benchmarks").First(&hardware, hardwareID)
|
||||
data["hardware"] = hardware
|
||||
|
||||
data["title"] = "Edit Hardware"
|
||||
t.HTML(http.StatusOK, "hardware/edit")
|
||||
}
|
||||
|
||||
func HardwarePostEdit(c flamego.Context, form forms.HardwareForm, errs binding.Errors) {
|
||||
if len(errs) > 0 {
|
||||
var err error
|
||||
switch errs[0].Category {
|
||||
case binding.ErrorCategoryValidation:
|
||||
err = errs[0].Err.(validator.ValidationErrors)[0]
|
||||
default:
|
||||
err = errs[0].Err
|
||||
}
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// find hardware ID from request
|
||||
hardwareID := c.Param("hardware_id")
|
||||
|
||||
// find hardware from DB
|
||||
var hardware models.Hardware
|
||||
models.DB.Preload("Tests.Benchmarks").First(&hardware, hardwareID)
|
||||
|
||||
hardware.Name = form.Name
|
||||
hardware.Type = form.Type
|
||||
|
||||
models.DB.Save(&hardware)
|
||||
|
||||
c.Redirect(fmt.Sprintf("/hardware/%d", hardware.ID))
|
||||
}
|
||||
|
@@ -148,5 +148,7 @@ func TestPostEdit(c flamego.Context, form forms.TestForm, errs binding.Errors) {
|
||||
}
|
||||
}
|
||||
|
||||
models.DB.Save(&test)
|
||||
|
||||
c.Redirect(fmt.Sprintf("/test/%d", test.ID))
|
||||
}
|
||||
|
Reference in New Issue
Block a user