5 Commits

Author SHA1 Message Date
6db18f63d6 Version bump to v0.2.2
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-11-09 14:34:30 -05:00
e33b23d88e Updated some styles on the home page
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-11-09 14:33:58 -05:00
c86546af82 Version bump to v0.2.1
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2022-11-06 11:41:14 -05:00
6c046dde81 Added license view and edit functions
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-11-06 11:40:45 -05:00
4167130f0c Started work on adding license tracking
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-11-06 01:37:56 -05:00
14 changed files with 323 additions and 24 deletions

View File

@ -34,7 +34,10 @@ input[type="submit"].button-primary{
}
.container.fluid{
width: calc(100% - 60px);
max-width: 100%;
margin-left: 30px;
margin-right: 30px;
}
#nav-bar{
@ -86,7 +89,8 @@ input[type="submit"].button-primary{
}
}
#item-header{
#item-header,
#license-header{
margin-bottom: 25px;
h1,
@ -96,7 +100,9 @@ input[type="submit"].button-primary{
}
.item-added-date,
.item-updated-date{
.item-updated-date,
.license-added-date,
.license-updated-date{
margin-bottom: 5px;
color: #666;
font-size: 1.6rem;

View File

@ -36,6 +36,9 @@ fi
chown -R overseer:overseer /opt/overseer
chown -R overseer:overseer /etc/overseer
# Reload systemd unit files
systemctl daemon-reload
#DEBHELPER#
exit 0

View File

@ -47,6 +47,7 @@ app.use(express.static('public'));
// load route handlers
const homeRoutes = require('./src/routes/home');
const itemRoutes = require('./src/routes/item');
const licenseRoutes = require('./src/routes/license');
// register route handlers
app.get('/', homeRoutes.getIndex);
@ -55,6 +56,11 @@ app.post('/item/add', itemRoutes.postAdd);
app.get('/item/:id', itemRoutes.getItem);
app.get('/item/:id/edit', itemRoutes.getItemEdit);
app.post('/item/:id/edit', itemRoutes.postItemEdit);
app.get('/license/add', licenseRoutes.getAdd);
app.post('/license/add', licenseRoutes.postAdd);
app.get('/license/:id', licenseRoutes.getLicense);
app.get('/license/:id/edit', licenseRoutes.getEdit);
app.post('/license/:id/edit', licenseRoutes.postEdit);
// start app
app.listen(config.get('server.port'), config.get('server.address'), () => {

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "overseer",
"version": "0.2.0",
"version": "0.2.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "overseer",
"version": "0.2.0",
"version": "0.2.2",
"license": "BSD-2-Clause",
"dependencies": {
"config": "^3.3.8",

View File

@ -1,6 +1,6 @@
{
"name": "overseer",
"version": "0.2.0",
"version": "0.2.2",
"description": "Self-hosted inventory tracker",
"main": "index.js",
"scripts": {

View File

@ -9,6 +9,7 @@ db.Sequelize = Sequelize;
db.sequelize = sequelize;
db.items = require('./item.js')(sequelize, Sequelize);
db.licenses = require('./license.js')(sequelize, Sequelize);
module.exports = db;

27
src/models/license.js Normal file
View File

@ -0,0 +1,27 @@
module.exports = (sequelize, Sequelize) => {
const License = sequelize.define('license', {
name: {
type: Sequelize.STRING,
},
key: {
type: Sequelize.STRING,
},
manufacturer: {
type: Sequelize.STRING,
},
purchasedFrom: {
type: Sequelize.STRING,
},
purchasedAt: {
type: Sequelize.DATE,
},
});
return License;
};

View File

@ -1,8 +1,10 @@
const db = require('../models');
const Item = db.items;
const License = db.licenses;
// GET - /
exports.getIndex = async function(req, res) {
// fetch inventory items from database
const items = await Item.findAll({
limit: 10,
order: [
@ -10,9 +12,18 @@ exports.getIndex = async function(req, res) {
],
});
// fetch licenses from database
const licenses = await License.findAll({
limit: 10,
order: [
['updatedAt', 'DESC'],
],
});
// req.flash('info', 'This is a test flash message.');
res.render('index.twig', {
inventory: items,
licenses: licenses,
});
};

74
src/routes/license.js Normal file
View File

@ -0,0 +1,74 @@
const db = require('../models');
const License = db.licenses;
// GET - /license/add
exports.getAdd = async function(req, res) {
res.render('license/add.twig');
};
// POST - /license/add
exports.postAdd = async function(req, res) {
const license = await License.create({
name: req.body.license_name,
key: req.body.license_key,
manufacturer: req.body.license_manufacturer,
purchasedFrom: req.body.license_purchase_from,
purchasedAt: req.body.license_purchase_date,
});
console.log(`Saved license ${license.name} to the database.`);
res.redirect('/');
};
// GET - /license/{id}
exports.getLicense = async function(req, res) {
const license = await License.findAll({
where: {
id: req.params.id,
},
});
res.render('license/view.twig', {
license: license[0],
});
};
// GET - /license/{id}/edit
exports.getEdit = async function(req, res) {
const license = await License.findAll({
where: {
id: req.params.id,
},
});
res.render('license/edit.twig', {
license: license[0],
});
};
// POST - /license/{id}/edit
exports.postEdit = async function(req, res) {
// fetch license from DB
const licenseSearch = await License.findAll({
where: {
id: req.params.id,
},
});
// retrieve the license record from the array for ease of use
const license = licenseSearch[0];
// update license attributes
license.name = req.body.license_name;
license.key = req.body.license_key;
license.manufacturer = req.body.license_manufacturer;
license.purchasedFrom = req.body.license_purchase_from;
license.purchasedAt = req.body.license_purchase_date;
// save attribute changes
await license.save();
// redirect user to license page
res.redirect('/license/' + license.id);
};

View File

@ -29,31 +29,52 @@
<section class="row">
<div class="columns twelve">
<h3>Recently updated records:</h3>
<h3>Recently updated hardware:</h3>
<table class="u-full-width">
<thead>
<tr>
<th>Name</th>
<th>Manufacturer</th>
<th>Type</th>
<th>Updated at</th>
</tr>
</thead>
<tbody>
{% for item in inventory %}
<tr>
<td><a href="/item/{{ item.id }}">{{ item.name }}</a></td>
<td>{{ item.manufacturer }}</td>
<td>{{ item.type }}</td>
<td>{{ item.updatedAt | date("m/d/Y h:i:s A") }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</section>
<section class="row">
<table class="columns twelve">
<thead>
<tr>
<th>Name</th>
<th>Manufacturer</th>
<th>Type</th>
<th>Updated at</th>
</tr>
</thead>
<tbody>
{% for item in inventory %}
<div class="columns twelve">
<h3>Recently updated licenses:</h3>
<table class="u-full-width">
<thead>
<tr>
<td><a href="/item/{{ item.id }}">{{ item.name }}</a></td>
<td>{{ item.manufacturer }}</td>
<td>{{ item.type }}</td>
<td>{{ item.updatedAt | date("m/d/Y h:i:s A") }}</td>
<th>Name</th>
<th>Manufacturer</th>
<th>Updated at</th>
</tr>
{% endfor %}
</tbody>
</table>
</thead>
<tbody>
{% for license in licenses %}
<tr>
<td><a href="/license/{{ license.id }}">{{ license.name }}</a></td>
<td>{{ license.manufacturer }}</td>
<td>{{ license.updatedAt | date("m/d/Y h:i:s A") }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</section>
{% endblock %}

View File

@ -20,6 +20,7 @@
<li class="nav-link"><a href="/">Home</a></li>
<li class="nav-link"><a href="/item/search">Search</a></li>
<li class="nav-link"><a href="/item/add">Add Item</a></li>
<li class="nav-link"><a href="/license/add">Add License</a></li>
</ul>
</div>
</nav>

53
views/license/add.twig Normal file
View File

@ -0,0 +1,53 @@
{% extends 'layout.twig' %}
{% block title %}Add New License{% endblock %}
{% block content %}
<!-- page header -->
<header class="row">
<div class="columns twelve">
<h1>Add new license</h1>
</div>
</header>
<section class="row">
<div class="columns twelve">
<form action="/license/add" method="POST">
<div class="row">
<div class="columns twelve">
<label for="license_name">License name:</label>
<input class="u-full-width" type="text" placeholder="My new license" id="license_name" name="license_name" required>
</div>
</div>
<div class="row">
<div class="six columns">
<label for="license_key">License Key:</label>
<input class="u-full-width" type="text" placeholder="ABCD-EFGH-1234-5678" id="license_key" name="license_key" required>
</div>
<div class="six columns">
<label for="license_manufacturer">Manufacturer:</label>
<input class="u-full-width" type="text" placeholder="Manufacturer" id="license_manufacturer" name="license_manufacturer">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="license_purchase_from">Purchased from:</label>
<input class="u-full-width" type="text" placeholder="Newegg" id="license_purchase_from" name="license_purchase_from">
</div>
<div class="six columns">
<label for="license_purchase_date">Purchased at:</label>
<input class="u-full-width" type="datetime-local" id="license_purchase_date" name="license_purchase_date">
</div>
</div>
<input class="button-primary u-full-width" type="submit" value="Submit">
</form>
</div>
</section>
{% endblock %}

53
views/license/edit.twig Normal file
View File

@ -0,0 +1,53 @@
{% extends 'layout.twig' %}
{% block title %}Edit License{% endblock %}
{% block content %}
<!-- page header -->
<header class="row">
<div class="columns twelve">
<h1>Editing "{{ license.name }}"</h1>
</div>
</header>
<section class="row">
<div class="columns twelve">
<form action="/license/{{ license.id }}/edit" method="POST">
<div class="row">
<div class="columns twelve">
<label for="license_name">License name:</label>
<input class="u-full-width" type="text" placeholder="My new license" id="license_name" name="license_name" value="{{ license.name }}" required>
</div>
</div>
<div class="row">
<div class="six columns">
<label for="license_key">License key:</label>
<input class="u-full-width" type="text" placeholder="ABCD-EFGH-1234-5678" id="license_key" name="license_key" value="{{ license.key }}" required>
</div>
<div class="six columns">
<label for="license_manufacturer">Manufacturer:</label>
<input class="u-full-width" type="text" placeholder="Manufacturer" id="license_manufacturer" name="license_manufacturer" value="{{ license.manufacturer }}">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="license_purchase_from">Purchased from:</label>
<input class="u-full-width" type="text" placeholder="Newegg" id="license_purchase_from" name="license_purchase_from" value="{{ license.purchasedFrom }}">
</div>
<div class="six columns">
<label for="license_purchase_date">Purchased at:</label>
<input class="u-full-width" type="datetime-local" id="license_purchase_date" name="license_purchase_date" value="{{ license.purchasedAt }}">
</div>
</div>
<input class="button-primary u-full-width" type="submit" value="Submit">
</form>
</div>
</section>
{% endblock %}

43
views/license/view.twig Normal file
View File

@ -0,0 +1,43 @@
{% extends 'layout.twig' %}
{% block title %}{{ license.name }}{% endblock %}
{% block content %}
<!-- page header -->
<header id="license-header" class="row">
<div class="columns twelve">
<span>
<h1>{{ license.name }}</h1>
<p><a href="/license/{{ license.id }}/edit"><i class="fa-solid fa-pen-to-square"></i> Edit</a></p>
</span>
<h4 class="license-added-date">license added at: {{ license.createdAt }}</h4>
<h4 class="license-updated-date">Last updated at: {{ license.updatedAt }}</h4>
</div>
</header>
<!-- license information -->
<section class="row">
<table class="columns twelve">
<thead>
<tr>
<th>Product name</th>
<th>License Key</th>
<th>Manufacturer</th>
<th>Seller</th>
<th>Purchase date</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ license.name }}</td>
<td>{{ license.key ? license.key : 'N/a' }}</td>
<td>{{ license.manufacturer ? license.manufacturer : 'N/a' }}</td>
<td>{{ license.purchasedFrom ? license.purchasedFrom : 'N/a' }}</td>
<td>{{ license.purchasedAt | date("m/d/Y h:i:s A") }}</td>
</tr>
</tbody>
</table>
</section>
{% endblock %}