[Issue #11] - reworked the benchmark profile add page to be more sensible; added links for editing and deleting settings profiles
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:
@@ -1,17 +1,27 @@
|
|||||||
{{ template "header" . }}
|
{{ template "header" . }}
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<h2>Add profile for {{ .benchmark.Name }}</h2>
|
<h2>Add benchmark settings profile</h2>
|
||||||
|
|
||||||
<form class="twelve columns" action="/benchmark/{{ .benchmark.ID }}/profile/add" method="POST">
|
<form class="twelve columns" action="/benchmark/profile/add" method="POST">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="six columns">
|
<div class="six columns">
|
||||||
<label for="benchmark_profile_benchmark">
|
<label for="benchmark_profile_benchmark">
|
||||||
Benchmark:
|
Benchmark:
|
||||||
|
{{ if .benchmark }}
|
||||||
<select id="benchmark_profile_benchmark" class="u-full-width" disabled>
|
<select id="benchmark_profile_benchmark" class="u-full-width" disabled>
|
||||||
<option value="{{ .benchmark.ID }}">{{ .benchmark.Name }}</option>
|
<option value="{{ .benchmark.ID }}">{{ .benchmark.Name }}</option>
|
||||||
</select>
|
</select>
|
||||||
<input type="hidden" name="benchmark_profile_benchmark" value="{{ .benchmark.ID }}">
|
<input type="hidden" name="benchmark_profile_benchmark" value="{{ .benchmark.ID }}">
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ if .benchmarks }}
|
||||||
|
<select id="benchmark_profile_benchmark" class="u-full-width" name="benchmark_profile_benchmark">
|
||||||
|
{{ range $benchmark := .benchmarks }}
|
||||||
|
<option value="{{ $benchmark.ID }}">{{ $benchmark.Name }}</option>
|
||||||
|
{{ end }}
|
||||||
|
</select>
|
||||||
|
{{ end }}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,17 @@
|
|||||||
|
|
||||||
<h4>Profiles for this Benchmark</h4>
|
<h4>Profiles for this Benchmark</h4>
|
||||||
|
|
||||||
<p><a href="/benchmark/{{ .benchmark.ID }}/profile/add">Add settings profile</a></p>
|
<p><a href="/benchmark/profile/add?benchmark={{ .benchmark.ID }}">Add settings profile</a></p>
|
||||||
|
|
||||||
<ul class="benchmark-profiles">
|
<ul class="benchmark-profiles">
|
||||||
{{ range $profile := .benchmark.BenchmarkProfiles }}
|
{{ range $profile := .benchmark.BenchmarkProfiles }}
|
||||||
<li>{{ $profile.Label }}</li>
|
<li>
|
||||||
|
{{ $profile.Label }}
|
||||||
|
<span>
|
||||||
|
<a href="/benchmark/profile/{{ $profile.ID }}/edit">Edit</a>
|
||||||
|
<a href="/benchmark/profile/{{ $profile.ID }}/delete">Delete</a>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func RegisterRoutes(f *flamego.Flame) {
|
|||||||
f.Get("/{benchmark_id}/edit", routes.BenchmarkGetEdit)
|
f.Get("/{benchmark_id}/edit", routes.BenchmarkGetEdit)
|
||||||
f.Post("/{benchmark_id}/edit", binding.Form(forms.BenchmarkForm{}), routes.BenchmarkPostEdit)
|
f.Post("/{benchmark_id}/edit", binding.Form(forms.BenchmarkForm{}), routes.BenchmarkPostEdit)
|
||||||
|
|
||||||
f.Group("/{benchmark_id}/profile", func() {
|
f.Group("/profile", func() {
|
||||||
f.Get("/add", routes.BenchmarkGetProfileAdd)
|
f.Get("/add", routes.BenchmarkGetProfileAdd)
|
||||||
f.Post("/add", binding.Form(forms.BenchmarkProfileForm{}), routes.BenchmarkPostProfileAdd)
|
f.Post("/add", binding.Form(forms.BenchmarkProfileForm{}), routes.BenchmarkPostProfileAdd)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -107,35 +107,34 @@ func BenchmarkPostEdit(c flamego.Context, form forms.BenchmarkForm, errs binding
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkGetProfileAdd(c flamego.Context, t template.Template, data template.Data) {
|
func BenchmarkGetProfileAdd(c flamego.Context, t template.Template, data template.Data) {
|
||||||
// find benchmark ID from request
|
// find benchmark ID from GET parameters
|
||||||
benchmarkID := c.Param("benchmark_id")
|
benchmarkID := c.Query("benchmark")
|
||||||
|
|
||||||
|
// check if the query parameter was used
|
||||||
|
if benchmarkID != "" {
|
||||||
// find benchmark from DB
|
// find benchmark from DB
|
||||||
var benchmark models.Benchmark
|
var benchmark models.Benchmark
|
||||||
models.DB.First(&benchmark, benchmarkID)
|
models.DB.First(&benchmark, benchmarkID)
|
||||||
data["benchmark"] = benchmark
|
data["benchmark"] = benchmark
|
||||||
|
} else {
|
||||||
|
// find all benchmarks from DB
|
||||||
|
var benchmarks []models.Benchmark
|
||||||
|
models.DB.Find(&benchmarks)
|
||||||
|
data["benchmarks"] = benchmarks
|
||||||
|
}
|
||||||
|
|
||||||
data["title"] = benchmark.Name
|
data["title"] = "Add new benchmark settings profile"
|
||||||
t.HTML(http.StatusOK, "benchmark/profile/add")
|
t.HTML(http.StatusOK, "benchmark/profile/add")
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkPostProfileAdd(c flamego.Context, form forms.BenchmarkProfileForm, errs binding.Errors) {
|
func BenchmarkPostProfileAdd(c flamego.Context, form forms.BenchmarkProfileForm, errs binding.Errors) {
|
||||||
// find benchmark ID from request
|
|
||||||
benchmarkID := c.Param("benchmark_id")
|
|
||||||
|
|
||||||
// find benchmark from DB
|
|
||||||
var benchmark models.Benchmark
|
|
||||||
models.DB.First(&benchmark, benchmarkID)
|
|
||||||
|
|
||||||
benchmarkProfile := models.BenchmarkProfile{
|
benchmarkProfile := models.BenchmarkProfile{
|
||||||
BenchmarkID: form.BenchmarkID,
|
BenchmarkID: form.BenchmarkID,
|
||||||
Label: form.Label,
|
Label: form.Label,
|
||||||
Settings: form.Settings,
|
Settings: form.Settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(form.BenchmarkID)
|
|
||||||
|
|
||||||
_ = models.DB.Create(&benchmarkProfile)
|
_ = models.DB.Create(&benchmarkProfile)
|
||||||
|
|
||||||
c.Redirect(fmt.Sprintf("/benchmark/%d", benchmark.ID))
|
c.Redirect(fmt.Sprintf("/benchmark/%d", form.BenchmarkID))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user