Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
06262431da | |||
e734d4077d | |||
9617f4280d | |||
3ec5605c53 | |||
ed5232371c | |||
29d9cbc59c | |||
3eca29c2db | |||
8df9b7684f | |||
7282d0a4b6 | |||
0525838f4b | |||
958c72ee63 | |||
fa92321176 | |||
458646ee8e | |||
9df8f6c9e1 | |||
7e294c8f72 | |||
cefa79a8b8 | |||
1e87466ccb |
2
Makefile
2
Makefile
@ -4,7 +4,7 @@ VERSION=`git describe --tags`
|
|||||||
.PHONY: build
|
.PHONY: build
|
||||||
## build: Compile the packages.
|
## build: Compile the packages.
|
||||||
build:
|
build:
|
||||||
@go build -o $(NAME) -ldflags "-X git.metaunix.net/bitgoblin/blt/app.Version=$(VERSION)"
|
@go build -o $(NAME) -ldflags "-X git.metaunix.net/bitgoblin/blt/app.AppVersion=$(VERSION)"
|
||||||
|
|
||||||
.PHONY: run
|
.PHONY: run
|
||||||
## run: Build and Run in development mode.
|
## run: Build and Run in development mode.
|
||||||
|
14
app/vars.go
14
app/vars.go
@ -1,5 +1,15 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
var (
|
import (
|
||||||
Version string = "N/a"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
AppVersion string = "N/a"
|
||||||
|
RuntimeVersion string = runtimeVersion()
|
||||||
|
)
|
||||||
|
|
||||||
|
func runtimeVersion() string {
|
||||||
|
raw_string := runtime.Version()
|
||||||
|
return raw_string[2:]
|
||||||
|
}
|
||||||
|
@ -11,5 +11,8 @@ type Benchmark struct {
|
|||||||
Description string
|
Description string
|
||||||
|
|
||||||
// many-to-many test
|
// many-to-many test
|
||||||
Tests[] Test `gorm:"many2many:tests_benchmarks;"`
|
Tests []Test `gorm:"many2many:tests_benchmarks;"`
|
||||||
|
|
||||||
|
// has many results
|
||||||
|
Results []Result
|
||||||
}
|
}
|
||||||
|
@ -10,5 +10,8 @@ type Hardware struct {
|
|||||||
Type string
|
Type string
|
||||||
|
|
||||||
// has many tests
|
// has many tests
|
||||||
Tests[] Test
|
Tests []Test
|
||||||
|
|
||||||
|
// has many results
|
||||||
|
Results []Result
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,6 @@ func Open() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Migrate the schema
|
// Migrate the schema
|
||||||
DB.AutoMigrate(&Test{}, &Hardware{}, &Benchmark{})
|
DB.AutoMigrate(&Test{}, &Hardware{}, &Benchmark{}, &Result{})
|
||||||
log.Println("Database migrations complete.")
|
log.Println("Database migrations complete.")
|
||||||
}
|
}
|
||||||
|
24
models/result.go
Normal file
24
models/result.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Result struct {
|
||||||
|
gorm.Model
|
||||||
|
AverageScore float32
|
||||||
|
MinimumScore float32
|
||||||
|
MaximumScore float32
|
||||||
|
|
||||||
|
// belongs to Hardware
|
||||||
|
HardwareID int
|
||||||
|
Hardware Hardware
|
||||||
|
|
||||||
|
// belongs to Benchmark
|
||||||
|
BenchmarkID int
|
||||||
|
Benchmark Benchmark
|
||||||
|
|
||||||
|
// belongs to Test
|
||||||
|
TestID int
|
||||||
|
Test Test
|
||||||
|
}
|
@ -14,5 +14,8 @@ type Test struct {
|
|||||||
Hardware Hardware
|
Hardware Hardware
|
||||||
|
|
||||||
// many-to-many benchmarks
|
// many-to-many benchmarks
|
||||||
Benchmarks[] Benchmark `gorm:"many2many:tests_benchmarks;"`
|
Benchmarks []Benchmark `gorm:"many2many:tests_benchmarks;"`
|
||||||
|
|
||||||
|
// has many results
|
||||||
|
Results []Result
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ body{
|
|||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding-top: 80px;
|
padding-top: 80px;
|
||||||
padding-bottom: 80px;
|
padding-bottom: 100px;
|
||||||
background: #eee;
|
background: #eee;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,6 +25,32 @@ form select[multiple]{
|
|||||||
min-height: 100px;
|
min-height: 100px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Material card styles */
|
||||||
|
.card-1 {
|
||||||
|
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
|
||||||
|
transition: all 0.3s cubic-bezier(.25,.8,.25,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-1:hover {
|
||||||
|
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-2 {
|
||||||
|
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-3 {
|
||||||
|
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-4 {
|
||||||
|
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-5 {
|
||||||
|
box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);
|
||||||
|
}
|
||||||
|
|
||||||
.container{
|
.container{
|
||||||
max-width: 1024px;
|
max-width: 1024px;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<!-- footer -->
|
<!-- footer -->
|
||||||
<nav id="main-footer">
|
<nav id="main-footer">
|
||||||
<p>BLT version {{ .app_version }}</p>
|
<p>BLT version {{ .app_version }} | Built with Go {{ .runtime_version }}</p>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
@ -16,5 +16,5 @@
|
|||||||
{{ template "navbar" . }}
|
{{ template "navbar" . }}
|
||||||
|
|
||||||
<!-- main content -->
|
<!-- main content -->
|
||||||
<div id="main-content" class="container">
|
<div id="main-content" class="container card-5">
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{{ define "navbar" }}
|
{{ define "navbar" }}
|
||||||
<nav id="main-nav">
|
<nav id="main-nav" class="card-2">
|
||||||
<div class="nav-left">
|
<div class="nav-left">
|
||||||
<h4>BLT</h4>
|
<h4>BLT</h4>
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -17,9 +17,79 @@
|
|||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
<h4>Add new result:</h4>
|
||||||
|
|
||||||
|
<form class="u-full-width" action="/result/add" method="POST">
|
||||||
|
<div class="row">
|
||||||
|
<div class="columns four">
|
||||||
|
<label for="result_benchmark">
|
||||||
|
Benchmark:
|
||||||
|
<select id="result_benchmark" class="u-full-width" name="result_benchmark">
|
||||||
|
{{ range $bm := .test.Benchmarks }}
|
||||||
|
<option value="{{ $bm.ID }}">{{ $bm.Name }}</option>
|
||||||
|
{{ end }}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="columns two">
|
||||||
|
<label for="result_avg">
|
||||||
|
Average score:
|
||||||
|
<input id="result_avg" class="u-full-width" type="number" name="result_avg" value="0">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="columns two">
|
||||||
|
<label for="result_min">
|
||||||
|
Minimum score:
|
||||||
|
<input id="result_min" class="u-full-width" type="number" name="result_min" value="0">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="columns two">
|
||||||
|
<label for="result_max">
|
||||||
|
Maximum score:
|
||||||
|
<input id="result_max" class="u-full-width" type="number" name="result_max" value="0">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="columns two">
|
||||||
|
<button class="button-primary u-full-width" type="submit" name="button">Submit</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" name="result_test" value="{{ .test.ID }}">
|
||||||
|
<input type="hidden" name="result_hardware" value="{{ .test.Hardware.ID }}">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
<h4>Latest Benchmark Results:</h4>
|
<h4>Latest Benchmark Results:</h4>
|
||||||
|
|
||||||
<p>There are currently no benchmarks recorded in this test.</p>
|
{{ $length := len .test.Results }} {{ if eq $length 0 }}
|
||||||
|
<p>There are currently no benchmarks recorded in this test.</p>
|
||||||
|
{{ else }}
|
||||||
|
<table class="u-full-width">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Benchmark</th>
|
||||||
|
<th>Average</th>
|
||||||
|
<th>Minimum</th>
|
||||||
|
<th>Maximum</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{ range $res := .test.Results }}
|
||||||
|
<tr>
|
||||||
|
<td>{{ $res.Benchmark.Name }}</td>
|
||||||
|
<td>{{ $res.AverageScore }}</td>
|
||||||
|
<td>{{ if eq $res.MinimumScore 0.0 }}N/a{{ else }}{{ $res.MinimumScore }}{{ end }}</td>
|
||||||
|
<td>{{ if eq $res.MaximumScore 0.0 }}N/a{{ else }}{{ $res.MaximumScore }}{{ end }}</td>
|
||||||
|
</tr>
|
||||||
|
{{ end }}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
10
web/forms/result.go
Normal file
10
web/forms/result.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package forms
|
||||||
|
|
||||||
|
type ResultForm struct {
|
||||||
|
Test int `form:"result_test" validate:"required"`
|
||||||
|
Hardware int `form:"result_hardware" validate:"required"`
|
||||||
|
Benchmark int `form:"result_benchmark" validate:"required"`
|
||||||
|
AverageScore float32 `form:"result_avg" validate:"required"`
|
||||||
|
MinimumScore float32 `form:"result_min"`
|
||||||
|
MaximumScore float32 `form:"result_max"`
|
||||||
|
}
|
@ -7,5 +7,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func CustomVars(data template.Data) {
|
func CustomVars(data template.Data) {
|
||||||
data["app_version"] = app.Version
|
data["app_version"] = app.AppVersion
|
||||||
|
data["runtime_version"] = app.RuntimeVersion
|
||||||
}
|
}
|
||||||
|
@ -53,4 +53,9 @@ func RegisterRoutes(f *flamego.Flame) {
|
|||||||
|
|
||||||
f.Get("/{test_id}", routes.TestGetView)
|
f.Get("/{test_id}", routes.TestGetView)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// result routes
|
||||||
|
f.Group("/result", func() {
|
||||||
|
f.Post("/add", binding.Form(forms.ResultForm{}), routes.ResultPostCreate)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
39
web/routes/result.go
Normal file
39
web/routes/result.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package routes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/flamego/binding"
|
||||||
|
"github.com/flamego/flamego"
|
||||||
|
"github.com/flamego/validator"
|
||||||
|
|
||||||
|
"git.metaunix.net/bitgoblin/blt/models"
|
||||||
|
"git.metaunix.net/bitgoblin/blt/web/forms"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ResultPostCreate(c flamego.Context, form forms.ResultForm, 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
result := models.Result{
|
||||||
|
TestID: form.Test,
|
||||||
|
HardwareID: form.Hardware,
|
||||||
|
BenchmarkID: form.Benchmark,
|
||||||
|
AverageScore: form.AverageScore,
|
||||||
|
MinimumScore: form.MinimumScore,
|
||||||
|
MaximumScore: form.MaximumScore,
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = models.DB.Create(&result)
|
||||||
|
|
||||||
|
c.Redirect(fmt.Sprintf("/test/%d", result.TestID))
|
||||||
|
}
|
@ -30,7 +30,7 @@ func TestGetView(c flamego.Context, t template.Template, data template.Data) {
|
|||||||
|
|
||||||
// find hardware from DB
|
// find hardware from DB
|
||||||
var test models.Test
|
var test models.Test
|
||||||
models.DB.Preload("Hardware").Preload("Benchmarks").First(&test, testID)
|
models.DB.Preload("Hardware").Preload("Benchmarks").Preload("Results.Benchmark").First(&test, testID)
|
||||||
data["test"] = test
|
data["test"] = test
|
||||||
|
|
||||||
data["title"] = test.Name
|
data["title"] = test.Name
|
||||||
|
Reference in New Issue
Block a user