Added benchmark and hardware models; added routes and views for hardware
This commit is contained in:
parent
e5602e660d
commit
2f016d3062
10
index.js
10
index.js
@ -35,14 +35,22 @@ app.use(express.static('public'));
|
||||
// load routes
|
||||
const indexRoutes = require('./src/routes/index');
|
||||
const projectRoutes = require('./src/routes/project');
|
||||
const hardwareRoutes = require('./src/routes/hardware');
|
||||
|
||||
// register routes
|
||||
app.get('/', indexRoutes.getIndex);
|
||||
// project routes
|
||||
app.get('/project', projectRoutes.getIndex);
|
||||
app.get('/project/list', projectRoutes.getList);
|
||||
app.get('/project/:project_id', projectRoutes.getView);
|
||||
app.get('/project/add', projectRoutes.getAdd);
|
||||
app.post('/project/add', projectRoutes.postAdd);
|
||||
app.get('/project/:project_id', projectRoutes.getView);
|
||||
// hardware routes
|
||||
app.get('/hardware', hardwareRoutes.getIndex);
|
||||
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);
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Leviathan listening on port ${port}`);
|
||||
|
@ -7,6 +7,9 @@ body{
|
||||
}
|
||||
|
||||
body{
|
||||
height: auto;
|
||||
min-height: 100%;
|
||||
box-sizing: border-box;
|
||||
padding-top: 80px;
|
||||
padding-bottom: 80px;
|
||||
background: #eee;
|
||||
@ -30,6 +33,7 @@ textarea{
|
||||
height: 64px;
|
||||
background: teal;
|
||||
color: white;
|
||||
z-index: 20;
|
||||
}
|
||||
|
||||
#main-nav ul{
|
||||
@ -61,6 +65,7 @@ textarea{
|
||||
padding: 14px 20px;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
#main-footer{
|
||||
@ -69,6 +74,7 @@ textarea{
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 64px;
|
||||
|
||||
}
|
||||
|
||||
#main-footer p{
|
||||
|
21
src/models/benchmark.js
Normal file
21
src/models/benchmark.js
Normal file
@ -0,0 +1,21 @@
|
||||
const { Sequelize } = require("sequelize");
|
||||
|
||||
module.exports = (sequelize) => {
|
||||
const Benchmark = sequelize.define('Benchmark', {
|
||||
name: {
|
||||
type: Sequelize.STRING,
|
||||
null: false,
|
||||
},
|
||||
description: {
|
||||
type: Sequelize.TEXT,
|
||||
},
|
||||
scoring: {
|
||||
type: Sequelize.STRING,
|
||||
null: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
tableName: 'benchmarks'
|
||||
});
|
||||
return Benchmark;
|
||||
};
|
18
src/models/hardware.js
Normal file
18
src/models/hardware.js
Normal file
@ -0,0 +1,18 @@
|
||||
const { Sequelize } = require("sequelize");
|
||||
|
||||
module.exports = (sequelize) => {
|
||||
const Hardware = sequelize.define('Hardware', {
|
||||
name: {
|
||||
type: Sequelize.STRING,
|
||||
null: false,
|
||||
},
|
||||
type: {
|
||||
type: Sequelize.STRING,
|
||||
null: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
tableName: 'hardware'
|
||||
});
|
||||
return Hardware;
|
||||
};
|
@ -6,5 +6,7 @@ const sequelize = new Sequelize({
|
||||
});
|
||||
|
||||
const Project = require('./project')(sequelize);
|
||||
const Hardware = require('./hardware')(sequelize);
|
||||
const Benchmark = require('./benchmark')(sequelize);
|
||||
|
||||
module.exports = sequelize;
|
||||
|
@ -10,6 +10,8 @@ module.exports = (sequelize) => {
|
||||
type: Sequelize.TEXT,
|
||||
},
|
||||
},
|
||||
{});
|
||||
{
|
||||
tableName: 'projects'
|
||||
});
|
||||
return Project;
|
||||
};
|
||||
|
41
src/routes/hardware.js
Normal file
41
src/routes/hardware.js
Normal file
@ -0,0 +1,41 @@
|
||||
const Hardware = require('../models').models.Hardware;
|
||||
|
||||
// GET /hardware - redirects to project list
|
||||
exports.getIndex = async function(req, res) {
|
||||
res.redirect('/hardware/list');
|
||||
};
|
||||
|
||||
// GET /hardware/list - list of hardware
|
||||
exports.getList = async function(req, res) {
|
||||
var hardware = await Hardware.findAll();
|
||||
res.render('hardware/list', {
|
||||
hardware: hardware
|
||||
});
|
||||
};
|
||||
|
||||
// GET /hardware/:hardware_id - view information about a piece of hardware
|
||||
exports.getView = async function(req, res) {
|
||||
var hardware = await Hardware.findAll({
|
||||
where: {
|
||||
id: req.params.hardware_id
|
||||
}
|
||||
});
|
||||
res.render('hardware/view', {
|
||||
hardware: hardware[0]
|
||||
});
|
||||
};
|
||||
|
||||
// GET /hardware/add - add a new hardware
|
||||
exports.getAdd = async function(req, res) {
|
||||
res.render('hardware/add');
|
||||
};
|
||||
|
||||
// POST /hardware/add - add the hardware to the database
|
||||
exports.postAdd = async function(req, res) {
|
||||
var hardware = await Hardware.create({
|
||||
name: req.body.hardware_name,
|
||||
type: req.body.hardware_type
|
||||
});
|
||||
|
||||
res.redirect('/hardware');
|
||||
};
|
35
views/hardware/add.twig
Normal file
35
views/hardware/add.twig
Normal file
@ -0,0 +1,35 @@
|
||||
{% extends 'layouts/default.twig' %}
|
||||
|
||||
{% block title %}Add Hardware{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<h2>Add hardware</h2>
|
||||
|
||||
<form class="twelve columns" action="/hardware/add" method="POST">
|
||||
<div class="row">
|
||||
<div class="nine columns">
|
||||
<label for="hardware_name">
|
||||
Hardware name:
|
||||
<input id="hardware_name" class="u-full-width" type="text" name="hardware_name" placeholder="EVGA RTX 3080 Ti">
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="three columns">
|
||||
<label for="hardware_type">
|
||||
Hardware type:
|
||||
<select id="hardware_type" class="u-full-width" name="hardware_type">
|
||||
<option value="cpu">Processor</option>
|
||||
<option value="mem">Memory</option>
|
||||
<option value="gpu">Graphics card</option>
|
||||
<option value="ssd">SSD</option>
|
||||
<option value="hdd">HDD</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input class="button-primary u-full-width" type="submit" value="Submit">
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
31
views/hardware/list.twig
Normal file
31
views/hardware/list.twig
Normal file
@ -0,0 +1,31 @@
|
||||
{% extends 'layouts/default.twig' %}
|
||||
|
||||
{% block title %}List of Hardware{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<h2>Hardware</h2>
|
||||
<a href="/hardware/add">Add new hardware</a>
|
||||
|
||||
<table class="twelve columns">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Name</td>
|
||||
<td>Type</td>
|
||||
<td>Created at</td>
|
||||
<td>Last updated</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for h in hardware %}
|
||||
<tr>
|
||||
<td><a href="/hardware/{{ h.id }}">{{ h.name }}</a></td>
|
||||
<td>{{ h.type }}</td>
|
||||
<td>{{ p.createdAt | date('m/d/Y g:ia') }}</td>
|
||||
<td>{{ p.updatedAt | date('m/d/Y g:ia') }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endblock %}
|
15
views/hardware/view.twig
Normal file
15
views/hardware/view.twig
Normal file
@ -0,0 +1,15 @@
|
||||
{% extends 'layouts/default.twig' %}
|
||||
|
||||
{% block title %}{{ hardware.name }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<h2>{{ hardware.name }}</h2>
|
||||
|
||||
<p>Hardware type: {{ hardware.type }}</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p><a href="/hardware">Back</a></p>
|
||||
</div>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user