Started working on test edit page; removed nodemon because it wasn't working
This commit is contained in:
10
web/helpers.go
Normal file
10
web/helpers.go
Normal file
@ -0,0 +1,10 @@
|
||||
package web
|
||||
|
||||
func Contains(slice []string, val string) bool {
|
||||
for _, v := range slice {
|
||||
if v == val {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
@ -51,7 +51,10 @@ func RegisterRoutes(f *flamego.Flame) {
|
||||
f.Get("/create", routes.TestGetCreate)
|
||||
f.Post("/create", binding.Form(forms.TestForm{}), routes.TestPostCreate)
|
||||
|
||||
f.Get("/{test_id}", routes.TestGetView)
|
||||
f.Group("/{test_id}", func() {
|
||||
f.Get("", routes.TestGetView)
|
||||
f.Get("/edit", routes.TestGetEdit)
|
||||
})
|
||||
})
|
||||
|
||||
// result routes
|
||||
|
@ -81,3 +81,24 @@ func TestPostCreate(c flamego.Context, form forms.TestForm, errs binding.Errors)
|
||||
|
||||
c.Redirect(fmt.Sprintf("/test/%d", test.ID))
|
||||
}
|
||||
|
||||
func TestGetEdit(c flamego.Context, t template.Template, data template.Data) {
|
||||
// find test in DB
|
||||
testID := c.Param("test_id")
|
||||
var test models.Test
|
||||
models.DB.Preload("Hardware").Preload("Benchmarks").First(&test, testID)
|
||||
data["test"] = test
|
||||
|
||||
// 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"] = fmt.Sprintf("Editing Test: %s", test.Name)
|
||||
t.HTML(http.StatusOK, "test/edit")
|
||||
}
|
||||
|
Reference in New Issue
Block a user