Added views and routes for benchmarks

This commit is contained in:
Gregory Ballantine 2023-11-27 00:42:42 -05:00
parent 2f016d3062
commit 34faecc52c
6 changed files with 138 additions and 1 deletions

View File

@ -36,6 +36,7 @@ app.use(express.static('public'));
const indexRoutes = require('./src/routes/index');
const projectRoutes = require('./src/routes/project');
const hardwareRoutes = require('./src/routes/hardware');
const benchmarkRoutes = require('./src/routes/benchmark');
// register routes
app.get('/', indexRoutes.getIndex);
@ -51,6 +52,12 @@ app.get('/hardware/list', hardwareRoutes.getList);
app.get('/hardware/add', hardwareRoutes.getAdd);
app.post('/hardware/add', hardwareRoutes.postAdd);
app.get('/hardware/:hardware_id', hardwareRoutes.getView);
// benchmark routes
app.get('/benchmark', benchmarkRoutes.getIndex);
app.get('/benchmark/list', benchmarkRoutes.getList);
app.get('/benchmark/add', benchmarkRoutes.getAdd);
app.post('/benchmark/add', benchmarkRoutes.postAdd);
app.get('/benchmark/:benchmark_id', benchmarkRoutes.getView);
app.listen(port, () => {
console.log(`Leviathan listening on port ${port}`);

42
src/routes/benchmark.js Normal file
View File

@ -0,0 +1,42 @@
const Benchmark = require('../models').models.Benchmark;
// GET /benchmark - redirects to benchmark list
exports.getIndex = async function(req, res) {
res.redirect('/benchmark/list');
};
// GET /benchmark/list - list of benchmarks
exports.getList = async function(req, res) {
var benchmarks = await Benchmark.findAll();
res.render('benchmark/list', {
benchmarks: benchmarks
});
};
// GET /benchmark/:benchmark_id - view information about a benchmark
exports.getView = async function(req, res) {
var benchmark = await Benchmark.findAll({
where: {
id: req.params.benchmark_id
}
});
res.render('benchmark/view', {
benchmark: benchmark[0]
});
};
// GET /benchmark/add - add a new benchmark
exports.getAdd = async function(req, res) {
res.render('benchmark/add');
};
// POST /benchmark/add - add the benchmark to the database
exports.postAdd = async function(req, res) {
var benchmark = await Benchmark.create({
name: req.body.benchmark_name,
scoring: req.body.benchmark_scoring,
description: req.body.benchmark_description
});
res.redirect('/benchmark');
};

40
views/benchmark/add.twig Normal file
View File

@ -0,0 +1,40 @@
{% extends 'layouts/default.twig' %}
{% block title %}Add a Benchmark{% endblock %}
{% block content %}
<div class="row">
<h2>Add a benchmark</h2>
<form class="twelve columns" action="/benchmark/add" method="POST">
<div class="row">
<div class="nine columns">
<label for="benchmark_name">
Benchmark name:
<input id="benchmark_name" class="u-full-width" type="text" name="benchmark_name" placeholder="My hardware benchmarking benchmark">
</label>
</div>
<div class="three columns">
<label for="benchmark_scoring">
Scoring type:
<select id="benchmark_scoring" class="u-full-width" name="benchmark_scoring">
<option value="fps">Frames per second</option>
<option value="pts">Total points</option>
<option value="time">Frame time</option>
</select>
</label>
</div>
</div>
<div class="row">
<label for="benchmark_description">
Benchmark description:
<textarea id="benchmark_description" class="twelve columns" cols="30" rows="10" name="benchmark_description"></textarea>
</label>
</div>
<input class="button-primary u-full-width" type="submit" value="Submit">
</form>
</div>
{% endblock %}

31
views/benchmark/list.twig Normal file
View File

@ -0,0 +1,31 @@
{% extends 'layouts/default.twig' %}
{% block title %}List of Benchmarks{% endblock %}
{% block content %}
<div class="row">
<h2>Benchmarks</h2>
<a href="/benchmark/add">Add a benchmark</a>
<table class="twelve columns">
<thead>
<tr>
<td>Benchmark name</td>
<td>Scoring type</td>
<td>Created at</td>
<td>Last updated</td>
</tr>
</thead>
<tbody>
{% for b in benchmarks %}
<tr>
<td><a href="/benchmark/{{ b.id }}">{{ b.name }}</a></td>
<td>{{ b.scoring }}</td>
<td>{{ b.createdAt | date('m/d/Y g:ia') }}</td>
<td>{{ b.updatedAt | date('m/d/Y g:ia') }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}

17
views/benchmark/view.twig Normal file
View File

@ -0,0 +1,17 @@
{% extends 'layouts/default.twig' %}
{% block title %}{{ benchmark.name }}{% endblock %}
{% block content %}
<div class="row">
<h2>{{ benchmark.name }}</h2>
<p>Scoring type: {{ benchmark.scoring }}</p>
<p>{{ benchmark.description }}</p>
<hr>
<p><a href="/benchmark">Back</a></p>
</div>
{% endblock %}

View File

@ -15,7 +15,7 @@
<tbody>
{% for p in projects %}
<tr>
<td>{{ p.title }}</td>
<td><a href="/project/{{ p.id }}">{{ p.title }}</a></td>
<td>{{ p.updatedAt | date('m/d/Y g:ia') }}</td>
</tr>
{% endfor %}