Started working on test edit page; removed nodemon because it wasn't working

This commit is contained in:
2025-07-02 17:34:06 -04:00
parent 3fa86ad23d
commit 6434fd0b9c
9 changed files with 101 additions and 142 deletions

View File

@ -18,8 +18,8 @@ grunt-watch:
.PHONY: run .PHONY: run
## run: Build and Run in development mode. ## run: Build and Run in development mode.
run: run: build
@npm run nodemon @./$(NAME) -e development
.PHONY: run-prod .PHONY: run-prod
## run-prod: Build and Run in production mode. ## run-prod: Build and Run in production mode.

12
main.go
View File

@ -1,6 +1,7 @@
package main package main
import ( import (
gotemplate "html/template"
"log" "log"
"net/http" "net/http"
@ -25,7 +26,16 @@ func main() {
f.Use(flamego.Renderer()) f.Use(flamego.Renderer())
// initialize templating engine // initialize templating engine
f.Use(template.Templater()) f.Use(template.Templater(template.Options{
FuncMaps: []gotemplate.FuncMap{
{
"contains": web.Contains,
},
},
Directory: "templates",
Extensions: []string{".tmpl", ".html"},
},
))
// inject custom middleware // inject custom middleware
f.Use(middleware.CustomVars) f.Use(middleware.CustomVars)

View File

@ -1,6 +0,0 @@
{
"exec": "go run main.go",
"ext": "go",
"watch": ["."],
"ignore": ["README.md"]
}

131
package-lock.json generated
View File

@ -14,7 +14,6 @@
"grunt-contrib-coffee": "^2.1.0", "grunt-contrib-coffee": "^2.1.0",
"grunt-contrib-sass": "^2.0.0", "grunt-contrib-sass": "^2.0.0",
"grunt-contrib-watch": "^1.1.0", "grunt-contrib-watch": "^1.1.0",
"nodemon": "^3.1.10",
"sass": "^1.55.0" "sass": "^1.55.0"
} }
}, },
@ -996,13 +995,6 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/ignore-by-default": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz",
"integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==",
"dev": true,
"license": "ISC"
},
"node_modules/immutable": { "node_modules/immutable": {
"version": "4.3.6", "version": "4.3.6",
"resolved": "https://registry.npmjs.org/immutable/-/immutable-4.3.6.tgz", "resolved": "https://registry.npmjs.org/immutable/-/immutable-4.3.6.tgz",
@ -1291,79 +1283,6 @@
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==",
"dev": true "dev": true
}, },
"node_modules/nodemon": {
"version": "3.1.10",
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.10.tgz",
"integrity": "sha512-WDjw3pJ0/0jMFmyNDp3gvY2YizjLmmOUQo6DEBY+JgdvW/yQ9mEeSw6H5ythl5Ny2ytb7f9C2nIbjSxMNzbJXw==",
"dev": true,
"license": "MIT",
"dependencies": {
"chokidar": "^3.5.2",
"debug": "^4",
"ignore-by-default": "^1.0.1",
"minimatch": "^3.1.2",
"pstree.remy": "^1.1.8",
"semver": "^7.5.3",
"simple-update-notifier": "^2.0.0",
"supports-color": "^5.5.0",
"touch": "^3.1.0",
"undefsafe": "^2.0.5"
},
"bin": {
"nodemon": "bin/nodemon.js"
},
"engines": {
"node": ">=10"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/nodemon"
}
},
"node_modules/nodemon/node_modules/debug": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz",
"integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"ms": "^2.1.3"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/nodemon/node_modules/minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
"dev": true,
"license": "ISC",
"dependencies": {
"brace-expansion": "^1.1.7"
},
"engines": {
"node": "*"
}
},
"node_modules/nodemon/node_modules/semver": {
"version": "7.7.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz",
"integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==",
"dev": true,
"license": "ISC",
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/nopt": { "node_modules/nopt": {
"version": "3.0.6", "version": "3.0.6",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz", "resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz",
@ -1561,13 +1480,6 @@
"url": "https://github.com/sponsors/jonschlinkert" "url": "https://github.com/sponsors/jonschlinkert"
} }
}, },
"node_modules/pstree.remy": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz",
"integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==",
"dev": true,
"license": "MIT"
},
"node_modules/qs": { "node_modules/qs": {
"version": "6.12.1", "version": "6.12.1",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.12.1.tgz", "resolved": "https://registry.npmjs.org/qs/-/qs-6.12.1.tgz",
@ -1764,32 +1676,6 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/simple-update-notifier": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz",
"integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==",
"dev": true,
"license": "MIT",
"dependencies": {
"semver": "^7.5.3"
},
"engines": {
"node": ">=10"
}
},
"node_modules/simple-update-notifier/node_modules/semver": {
"version": "7.7.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz",
"integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==",
"dev": true,
"license": "ISC",
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/source-map-js": { "node_modules/source-map-js": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz",
@ -1867,16 +1753,6 @@
"node": ">=8.0" "node": ">=8.0"
} }
}, },
"node_modules/touch": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz",
"integrity": "sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==",
"dev": true,
"license": "ISC",
"bin": {
"nodetouch": "bin/nodetouch.js"
}
},
"node_modules/unc-path-regex": { "node_modules/unc-path-regex": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/unc-path-regex/-/unc-path-regex-0.1.2.tgz", "resolved": "https://registry.npmjs.org/unc-path-regex/-/unc-path-regex-0.1.2.tgz",
@ -1886,13 +1762,6 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/undefsafe": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz",
"integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==",
"dev": true,
"license": "MIT"
},
"node_modules/underscore.string": { "node_modules/underscore.string": {
"version": "3.3.6", "version": "3.3.6",
"resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-3.3.6.tgz", "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-3.3.6.tgz",

View File

@ -31,7 +31,6 @@
"grunt-contrib-coffee": "^2.1.0", "grunt-contrib-coffee": "^2.1.0",
"grunt-contrib-sass": "^2.0.0", "grunt-contrib-sass": "^2.0.0",
"grunt-contrib-watch": "^1.1.0", "grunt-contrib-watch": "^1.1.0",
"nodemon": "^3.1.10",
"sass": "^1.55.0" "sass": "^1.55.0"
} }
} }

53
templates/test/edit.tmpl Normal file
View File

@ -0,0 +1,53 @@
{{ template "header" . }}
<div class="row">
<h2>{{ .title }}</h2>
<form class="twelve columns" action="/test/{{ .test.ID }}/edit" method="POST">
<div class="row">
<div class="columns four">
<label for="test_hardware">
Hardware Component:
<select id="test_hardware" class="u-full-width" name="test_hardware">
{{ $testHardwareID := .test.Hardware.ID }}
{{ range $hw := .hardware }}
<option value="{{ $hw.ID }}" {{ if eq $testHardwareID $hw.ID }}selected{{ end }}>{{ $hw.Name }}</option>
{{ end }}
</select>
</label>
</div>
<div class="columns eight">
<label for="test_name">
Test name:
<input id="test_name" class="u-full-width" type="text" name="test_name" placeholder="My hardware benchmarking test" value="{{ .test.Name }}">
</label>
</div>
</div>
<div class="row">
<div class="columns twelve">
<label for="test_benchmarks">
Benchmarks to Test:
<select id="test_benchmarks" class="u-full-width" name="test_benchmarks" multiple>
{{ $testBenchmarks := .test.Benchmarks }}
{{ range $bm := .benchmarks }}
<option value="{{ $bm.ID }}" {{ if contains $testBenchmarks $bm.ID }}selected{{ end }}>{{ $bm.Name }}</option>
{{ end }}
</select>
</label>
</div>
</div>
<div class="row">
<label for="test_description">
Test description:
<textarea id="test_description" class="twelve columns" cols="30" rows="10" name="test_description"></textarea>
</label>
</div>
<input class="button-primary u-full-width" type="submit" value="Submit">
</form>
</div>
{{ template "footer" . }}

10
web/helpers.go Normal file
View 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
}

View File

@ -51,7 +51,10 @@ func RegisterRoutes(f *flamego.Flame) {
f.Get("/create", routes.TestGetCreate) f.Get("/create", routes.TestGetCreate)
f.Post("/create", binding.Form(forms.TestForm{}), routes.TestPostCreate) 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 // result routes

View File

@ -81,3 +81,24 @@ func TestPostCreate(c flamego.Context, form forms.TestForm, errs binding.Errors)
c.Redirect(fmt.Sprintf("/test/%d", test.ID)) 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")
}