60 Commits

Author SHA1 Message Date
27cff3e79b Adding event: tag to the asset packaging step
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline failed
2025-07-14 14:17:12 -04:00
03ef5cc905 Updating Grunt commands 2025-07-14 14:17:11 -04:00
f81879302d Started working on test edit page; removed nodemon because it wasn't working 2025-07-14 14:17:11 -04:00
9ecff3a25d Added nodemon to dev dependencies to automatially reload the app on changes 2025-07-14 14:17:10 -04:00
bef17b5a59 Fixed typo in Gruntfile; added Make tasks to compile frontend assets; Modernized the gathering of benchmark result data for the test view 2025-07-14 14:17:10 -04:00
82f42ecbed Improved some styles 2025-07-14 14:17:09 -04:00
673e2e9634 [Issue #8] - Licensing project under the BSD 2-Clause license (#10)
Adding license to project

Co-authored-by: Gregory Ballantine <gballantine@bitgoblin.tech>
Reviewed-on: #10
2025-07-14 14:17:07 -04:00
178894a360 3-add-gruntjs (#9)
Adding Grunt.js to compile SASS and CoffeeScript assets

Co-authored-by: Gregory Ballantine <gballantine555@gmail.com>
Reviewed-on: #9
2025-07-14 14:16:58 -04:00
5fc381c4b9 Updated some styles for tables and links 2025-07-14 13:53:50 -04:00
c9d2f7114a Added tests to hardware page 2025-07-14 13:53:50 -04:00
bce063c5f4 Updated some styles 2025-07-14 13:53:50 -04:00
b54d31213b Updated some styles 2025-07-14 13:53:50 -04:00
ae4198f3cc Fixed results table in test view 2025-07-14 13:53:50 -04:00
9fdf6e2b99 Fixed results table in test view 2025-07-14 13:53:50 -04:00
8f0cce7550 Fixed results table in test view 2025-07-14 13:53:50 -04:00
d97fee0911 Fixed results table in test view 2025-07-14 13:53:50 -04:00
de107761eb Added back reference associations for result; added table of results to test view 2025-07-14 13:53:50 -04:00
26ad420436 added missing import 2025-07-14 13:53:50 -04:00
47f3dcdbd1 Fixed result form stuff 2025-07-14 13:53:50 -04:00
6bb06205b0 Fixed float variable types 2025-07-14 13:53:50 -04:00
b508efd5a8 Added result creation route 2025-07-14 13:53:50 -04:00
e5a18f77f2 Added result model; added form to submit results 2025-07-14 13:53:50 -04:00
db41f0d6bd Added result model; added form to submit results 2025-07-14 13:53:50 -04:00
b93c8a5319 Added result model; added form to submit results 2025-07-14 13:53:50 -04:00
346b9e3911 Cleaned up runtime version 2025-07-14 13:53:50 -04:00
446590acb1 Added Go runtime version to the layout footer 2025-07-14 13:53:50 -04:00
a38ede5187 Added Go runtime version to the layout footer 2025-07-14 13:53:50 -04:00
2b3f24ee5c Fixed associating benchmarks to test 2025-07-14 13:53:50 -04:00
9104125de7 Fixed creating new test 2025-07-14 13:53:50 -04:00
5ad0810d81 Fixed creating new test 2025-07-14 13:53:50 -04:00
e27fd8d214 Added more information to the test view page 2025-07-14 13:53:50 -04:00
3910c4dc9c Fixed typo in test view route 2025-07-14 13:53:50 -04:00
3b8a30c7f8 Fixed typos in benchmark list view 2025-07-14 13:53:50 -04:00
293098e173 Fixed typos in model searches 2025-07-14 13:53:50 -04:00
10298cbf7c Fixed typo in benchmark list view 2025-07-14 13:53:50 -04:00
743a108add Fixed benchmark form submission error 2025-07-14 13:53:50 -04:00
c8a47b270a Fixed mix up between benchmark and hardware routes files 2025-07-14 13:53:50 -04:00
fde8d1dee4 Added benchmarks routes and views 2025-07-14 13:53:50 -04:00
bee64576bc Slight tweak to create test view 2025-07-14 13:53:50 -04:00
3c1d48a9ed Fixed form select field styling 2025-07-14 13:53:50 -04:00
633fc4ac02 Fixed variable capitalization in create test view 2025-07-14 13:53:50 -04:00
79924cd978 Added description field to Test model 2025-07-14 13:53:50 -04:00
e5443fb644 Passed hardware components and benchmarks to create test view 2025-07-14 13:53:50 -04:00
81a87e2761 Added route to view test 2025-07-14 13:53:50 -04:00
65550c983c Added route to view test 2025-07-14 13:53:50 -04:00
f3a2376c19 Added route to view test 2025-07-14 13:53:50 -04:00
99f45b3b3a Added route to view hardware component 2025-07-14 13:53:50 -04:00
4718aeaccd Added route to view hardware component 2025-07-14 13:53:50 -04:00
62654b9a3e Added route to view hardware component 2025-07-14 13:53:50 -04:00
93778274c2 Added hardware routes and views 2025-07-14 13:53:50 -04:00
7c13b1f209 Lots of changes 2025-07-14 13:53:50 -04:00
e09d399c98 Added ability to create projects 2025-07-14 13:53:50 -04:00
c9ad5df2ed Refactored models code to follow a better approach for opening and closing the database connection 2025-07-14 13:53:50 -04:00
0f89087134 Added models; started working on project routes 2025-07-14 13:53:50 -04:00
819baeb0c3 Added Gorm to project 2025-07-14 13:53:50 -04:00
fe303cb778 Copied some styles from Leviathan 2025-07-14 13:53:50 -04:00
98bd1f7eca Started working on the layout of the app 2025-07-14 13:53:50 -04:00
09a2667fc5 Updated Makefile to auto-define version 2025-07-14 13:53:50 -04:00
4020812549 Added templating, versioning, middleware, etc 2025-07-14 13:53:50 -04:00
8bc9849776 Better start for Flamego 2025-07-14 13:53:50 -04:00
27 changed files with 2413 additions and 187 deletions

7
.gitignore vendored
View File

@ -4,3 +4,10 @@ blt
# Local data files
data/
# Compiled assets
public/css/
public/js/
# Node modules
node_modules/

32
.woodpecker.yml Normal file
View File

@ -0,0 +1,32 @@
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

67
Gruntfile.js Normal file
View File

@ -0,0 +1,67 @@
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
dist: {
options: {
style: 'compressed'
},
files: [{
expand: true,
cwd: 'assets/styles',
src: ['**/*.sass'],
dest: 'public/css',
ext: '.css'
}]
}
},
coffee: {
options: {
sourceMap: true,
style: 'compressed'
},
files: {
expand: true,
flatten: true,
cwd: 'assets/scripts',
src: ['*.coffee'],
dest: 'public/js',
ext: '.js'
}
},
watch: {
css: {
files: ['assets/styles/**/*.sass'],
tasks: ['sass'],
options: {
atBegin: true,
spawn: false
}
},
js: {
files: ['assets/scripts/**/*.coffee'],
tasks: ['coffee'],
options: {
atBegin: true,
spawn: false
}
}
}
});
// Load plugins.
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-coffee');
// CLI tasks.
grunt.registerTask('build', ['sass', 'coffee']);
grunt.registerTask('dev', ['watch']);
grunt.registerTask('default', ['build']);
};

9
LICENSE Normal file
View File

@ -0,0 +1,9 @@
Copyright (c) 2023 Bit Goblin
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -6,6 +6,16 @@ VERSION=`git describe --tags`
build:
@go build -o $(NAME) -ldflags "-X git.metaunix.net/bitgoblin/blt/app.AppVersion=$(VERSION)"
.PHONY: grunt
## grunt: Compile frontend assets.
grunt:
@npm run grunt
.PHONY: grunt-watch
## grunt-watch: Compile frontend assets while watching for changes.
grunt-watch:
@npm run grunt watch
.PHONY: run
## run: Build and Run in development mode.
run: build

View File

@ -0,0 +1,7 @@
root = if typeof window isnt 'undefined' then window else global
root.roundDecimal = (value) ->
return Math.round(value * 100) / 100
$ ->
console.log('DOM is ready.')

View File

@ -0,0 +1,62 @@
testId = $('#results-table').data('test-id')
$ ->
$('#result-form').on 'submit', (e) ->
e.preventDefault()
form = $(this)
formData = $(this).serialize()
benchmarkId = $(this).find('[name="result_benchmark"]').val()
$.post '/api/v1/result/add', formData, (response) ->
if response == 'success'
fetchTestBenchmarkResults(testId, benchmarkId)
form[0].reset()
fetchTestBenchmarkResults = (testId, benchmarkId) ->
try
benchmarkSearchParams = new URLSearchParams
benchmark_id: benchmarkId
benchmarkRes = await fetch("/api/v1/benchmark/details?#{benchmarkSearchParams}")
benchmarkData = await benchmarkRes.json()
resultSearchParams = new URLSearchParams
test_id: testId
benchmark_id: benchmarkId
resultRes = await fetch("/api/v1/result/list?#{resultSearchParams}")
resultData = await resultRes.json()
avg_total = 0
min_total = 0
max_total = 0
for result in resultData
avg_total += result.AverageScore
min_total += result.MinimumScore if result.MinimumScore
max_total += result.MaximumScore if result.MaximumScore
tableRow = $("#results-table tr[data-benchmark-id=#{benchmarkId}]")
tableRow.empty()
tableRow.append('<td><a href="/benchmark/' + benchmarkData.ID + '">' + benchmarkData.Name + '</a></td>')
tableRow.append('<td>' + benchmarkData.ScoringType + '</td>')
tableRow.append('<td>' + resultData.length + '</td>')
if resultData.length != 0
tableRow.append('<td>' + roundDecimal(avg_total / resultData.length) + '</td>')
else
tableRow.append('<td>N/a</td>')
if min_total != 0
tableRow.append('<td>' + roundDecimal(min_total / resultData.length) + '</td>')
tableRow.append('<td>' + roundDecimal(max_total / resultData.length) + '</td>')
else
tableRow.append('<td>N/a</td>')
tableRow.append('<td>N/a</td>')
catch error
console.error 'An error occurred while fetching benchmark results.', error
$('#results-table tbody tr').each (index, tr) ->
benchmarkId = $(tr).data('benchmark-id')
console.log("Fetching results for benchmark id: " + benchmarkId)
fetchTestBenchmarkResults(testId, benchmarkId)

133
assets/styles/kourend.sass Normal file
View File

@ -0,0 +1,133 @@
html,
body
width: 100%
height: 100%
margin: 0
padding: 0
body
height: auto
min-height: 100%
box-sizing: border-box
padding-top: 80px
padding-bottom: 100px
background: #eee
a
color: teal
transition: color 180ms ease-in-out
&:hover
color: darkcyan
button.button-primary
background: teal
transition: background 180ms ease-in-out
&:hover
background: darkcyan
textarea
max-width: 100%
min-width: 100%
height: 100px
form select[multiple]
min-height: 100px
table
border: 1px solid #ddd
border-radius: 8px
border-spacing: 0
overflow: hidden
table th,
table td,
table th:first-child,
table td:first-child
border: none
padding: 7px 12px
table thead tr
border-radius: 8px 8px 0 0
&:last-child
border-radius: 0 0 8px 8px
table thead tr,
table tr:nth-child(even)
background: #eee
table tbody tr
transition: background 180ms ease-in-out
&:hover
background: lightgrey
/* 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)
&: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
max-width: 1200px
#main-nav
position: fixed
top: 0
left: 0
width: 100%
height: 64px
background: teal
color: white
z-index: 20
ul
list-style: none
display: inline-block
li
display: inline-block
margin-left: 15px
h4
display: inline-block
margin-left: 25px
line-height: 64px
a
color: white
font-size: 2.25rem
line-height: 64px
transition: all 200ms ease-in-out
&:hover
color: #eee
font-size: 2.5rem
#main-content
padding: 15px 25px
background: white
border-radius: 8px
z-index: 10
#main-footer
position: fixed
bottom: 0
left: 0
width: 100%
height: 64px
p
margin-bottom: 5px
text-align: center

15
main.go
View File

@ -1,6 +1,7 @@
package main
import (
gotemplate "html/template"
"log"
"net/http"
@ -21,8 +22,20 @@ func main() {
// initialize database
models.Open()
// initialize base renderer
f.Use(flamego.Renderer())
// 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
f.Use(middleware.CustomVars)

View File

@ -11,7 +11,4 @@ type Hardware struct {
// has many tests
Tests []Test
// has many results
Results []Result
}

View File

@ -10,10 +10,6 @@ type Result struct {
MinimumScore float32
MaximumScore float32
// belongs to Hardware
HardwareID int
Hardware Hardware
// belongs to Benchmark
BenchmarkID int
Benchmark Benchmark

1853
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

36
package.json Normal file
View File

@ -0,0 +1,36 @@
{
"name": "blt",
"version": "0.1.0",
"description": "Self-hosted PC hardware benchmark logging tool",
"main": "index.js",
"scripts": {
"grunt": "grunt",
"nodemon": "nodemon"
},
"repository": {
"type": "git",
"url": "gitea@git.metaunix.net:BitGoblin/blt.git"
},
"keywords": [
"hardware",
"benchmark",
"testing",
"PC"
],
"author": "Gregory Ballanine <gballantine@bitgoblin.tech>",
"uploaders": [
{
"name": "Gregory Ballantine",
"email": "gballantine@bitgoblin.tech"
}
],
"license": "BSD-2-Clause",
"devDependencies": {
"grunt": "^1.5.3",
"grunt-cli": "^1.4.3",
"grunt-contrib-coffee": "^2.1.0",
"grunt-contrib-sass": "^2.0.0",
"grunt-contrib-watch": "^1.1.0",
"sass": "^1.55.0"
}
}

View File

@ -1,156 +0,0 @@
html,
body{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
body{
height: auto;
min-height: 100%;
box-sizing: border-box;
padding-top: 80px;
padding-bottom: 100px;
background: #eee;
}
a{
color: teal;
transition: color 180ms ease-in-out;
}
a:hover{
color: darkcyan;
}
button.button-primary{
background: teal;
transition: background 180ms ease-in-out;
}
button.button-primary:hover{
background: darkcyan;
}
textarea{
max-width: 100%;
min-width: 100%;
height: 100px;
}
form select[multiple]{
min-height: 100px;
}
table{
border: 1px solid #ddd;
border-radius: 8px;
border-spacing: 0;
overflow: hidden;
}
table th,
table td,
table th:first-child,
table td:first-child{
border: none;
padding: 7px 12px;
}
table thead tr{
border-radius: 8px 8px 0 0;
}
table tbody tr:last-child{
border-radius: 0 0 8px 8px;
}
table thead tr,
table tr:nth-child(even){
background: #eee;
}
/* 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{
max-width: 1200px;
}
#main-nav{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 64px;
background: teal;
color: white;
z-index: 20;
}
#main-nav ul{
list-style: none;
display: inline-block;
}
#main-nav h4{
display: inline-block;
margin-left: 25px;
line-height: 64px;
}
#main-nav ul li{
display: inline-block;
margin-left: 15px;
}
#main-nav a{
color: white;
font-size: 2.25rem;
line-height: 64px;
transition: all 200ms ease-in-out;
}
#main-nav a:hover{
color: #eee;
font-size: 2.5rem;
}
#main-content{
padding: 15px 25px;
background: white;
border-radius: 8px;
z-index: 10;
}
#main-footer{
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 64px;
}
#main-footer p{
margin-bottom: 5px;
text-align: center;
}

View File

@ -4,7 +4,7 @@
<h2>Benchmark</h2>
<a href="/benchmark/create">Add new benchmark</a>
<table class="twelve columns card-1">
<table class="twelve columns card-2">
<thead>
<tr>
<td>Name</td>

View File

@ -4,7 +4,7 @@
<h2>Hardware</h2>
<a href="/hardware/create">Add new hardware</a>
<table class="twelve columns card-1">
<table class="twelve columns card-2">
<thead>
<tr>
<td>Name</td>

View File

@ -12,7 +12,7 @@
{{ $length := len .hardware.Tests }} {{ if eq $length 0 }}
<p>There are currently no tests using this hardware component.</p>
{{ else }}
<table class="u-full-width card-1">
<table class="u-full-width card-2">
<thead>
<tr>
<th>Test</th>

View File

@ -9,6 +9,7 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="/css/kourend.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" charset="utf-8"></script>
<script src="/js/kebos.js" charset="utf-8"></script>
</head>
<body>

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" . }}

View File

@ -4,7 +4,7 @@
<h2>Tests</h2>
<a href="/test/create">Create a new test</a>
<table class="twelve columns card-1">
<table class="twelve columns card-2">
<thead>
<tr>
<td>Title</td>

View File

@ -3,7 +3,7 @@
<div class="row">
<h2>{{ .test.Name }}</h2>
<p><a href="/hardware/{{ .test.Hardware.ID }}">link to hardware tested.</a></p>
<p>Hardware tested: <a href="/hardware/{{ .test.Hardware.ID }}">{{ .test.Hardware.Name }}</a></p>
<p>{{ .test.Description }}</p>
@ -19,7 +19,7 @@
<h4>Add new result:</h4>
<form class="u-full-width" action="/result/add" method="POST">
<form id="result-form" class="u-full-width" action="/result/add" method="POST">
<div class="row">
<div class="columns four">
<label for="result_benchmark">
@ -35,21 +35,21 @@
<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">
<input id="result_avg" class="u-full-width" type="number" name="result_avg" step="0.01" placeholder="0.00">
</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">
<input id="result_min" class="u-full-width" type="number" name="result_min" step="0.01" placeholder="0.00">
</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">
<input id="result_max" class="u-full-width" type="number" name="result_max" step="0.01" placeholder="0.00">
</label>
</div>
@ -58,34 +58,30 @@
</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>Benchmark Results:</h4>
{{ $length := len .test.Results }} {{ if eq $length 0 }}
{{ $length := len .test.Benchmarks }} {{ if eq $length 0 }}
<p>There are currently no benchmarks recorded in this test.</p>
{{ else }}
<table class="u-full-width card-1">
<table id="results-table" class="u-full-width card-2" data-test-id="{{ .test.ID }}">
<thead>
<tr>
<th>Benchmark</th>
<th>Scoring Type</th>
<th># of Results</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>
{{ range $benchmark := .test.Benchmarks }}
<tr data-benchmark-id="{{ $benchmark.ID }}"></tr>
{{ end }}
</tbody>
</table>
@ -96,4 +92,6 @@
<p><a href="/test">Back</a></p>
</div>
<script src="/js/test.js"></script>
{{ template "footer" . }}

View File

@ -2,7 +2,6 @@ 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"`

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,11 +51,28 @@ 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
f.Group("/result", func() {
f.Post("/add", binding.Form(forms.ResultForm{}), routes.ResultPostCreate)
})
// API v1 routes
f.Group("/api", func () {
f.Group("/v1", func() {
f.Group("/benchmark", func() {
f.Get("/details", routes.ApiV1BenchmarkDetails)
})
f.Group("/result", func() {
f.Post("/add", binding.Form(forms.ResultForm{}), routes.ApiV1ResultAdd)
f.Get("/list", routes.ApiV1ResultList)
})
})
})
}

62
web/routes/api_v1.go Normal file
View File

@ -0,0 +1,62 @@
package routes
import (
"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 ApiV1BenchmarkDetails(c flamego.Context, r flamego.Render) {
// find benchmark ID from request
benchmarkID := c.Query("benchmark_id")
// find benchmark from DB
var benchmark models.Benchmark
models.DB.First(&benchmark, benchmarkID)
// return JSON response
r.JSON(200, benchmark)
}
func ApiV1ResultAdd(c flamego.Context, form forms.ResultForm, errs binding.Errors, r flamego.Render) {
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,
BenchmarkID: form.Benchmark,
AverageScore: form.AverageScore,
MinimumScore: form.MinimumScore,
MaximumScore: form.MaximumScore,
}
_ = models.DB.Create(&result)
r.JSON(200, "success")
}
func ApiV1ResultList(c flamego.Context, r flamego.Render) {
// find benchmark and test IDs from request
benchmarkID := c.Query("benchmark_id")
testID := c.Query("test_id")
// find results from the DB that match the benchmark and test
var results []models.Result
models.DB.Where("test_id = ? AND benchmark_id = ?", testID, benchmarkID).Find(&results)
// return JSON response
r.JSON(200, results)
}

View File

@ -26,7 +26,6 @@ func ResultPostCreate(c flamego.Context, form forms.ResultForm, errs binding.Err
result := models.Result{
TestID: form.Test,
HardwareID: form.Hardware,
BenchmarkID: form.Benchmark,
AverageScore: form.AverageScore,
MinimumScore: form.MinimumScore,

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))
}
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")
}