Compare commits
56 Commits
main
...
190ae9f302
Author | SHA1 | Date | |
---|---|---|---|
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,32 +0,0 @@
|
|||||||
pipeline:
|
|
||||||
build:
|
|
||||||
image: golang:1.22
|
|
||||||
commands:
|
|
||||||
- go mod vendor
|
|
||||||
- GOOS=linux GOARCH=amd64 go build -o "dist/blt-linux-amd64-${CI_COMMIT_TAG}.bin"
|
|
||||||
- GOOS=windows GOARCH=amd64 go build -o "dist/blt-windows-amd64-${CI_COMMIT_TAG}.exe"
|
|
||||||
|
|
||||||
assets:
|
|
||||||
image: node:24
|
|
||||||
commands:
|
|
||||||
- npm install
|
|
||||||
- npm run grunt build
|
|
||||||
|
|
||||||
package:
|
|
||||||
image: alpine
|
|
||||||
commands:
|
|
||||||
- tar -cvzf "dist/blt-assets-${CI_COMMIT_TAG}.tar.gz" public/
|
|
||||||
when:
|
|
||||||
event: tag
|
|
||||||
|
|
||||||
gitea_release:
|
|
||||||
image: plugins/gitea-release
|
|
||||||
settings:
|
|
||||||
api_key:
|
|
||||||
from_secret: gitea_api_key
|
|
||||||
base_url: https://git.metaunix.net
|
|
||||||
title: "${CI_COMMIT_TAG}"
|
|
||||||
files:
|
|
||||||
- dist/blt-*
|
|
||||||
when:
|
|
||||||
event: tag
|
|
@@ -60,8 +60,6 @@ module.exports = function(grunt) {
|
|||||||
grunt.loadNpmTasks('grunt-contrib-coffee');
|
grunt.loadNpmTasks('grunt-contrib-coffee');
|
||||||
|
|
||||||
// CLI tasks.
|
// CLI tasks.
|
||||||
grunt.registerTask('build', ['sass', 'coffee']);
|
grunt.registerTask('default', ['sass', 'coffee']);
|
||||||
grunt.registerTask('dev', ['watch']);
|
|
||||||
grunt.registerTask('default', ['build']);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
12
main.go
12
main.go
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gotemplate "html/template"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@@ -26,16 +25,7 @@ func main() {
|
|||||||
f.Use(flamego.Renderer())
|
f.Use(flamego.Renderer())
|
||||||
|
|
||||||
// initialize templating engine
|
// initialize templating engine
|
||||||
f.Use(template.Templater(template.Options{
|
f.Use(template.Templater())
|
||||||
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)
|
||||||
|
@@ -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
|
|
||||||
}
|
|
||||||
|
@@ -4,8 +4,7 @@
|
|||||||
"description": "Self-hosted PC hardware benchmark logging tool",
|
"description": "Self-hosted PC hardware benchmark logging tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"grunt": "grunt",
|
"grunt": "grunt"
|
||||||
"nodemon": "nodemon"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -28,8 +27,8 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"grunt": "^1.5.3",
|
"grunt": "^1.5.3",
|
||||||
"grunt-cli": "^1.4.3",
|
"grunt-cli": "^1.4.3",
|
||||||
"grunt-contrib-coffee": "^2.1.0",
|
|
||||||
"grunt-contrib-sass": "^2.0.0",
|
"grunt-contrib-sass": "^2.0.0",
|
||||||
|
"grunt-contrib-coffee": "^2.1.0",
|
||||||
"grunt-contrib-watch": "^1.1.0",
|
"grunt-contrib-watch": "^1.1.0",
|
||||||
"sass": "^1.55.0"
|
"sass": "^1.55.0"
|
||||||
}
|
}
|
||||||
|
@@ -1,53 +0,0 @@
|
|||||||
{{ 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>
|
|
||||||
{{ $selectedBenchmarks := .selectedBenchmarks }}
|
|
||||||
{{ range $bm := .benchmarks }}
|
|
||||||
<option value="{{ $bm.ID }}" {{ if contains $selectedBenchmarks $bm.StringID }}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" . }}
|
|
@@ -1,10 +0,0 @@
|
|||||||
package web
|
|
||||||
|
|
||||||
func Contains(slice []string, val string) bool {
|
|
||||||
for _, v := range slice {
|
|
||||||
if v == val {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
@@ -51,10 +51,7 @@ 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.Group("/{test_id}", func() {
|
f.Get("/{test_id}", routes.TestGetView)
|
||||||
f.Get("", routes.TestGetView)
|
|
||||||
f.Get("/edit", routes.TestGetEdit)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// result routes
|
// result routes
|
||||||
|
@@ -81,68 +81,3 @@ 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
|
|
||||||
|
|
||||||
// determine which benchmarks are selected in a test
|
|
||||||
selectedBenchmarks := test.SelectedBenchmarks()
|
|
||||||
data["selectedBenchmarks"] = selectedBenchmarks
|
|
||||||
|
|
||||||
data["title"] = fmt.Sprintf("Editing Test: %s", test.Name)
|
|
||||||
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