Compare commits
60 Commits
main
...
a8b1238017
Author | SHA1 | Date | |
---|---|---|---|
a8b1238017 | |||
73cb99630f | |||
6434fd0b9c | |||
3fa86ad23d | |||
190ae9f302 | |||
771d26ec3b | |||
da6397dd14 | |||
8e20e5e354 | |||
533c407183 | |||
fb76f28643 | |||
06262431da | |||
e734d4077d | |||
9617f4280d | |||
3ec5605c53 | |||
ed5232371c | |||
29d9cbc59c | |||
3eca29c2db | |||
8df9b7684f | |||
7282d0a4b6 | |||
0525838f4b | |||
958c72ee63 | |||
fa92321176 | |||
458646ee8e | |||
9df8f6c9e1 | |||
7e294c8f72 | |||
cefa79a8b8 | |||
1e87466ccb | |||
e3e4e24e56 | |||
2be6d216d1 | |||
93170d0935 | |||
2299ac0a93 | |||
3ec465872e | |||
52e4d9c420 | |||
9ddf7fa928 | |||
ab6b94cb5f | |||
39185f1144 | |||
403ab7f166 | |||
ba06a2ea4c | |||
95fe5ab400 | |||
9ddc3db48d | |||
8412163370 | |||
86bf4d37f0 | |||
6cb2ac0263 | |||
dea08d15dd | |||
cf7623fbb9 | |||
a51c8aa8a4 | |||
9fd6ec6b0b | |||
5b14721b14 | |||
dcfc6e0115 | |||
4ad9a92306 | |||
c5df026d04 | |||
16704aeeb1 | |||
bae65994f8 | |||
19670e9abd | |||
49925c6d8f | |||
0ee3d06f89 | |||
9dceaa8119 | |||
cbc816ad70 | |||
92d8e5fa09 | |||
cd7003223a |
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,7 +3,6 @@ blt
|
|||||||
|
|
||||||
# Local data files
|
# Local data files
|
||||||
data/
|
data/
|
||||||
tmp/
|
|
||||||
|
|
||||||
# Compiled assets
|
# Compiled assets
|
||||||
public/css/
|
public/css/
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,7 +16,3 @@ type Benchmark struct {
|
|||||||
// has many results
|
// has many results
|
||||||
Results []Result
|
Results []Result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Benchmark) StringID() string {
|
|
||||||
return strconv.Itoa(int(b.ID))
|
|
||||||
}
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,29 +19,3 @@ type Test struct {
|
|||||||
// has many results
|
// has many results
|
||||||
Results []Result
|
Results []Result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Test) SelectedBenchmarks() []string {
|
|
||||||
benchmarks := t.Benchmarks
|
|
||||||
ids := make([]string, len(benchmarks))
|
|
||||||
for i, b := range benchmarks {
|
|
||||||
ids[i] = strconv.Itoa(int(b.ID))
|
|
||||||
}
|
|
||||||
return ids
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *Test) IsBenchmarkSelected(benchmarkID string) bool {
|
|
||||||
benchmarkConv, err := strconv.ParseUint(benchmarkID, 10, 0)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error parsing Uint: ", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
benchmarkUint := uint(benchmarkConv)
|
|
||||||
|
|
||||||
for _, b := range t.Benchmarks {
|
|
||||||
if b.ID == benchmarkUint {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
@ -30,9 +30,9 @@
|
|||||||
<label for="test_benchmarks">
|
<label for="test_benchmarks">
|
||||||
Benchmarks to Test:
|
Benchmarks to Test:
|
||||||
<select id="test_benchmarks" class="u-full-width" name="test_benchmarks" multiple>
|
<select id="test_benchmarks" class="u-full-width" name="test_benchmarks" multiple>
|
||||||
{{ $selectedBenchmarks := .selectedBenchmarks }}
|
{{ $testBenchmarks := .test.Benchmarks }}
|
||||||
{{ range $bm := .benchmarks }}
|
{{ range $bm := .benchmarks }}
|
||||||
<option value="{{ $bm.ID }}" {{ if contains $selectedBenchmarks $bm.StringID }}selected{{ end }}>{{ $bm.Name }}</option>
|
<option value="{{ $bm.ID }}" {{ if contains $testBenchmarks $bm.ID }}selected{{ end }}>{{ $bm.Name }}</option>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
|
@ -99,50 +99,6 @@ func TestGetEdit(c flamego.Context, t template.Template, data template.Data) {
|
|||||||
models.DB.Find(&benchmarks)
|
models.DB.Find(&benchmarks)
|
||||||
data["benchmarks"] = benchmarks
|
data["benchmarks"] = benchmarks
|
||||||
|
|
||||||
// determine which benchmarks are selected in a test
|
|
||||||
selectedBenchmarks := test.SelectedBenchmarks()
|
|
||||||
data["selectedBenchmarks"] = selectedBenchmarks
|
|
||||||
|
|
||||||
data["title"] = fmt.Sprintf("Editing Test: %s", test.Name)
|
data["title"] = fmt.Sprintf("Editing Test: %s", test.Name)
|
||||||
t.HTML(http.StatusOK, "test/edit")
|
t.HTML(http.StatusOK, "test/edit")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPostEdit(c flamego.Context, form forms.TestForm, 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 test ID from request
|
|
||||||
testID := c.Param("test_id")
|
|
||||||
|
|
||||||
// find hardware from DB
|
|
||||||
var test models.Test
|
|
||||||
models.DB.Preload("Hardware").Preload("Benchmarks").First(&test, testID)
|
|
||||||
|
|
||||||
test.Name = form.Name
|
|
||||||
test.Description = form.Description
|
|
||||||
test.HardwareID = form.Hardware
|
|
||||||
|
|
||||||
// bind benchmarks to test that aren't already associated
|
|
||||||
for _, b := range form.Benchmarks {
|
|
||||||
if ! test.IsBenchmarkSelected(b) {
|
|
||||||
var benchmark models.Benchmark
|
|
||||||
models.DB.First(&benchmark, b) // find benchmark
|
|
||||||
models.DB.Model(&test).Association("Benchmarks").Append(&benchmark)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// removed associated benchmarks that weren't in the form
|
|
||||||
for _, b := range test.Benchmarks {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Redirect(fmt.Sprintf("/test/%d", test.ID))
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user