Added ability to edit benchmark parameters
This commit is contained in:
38
templates/benchmark/edit.tmpl
Normal file
38
templates/benchmark/edit.tmpl
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
{{ template "header" . }}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<h2>Editing Benchmark: {{ .benchmark.Name }}</h2>
|
||||||
|
|
||||||
|
<form class="twelve columns" action="/benchmark/{{ .benchmark.ID }}/edit" method="POST">
|
||||||
|
<div class="row">
|
||||||
|
<div class="nine columns">
|
||||||
|
<label for="benchmark_name">
|
||||||
|
Benchmark name:
|
||||||
|
<input id="benchmark_name" class="u-full-width" type="text" name="benchmark_name" placeholder="Unigine Heaven" value="{{ .benchmark.Name }}">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="three columns">
|
||||||
|
<label for="benchmark_scoring">
|
||||||
|
Benchmark type:
|
||||||
|
<select id="benchmark_scoring" class="u-full-width" name="benchmark_scoring">
|
||||||
|
<option value="fps" {{ if eq .benchmark.ScoringType "fps" }}selected{{ end }}>Frames per second</option>
|
||||||
|
<option value="ms" {{ if eq .benchmark.ScoringType "ms" }}selected{{ end }}>Frame time</option>
|
||||||
|
<option value="pts" {{ if eq .benchmark.ScoringType "pts" }}selected{{ end }}>Total points</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<label for="benchmark_description">
|
||||||
|
Benchmark description:
|
||||||
|
<textarea id="benchmark_description" class="twelve columns" cols="30" rows="10" name="benchmark_description">{{ .benchmark.Description }}</textarea>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input class="button-primary u-full-width" type="submit" value="Submit">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{ template "footer" . }}
|
@@ -3,8 +3,12 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<h2>{{ .benchmark.Name }}</h2>
|
<h2>{{ .benchmark.Name }}</h2>
|
||||||
|
|
||||||
|
<span><a href="/benchmark/{{ .benchmark.ID }}/edit">Edit</a></span>
|
||||||
|
|
||||||
<p>{{ .benchmark.ScoringType }}</p>
|
<p>{{ .benchmark.ScoringType }}</p>
|
||||||
|
|
||||||
|
<p>{{ .benchmark.Description }}</p>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<h4>Latest Benchmark Results:</h4>
|
<h4>Latest Benchmark Results:</h4>
|
||||||
|
@@ -41,6 +41,9 @@ func RegisterRoutes(f *flamego.Flame) {
|
|||||||
f.Post("/create", binding.Form(forms.BenchmarkForm{}), routes.BenchmarkPostCreate)
|
f.Post("/create", binding.Form(forms.BenchmarkForm{}), routes.BenchmarkPostCreate)
|
||||||
|
|
||||||
f.Get("/{benchmark_id}", routes.BenchmarkGetView)
|
f.Get("/{benchmark_id}", routes.BenchmarkGetView)
|
||||||
|
|
||||||
|
f.Get("/{benchmark_id}/edit", routes.BenchmarkGetEdit)
|
||||||
|
f.Post("/{benchmark_id}/edit", binding.Form(forms.BenchmarkForm{}), routes.BenchmarkPostEdit)
|
||||||
})
|
})
|
||||||
|
|
||||||
// test routes
|
// test routes
|
||||||
|
@@ -64,3 +64,44 @@ func BenchmarkPostCreate(c flamego.Context, form forms.BenchmarkForm, errs bindi
|
|||||||
|
|
||||||
c.Redirect(fmt.Sprintf("/benchmark/%d", benchmark.ID))
|
c.Redirect(fmt.Sprintf("/benchmark/%d", benchmark.ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkGetEdit(c flamego.Context, t template.Template, data template.Data) {
|
||||||
|
// find benchmark ID from request
|
||||||
|
benchmarkID := c.Param("benchmark_id")
|
||||||
|
|
||||||
|
// find benchmark from DB
|
||||||
|
var benchmark models.Benchmark
|
||||||
|
models.DB.First(&benchmark, benchmarkID)
|
||||||
|
data["benchmark"] = benchmark
|
||||||
|
|
||||||
|
data["title"] = "Editing Benchmark"
|
||||||
|
t.HTML(http.StatusOK, "benchmark/edit")
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkPostEdit(c flamego.Context, form forms.BenchmarkForm, 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 benchmark ID from request
|
||||||
|
benchmarkID := c.Param("benchmark_id")
|
||||||
|
|
||||||
|
// find benchmark from DB
|
||||||
|
var benchmark models.Benchmark
|
||||||
|
models.DB.First(&benchmark, benchmarkID)
|
||||||
|
|
||||||
|
benchmark.Name = form.Name
|
||||||
|
benchmark.ScoringType = form.ScoringType
|
||||||
|
benchmark.Description = form.Description
|
||||||
|
|
||||||
|
models.DB.Save(&benchmark)
|
||||||
|
|
||||||
|
c.Redirect(fmt.Sprintf("/benchmark/%d", benchmark.ID))
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user