Compare commits
33 Commits
836d3ecc65
...
v0.1.4
Author | SHA1 | Date | |
---|---|---|---|
0cea6eb4ca | |||
d1268fe708 | |||
ff92316e1e | |||
629a7df3c4 | |||
30e23caf7f | |||
9afe8c5391 | |||
e958080702 | |||
6455f3ff10 | |||
1536c0721d | |||
64e71f7f98 | |||
3b36d33d09 | |||
50d83ea4b9 | |||
b24dab7b84 | |||
7685d2acd0 | |||
21b48b1f3c | |||
5e895aa3ca | |||
bfb8d751b8 | |||
cb5083d0d7 | |||
6c64e6c9a1 | |||
01149d8da7 | |||
5f00cf0edd | |||
6751d832fd | |||
4a0241dd2b | |||
1b46e7c3fb | |||
12770a995d | |||
182356c685 | |||
aa980948d8 | |||
3c0ebc7001 | |||
53e0a557a3 | |||
e5c7bdedc1 | |||
3369ab2873 | |||
91f72d4893 | |||
7c793dac88 |
14
.eslintrc.json
Normal file
14
.eslintrc.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"es2021": true,
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"extends": "google",
|
||||||
|
"overrides": [
|
||||||
|
],
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": "latest"
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
}
|
||||||
|
}
|
14
.gitignore
vendored
14
.gitignore
vendored
@ -1,8 +1,10 @@
|
|||||||
# ---> Composer
|
# NPM modules (mainly for Gulp.js)
|
||||||
composer.phar
|
node_modules/
|
||||||
/vendor/
|
|
||||||
|
|
||||||
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
|
# Compiled CSS and JS assets
|
||||||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
|
public/css/
|
||||||
# composer.lock
|
public/js/
|
||||||
|
|
||||||
|
# Local data storage
|
||||||
|
data/
|
||||||
|
|
||||||
|
62
.woodpecker.yml
Normal file
62
.woodpecker.yml
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
pipeline:
|
||||||
|
setup:
|
||||||
|
image: node:18
|
||||||
|
commands:
|
||||||
|
- npm install
|
||||||
|
- npm run grunt
|
||||||
|
|
||||||
|
lint:
|
||||||
|
image: node:18
|
||||||
|
commands:
|
||||||
|
- npm run lint
|
||||||
|
|
||||||
|
linux_package:
|
||||||
|
group: packaging
|
||||||
|
image: node:18
|
||||||
|
commands:
|
||||||
|
- npm run grunt package
|
||||||
|
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/*.deb"
|
||||||
|
when:
|
||||||
|
event: tag
|
||||||
|
|
||||||
|
copy_deb_package:
|
||||||
|
image: appleboy/drone-scp
|
||||||
|
settings:
|
||||||
|
host: "repo.int.metaunix.net"
|
||||||
|
username:
|
||||||
|
from_secret: repo_admin
|
||||||
|
password:
|
||||||
|
from_secret: repo_password
|
||||||
|
port: 22
|
||||||
|
target: /srv/repo/apt/overseer/
|
||||||
|
source: dist/*.deb
|
||||||
|
strip_components: 1
|
||||||
|
when:
|
||||||
|
event: tag
|
||||||
|
|
||||||
|
update_repos:
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
settings:
|
||||||
|
host:
|
||||||
|
- repo.int.metaunix.net
|
||||||
|
username:
|
||||||
|
from_secret: repo_admin
|
||||||
|
password:
|
||||||
|
from_secret: repo_password
|
||||||
|
port: 22
|
||||||
|
command_timeout: 2m
|
||||||
|
script:
|
||||||
|
- "sudo ~/scripts/update_repo.sh"
|
||||||
|
when:
|
||||||
|
event: tag
|
133
Gruntfile.js
Normal file
133
Gruntfile.js
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
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: ['**/*.scss'],
|
||||||
|
dest: 'public/css',
|
||||||
|
ext: '.css'
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
uglify: {
|
||||||
|
options: {
|
||||||
|
mangle: false
|
||||||
|
},
|
||||||
|
compile: {
|
||||||
|
files: {
|
||||||
|
'public/js/nechryael.min.js': ['assets/js/**/*.js']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
css: {
|
||||||
|
files: ['assets/styles/**/*.scss'],
|
||||||
|
tasks: ['sass'],
|
||||||
|
options: {
|
||||||
|
atBegin: true,
|
||||||
|
spawn: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
js: {
|
||||||
|
files: ['assets/js/**/*.js'],
|
||||||
|
tasks: ['uglify'],
|
||||||
|
options: {
|
||||||
|
atBegin: true,
|
||||||
|
spawn: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
deb_package: {
|
||||||
|
options: {
|
||||||
|
maintainer: 'Gregory Ballantine <gballantine@bitgoblin.tech>',
|
||||||
|
long_description: 'A simple web app to track inventory records.',
|
||||||
|
output: './dist/',
|
||||||
|
},
|
||||||
|
build: {
|
||||||
|
files: [
|
||||||
|
{
|
||||||
|
cwd: './',
|
||||||
|
src: 'index.js',
|
||||||
|
dest: '/opt/overseer'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cwd: './',
|
||||||
|
src: 'src/**/*',
|
||||||
|
dest: '/opt/overseer/'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cwd: './',
|
||||||
|
src: 'views/**/*',
|
||||||
|
dest: '/opt/overseer/'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cwd: './',
|
||||||
|
src: 'config/**/*',
|
||||||
|
dest: '/opt/overseer/'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cwd: './',
|
||||||
|
src: 'public/**/*',
|
||||||
|
dest: '/opt/overseer/'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cwd: './build/etc/',
|
||||||
|
src: 'default.json',
|
||||||
|
dest: '/etc/overseer/'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cwd: './build/etc/',
|
||||||
|
src: 'overseer.service',
|
||||||
|
dest: '/etc/systemd/system/'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cwd: './',
|
||||||
|
src: 'bin/**/*',
|
||||||
|
dest: '/opt/overseer/'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cwd: './',
|
||||||
|
src: 'node_modules/**/*',
|
||||||
|
dest: '/opt/overseer/'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cwd: './',
|
||||||
|
src: 'LICENSE',
|
||||||
|
dest: '/opt/overseer/',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
links: {
|
||||||
|
'/usr/bin/overseer': '/opt/overseer/bin/start.sh'
|
||||||
|
},
|
||||||
|
scripts: {
|
||||||
|
postinst: {
|
||||||
|
src: './build/scripts/postinst.sh'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Load plugins.
|
||||||
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
||||||
|
grunt.loadNpmTasks('grunt-contrib-sass');
|
||||||
|
grunt.loadNpmTasks('grunt-contrib-uglify');
|
||||||
|
grunt.loadNpmTasks('grunt-deb');
|
||||||
|
|
||||||
|
// CLI tasks.
|
||||||
|
grunt.registerTask('default', ['sass', 'uglify']);
|
||||||
|
grunt.registerTask('package', ['deb_package']);
|
||||||
|
|
||||||
|
};
|
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) <year> <owner>
|
Copyright (c) 2022 Bit Goblin
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
3
assets/js/nechryael.js
Normal file
3
assets/js/nechryael.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
$(document).ready(function() {
|
||||||
|
console.log('Document is ready!');
|
||||||
|
});
|
105
assets/styles/gargoyle.scss
Normal file
105
assets/styles/gargoyle.scss
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
$primary-color: orangered;
|
||||||
|
$primary-color-highlight: darken($primary-color, 10%);
|
||||||
|
$box-shadow-1: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
|
||||||
|
$box-shadow-2: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
|
||||||
|
|
||||||
|
$nav-bar-height: 60px;
|
||||||
|
|
||||||
|
body{
|
||||||
|
padding: $nav-bar-height 0 0;
|
||||||
|
background: lightgrey;
|
||||||
|
}
|
||||||
|
|
||||||
|
a{
|
||||||
|
color: $primary-color;
|
||||||
|
transition: all 230ms ease-in-out;
|
||||||
|
|
||||||
|
&:hover{
|
||||||
|
color: $primary-color-highlight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.button.button-primary,
|
||||||
|
button.button-primary,
|
||||||
|
input[type="button"].button-primary,
|
||||||
|
input[type="reset"].button-primary,
|
||||||
|
input[type="submit"].button-primary{
|
||||||
|
background-color: $primary-color;
|
||||||
|
color: white;
|
||||||
|
transition: all 230ms ease-in-out;
|
||||||
|
|
||||||
|
&:hover{
|
||||||
|
background-color: $primary-color-highlight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.container.fluid{
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-bar{
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: $nav-bar-height;
|
||||||
|
background: #212121;
|
||||||
|
box-shadow: $box-shadow-1;
|
||||||
|
color: white;
|
||||||
|
|
||||||
|
.nav-bar-left{
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul{
|
||||||
|
list-style: none;
|
||||||
|
|
||||||
|
li{
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.site-logo,
|
||||||
|
.nav-link a{
|
||||||
|
padding: 10px 12px;
|
||||||
|
font-size: 2.5rem;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.site-logo{
|
||||||
|
padding-left: 35px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#main-content{
|
||||||
|
margin-top: 25px;
|
||||||
|
padding: 20px 32px;
|
||||||
|
background: white;
|
||||||
|
box-shadow: $box-shadow-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
#record-actions{
|
||||||
|
p{
|
||||||
|
margin-bottom: 0;
|
||||||
|
font-size: 2rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#item-header{
|
||||||
|
margin-bottom: 25px;
|
||||||
|
|
||||||
|
h1,
|
||||||
|
p{
|
||||||
|
display: inline-block;
|
||||||
|
margin-bottom: 7px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-added-date,
|
||||||
|
.item-updated-date{
|
||||||
|
margin-bottom: 5px;
|
||||||
|
color: #666;
|
||||||
|
font-size: 1.6rem;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
}
|
5
bin/start.sh
Executable file
5
bin/start.sh
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
cd /opt/overseer/
|
||||||
|
|
||||||
|
/usr/bin/env node index.js
|
10
build/etc/default.json
Normal file
10
build/etc/default.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"server": {
|
||||||
|
"address": "0.0.0.0",
|
||||||
|
"port": 3000
|
||||||
|
},
|
||||||
|
"database": {
|
||||||
|
"driver": "sqlite",
|
||||||
|
"connection_string": "/opt/overseer/data/overseer.db"
|
||||||
|
}
|
||||||
|
}
|
12
build/etc/overseer.service
Normal file
12
build/etc/overseer.service
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Overseer inventory tracking app
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=overseer
|
||||||
|
Group=overseer
|
||||||
|
Environment="NODE_CONFIG_DIR=/etc/overseer"
|
||||||
|
ExecStart=/usr/bin/overseer
|
||||||
|
SuccessExitStatus=143
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
41
build/scripts/postinst.sh
Executable file
41
build/scripts/postinst.sh
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
GETENT_USER=$(getent passwd overseer)
|
||||||
|
GETENT_GROUP=$(getent group overseer)
|
||||||
|
|
||||||
|
# Create the overseer user if it doesn't already exist
|
||||||
|
if [ "$GETENT_USER" = "" ]; then
|
||||||
|
echo "Creating the 'overseer' user."
|
||||||
|
useradd -r overseer
|
||||||
|
else
|
||||||
|
echo "The 'overseer' user already exists, skipping creation."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create the overseer group if it doesn't already exist
|
||||||
|
if [ "$GETENT_GROUP" = "" ]; then
|
||||||
|
echo "Creating the 'overseer' group."
|
||||||
|
groupadd overseer
|
||||||
|
usermod -aG overseer overseer
|
||||||
|
else
|
||||||
|
echo "The 'overseer' group already exists, skipping creation."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Change the directory ownership of /etc
|
||||||
|
chown -R overseer:overseer /etc/overseer
|
||||||
|
|
||||||
|
# Create the log directory under /var/log
|
||||||
|
if [ ! -d /var/log/overseer ]; then
|
||||||
|
echo "Creating /var/log/overseer to store log files."
|
||||||
|
mkdir /var/log/overseer
|
||||||
|
chown overseer:overseer /var/log/overseer
|
||||||
|
else
|
||||||
|
echo "/var/log/overseer already exists, skipping creation."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Make sure the app's source and configuration files are owned the new user and group
|
||||||
|
chown -R overseer:overseer /opt/overseer
|
||||||
|
chown -R overseer:overseer /etc/overseer
|
||||||
|
|
||||||
|
#DEBHELPER#
|
||||||
|
|
||||||
|
exit 0
|
10
config/default.json
Normal file
10
config/default.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"server": {
|
||||||
|
"address": "0.0.0.0",
|
||||||
|
"port": 3000
|
||||||
|
},
|
||||||
|
"database": {
|
||||||
|
"driver": "sqlite",
|
||||||
|
"connection_string": "data/overseer.db"
|
||||||
|
}
|
||||||
|
}
|
0
data/.gitkeep
Normal file
0
data/.gitkeep
Normal file
55
index.js
Normal file
55
index.js
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const session = require('express-session');
|
||||||
|
// const flash = require('express-flasher');
|
||||||
|
|
||||||
|
// instantiate new express.js app
|
||||||
|
const app = express();
|
||||||
|
const config = require('config');
|
||||||
|
|
||||||
|
// initialize database connection
|
||||||
|
(async () => {
|
||||||
|
const db = require('./src/models');
|
||||||
|
await db.sequelize.sync({
|
||||||
|
alter: true,
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
||||||
|
// initialize express.js session
|
||||||
|
app.use(session({
|
||||||
|
resave: false, // don't save session if unmodified
|
||||||
|
saveUninitialized: false, // don't create session until something stored
|
||||||
|
secret: 'lord of the rings',
|
||||||
|
}));
|
||||||
|
|
||||||
|
// setup flash messaging
|
||||||
|
// app.use(flash.flash());
|
||||||
|
// app.use(flash.flashRead());
|
||||||
|
|
||||||
|
// set up body POST parameters
|
||||||
|
app.use(express.json());
|
||||||
|
app.use(express.urlencoded({
|
||||||
|
extended: true,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// load the template engine
|
||||||
|
app.set('view engine', 'twig');
|
||||||
|
|
||||||
|
// enable static file serving
|
||||||
|
app.use(express.static('public'));
|
||||||
|
|
||||||
|
// load route handlers
|
||||||
|
const homeRoutes = require('./src/routes/home');
|
||||||
|
const itemRoutes = require('./src/routes/item');
|
||||||
|
|
||||||
|
// register route handlers
|
||||||
|
app.get('/', homeRoutes.getIndex);
|
||||||
|
app.get('/item/add', itemRoutes.getAdd);
|
||||||
|
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);
|
||||||
|
|
||||||
|
// start app
|
||||||
|
app.listen(config.get('server.port'), config.get('server.address'), () => {
|
||||||
|
console.log(`Overseer is listening on port ${config.get('server.port')}.`);
|
||||||
|
});
|
9
nodemon.json
Normal file
9
nodemon.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"verbose": true,
|
||||||
|
"ext": "js,json,twig",
|
||||||
|
"ignore": [
|
||||||
|
"*.test.js",
|
||||||
|
"assets/",
|
||||||
|
"data/"
|
||||||
|
]
|
||||||
|
}
|
9801
package-lock.json
generated
Normal file
9801
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
49
package.json
Normal file
49
package.json
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
{
|
||||||
|
"name": "overseer",
|
||||||
|
"version": "0.1.4",
|
||||||
|
"description": "Self-hosted inventory tracker",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node index.js",
|
||||||
|
"grunt": "grunt",
|
||||||
|
"nodemon": "nodemon index.js",
|
||||||
|
"lint": "eslint index.js src/**/*.js",
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "gitea@git.metaunix.net:BitGoblin/overseer.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"inventory",
|
||||||
|
"tracking"
|
||||||
|
],
|
||||||
|
"author": "Gregory Ballanine <gballantine@bitgoblin.tech>",
|
||||||
|
"uploaders": [
|
||||||
|
{
|
||||||
|
"name": "Gregory Ballantine",
|
||||||
|
"email": "gballantine@bitgoblin.tech"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"license": "BSD-2-Clause",
|
||||||
|
"devDependencies": {
|
||||||
|
"eslint": "^8.26.0",
|
||||||
|
"eslint-config-google": "^0.14.0",
|
||||||
|
"grunt": "^1.5.3",
|
||||||
|
"grunt-cli": "^1.4.3",
|
||||||
|
"grunt-contrib-sass": "^2.0.0",
|
||||||
|
"grunt-contrib-uglify": "^5.2.2",
|
||||||
|
"grunt-contrib-watch": "^1.1.0",
|
||||||
|
"grunt-deb": "^0.2.5",
|
||||||
|
"nodemon": "^2.0.20",
|
||||||
|
"sass": "^1.55.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"config": "^3.3.8",
|
||||||
|
"express": "^4.18.2",
|
||||||
|
"express-session": "^1.17.3",
|
||||||
|
"sequelize": "^6.25.3",
|
||||||
|
"sqlite3": "^5.1.2",
|
||||||
|
"twig": "^1.15.4"
|
||||||
|
}
|
||||||
|
}
|
16
src/models/index.js
Normal file
16
src/models/index.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
const dbConfig = require('config').get('database');
|
||||||
|
const Sequelize = require('sequelize');
|
||||||
|
|
||||||
|
const sequelize = new Sequelize({
|
||||||
|
dialect: dbConfig.get('driver'),
|
||||||
|
storage: dbConfig.get('connection_string'),
|
||||||
|
});
|
||||||
|
|
||||||
|
const db = {};
|
||||||
|
|
||||||
|
db.Sequelize = Sequelize;
|
||||||
|
db.sequelize = sequelize;
|
||||||
|
|
||||||
|
db.items = require('./item.js')(sequelize, Sequelize);
|
||||||
|
|
||||||
|
module.exports = db;
|
35
src/models/item.js
Normal file
35
src/models/item.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
module.exports = (sequelize, Sequelize) => {
|
||||||
|
const Item = sequelize.define('item', {
|
||||||
|
|
||||||
|
name: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
|
||||||
|
manufacturer: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
|
||||||
|
serialNumber: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
|
||||||
|
skuNumber: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
|
||||||
|
type: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
|
||||||
|
purchasedFrom: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
|
||||||
|
purchasedAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return Item;
|
||||||
|
};
|
18
src/routes/home.js
Normal file
18
src/routes/home.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
const db = require('../models');
|
||||||
|
const Item = db.items;
|
||||||
|
|
||||||
|
// GET - /
|
||||||
|
exports.getIndex = async function(req, res) {
|
||||||
|
const items = await Item.findAll({
|
||||||
|
limit: 10,
|
||||||
|
order: [
|
||||||
|
['updatedAt', 'DESC'],
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
// req.flash('info', 'This is a test flash message.');
|
||||||
|
|
||||||
|
res.render('index.twig', {
|
||||||
|
inventory: items,
|
||||||
|
});
|
||||||
|
};
|
78
src/routes/item.js
Normal file
78
src/routes/item.js
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
const db = require('../models');
|
||||||
|
const Item = db.items;
|
||||||
|
|
||||||
|
// GET - /item/add
|
||||||
|
exports.getAdd = async function(req, res) {
|
||||||
|
res.render('item/add.twig');
|
||||||
|
};
|
||||||
|
|
||||||
|
// POST - /item/add
|
||||||
|
exports.postAdd = async function(req, res) {
|
||||||
|
const item = await Item.create({
|
||||||
|
name: req.body.item_name,
|
||||||
|
serialNumber: req.body.item_serial,
|
||||||
|
skuNumber: req.body.item_sku,
|
||||||
|
purchasedFrom: req.body.item_purchase_from,
|
||||||
|
purchasedAt: req.body.item_purchase_date,
|
||||||
|
manufacturer: req.body.item_manufacturer,
|
||||||
|
type: req.body.item_type,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Saved item ${item.name} to the database.`);
|
||||||
|
|
||||||
|
res.redirect('/');
|
||||||
|
};
|
||||||
|
|
||||||
|
// GET - /item/{id}
|
||||||
|
exports.getItem = async function(req, res) {
|
||||||
|
const item = await Item.findAll({
|
||||||
|
where: {
|
||||||
|
id: req.params.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
res.render('item/view.twig', {
|
||||||
|
item: item[0],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// GET - /item/{id}/edit
|
||||||
|
exports.getItemEdit = async function(req, res) {
|
||||||
|
const item = await Item.findAll({
|
||||||
|
where: {
|
||||||
|
id: req.params.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
res.render('item/edit.twig', {
|
||||||
|
item: item[0],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// POST - /item/{id}/edit
|
||||||
|
exports.postItemEdit = async function(req, res) {
|
||||||
|
// fetch item from DB
|
||||||
|
const itemSearch = await Item.findAll({
|
||||||
|
where: {
|
||||||
|
id: req.params.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// retrieve the item record from the array for ease of use
|
||||||
|
const item = itemSearch[0];
|
||||||
|
|
||||||
|
// update item attributes
|
||||||
|
item.name = req.body.item_name;
|
||||||
|
item.serialNumber = req.body.item_serial;
|
||||||
|
item.skuNumber = req.body.item_sku;
|
||||||
|
item.purchasedFrom = req.body.item_purchase_from;
|
||||||
|
item.purchasedAt = req.body.item_purchase_date;
|
||||||
|
item.manufacturer = req.body.item_manufacturer;
|
||||||
|
item.type = req.body.item_type;
|
||||||
|
|
||||||
|
// save attribute changes
|
||||||
|
await item.save();
|
||||||
|
|
||||||
|
// redirect user to item page
|
||||||
|
res.redirect('/item/' + item.id);
|
||||||
|
};
|
59
views/index.twig
Normal file
59
views/index.twig
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
{% extends 'layout.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Home{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<!-- page header -->
|
||||||
|
<header class="row">
|
||||||
|
<div class="columns twelve">
|
||||||
|
<h1>Welcome to Overseer!</h1>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section id="record-actions" class="row">
|
||||||
|
<div class="columns six">
|
||||||
|
<a href="/item/add">
|
||||||
|
<p><i class="fa-solid fa-plus"></i> Add Item</p>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="columns six">
|
||||||
|
<a href="/item/search">
|
||||||
|
<p><i class="fa-solid fa-search"></i> Search</p>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<section class="row">
|
||||||
|
<div class="columns twelve">
|
||||||
|
<h3>Recently updated records:</h3>
|
||||||
|
</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 %}
|
||||||
|
<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>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{% endblock %}
|
73
views/item/add.twig
Normal file
73
views/item/add.twig
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
{% extends 'layout.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Add New Item{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<!-- page header -->
|
||||||
|
<header class="row">
|
||||||
|
<div class="columns twelve">
|
||||||
|
<h1>Add new item</h1>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section class="row">
|
||||||
|
<div class="columns twelve">
|
||||||
|
<form action="/item/add" method="POST">
|
||||||
|
<div class="row">
|
||||||
|
<div class="columns twelve">
|
||||||
|
<label for="item_name">Item name:</label>
|
||||||
|
<input class="u-full-width" type="text" placeholder="My new item" id="item_name" name="item_name" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="six columns">
|
||||||
|
<label for="item_serial">Serial number:</label>
|
||||||
|
<input class="u-full-width" type="text" placeholder="0123456789" id="item_serial" name="item_serial">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="six columns">
|
||||||
|
<label for="item_sku">SKU number:</label>
|
||||||
|
<input class="u-full-width" type="text" placeholder="ABC12345678" id="item_sku" name="item_sku">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="six columns">
|
||||||
|
<label for="item_purchase_from">Purchased from:</label>
|
||||||
|
<input class="u-full-width" type="text" placeholder="Newegg" id="item_purchase_from" name="item_purchase_from">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="six columns">
|
||||||
|
<label for="item_purchase_date">Purchased at:</label>
|
||||||
|
<input class="u-full-width" type="datetime-local" id="item_purchase_date" name="item_purchase_date">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="six columns">
|
||||||
|
<label for="item_manufacturer">Manufacturer:</label>
|
||||||
|
<input class="u-full-width" type="text" placeholder="Manufacturer" id="item_manufacturer" name="item_manufacturer">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="six columns">
|
||||||
|
<label for="item_type">Item type</label>
|
||||||
|
<select class="u-full-width" id="item_type" name="item_type">
|
||||||
|
<option value="cpu">Processor</option>
|
||||||
|
<option value="motherboard">Motherboard</option>
|
||||||
|
<option value="memory">Memory (RAM)</option>
|
||||||
|
<option value="psu">Power Supply</option>
|
||||||
|
<option value="case">Case</option>
|
||||||
|
<option value="storage">Storage Device</option>
|
||||||
|
<option value="gpu">Graphics Card</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input class="button-primary u-full-width" type="submit" value="Submit">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{% endblock %}
|
73
views/item/edit.twig
Normal file
73
views/item/edit.twig
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
{% extends 'layout.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Edit Item{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<!-- page header -->
|
||||||
|
<header class="row">
|
||||||
|
<div class="columns twelve">
|
||||||
|
<h1>Editing "{{ item.name }}"</h1>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section class="row">
|
||||||
|
<div class="columns twelve">
|
||||||
|
<form action="/item/{{ item.id }}/edit" method="POST">
|
||||||
|
<div class="row">
|
||||||
|
<div class="columns twelve">
|
||||||
|
<label for="item_name">Item name:</label>
|
||||||
|
<input class="u-full-width" type="text" placeholder="My new item" id="item_name" name="item_name" value="{{ item.name }}" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="six columns">
|
||||||
|
<label for="item_serial">Serial number:</label>
|
||||||
|
<input class="u-full-width" type="text" placeholder="0123456789" id="item_serial" name="item_serial" value="{{ item.serialNumber }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="six columns">
|
||||||
|
<label for="item_sku">SKU number:</label>
|
||||||
|
<input class="u-full-width" type="text" placeholder="ABC12345678" id="item_sku" name="item_sku" value="{{ item.skuNumber }}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="six columns">
|
||||||
|
<label for="item_purchase_from">Purchased from:</label>
|
||||||
|
<input class="u-full-width" type="text" placeholder="Newegg" id="item_purchase_from" name="item_purchase_from" value="{{ item.purchasedFrom }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="six columns">
|
||||||
|
<label for="item_purchase_date">Purchased at:</label>
|
||||||
|
<input class="u-full-width" type="datetime-local" id="item_purchase_date" name="item_purchase_date" value="{{ item.purchasedAt }}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="six columns">
|
||||||
|
<label for="item_manufacturer">Manufacturer:</label>
|
||||||
|
<input class="u-full-width" type="text" placeholder="Manufacturer" id="item_manufacturer" name="item_manufacturer" value="{{ item.manufacturer }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="six columns">
|
||||||
|
<label for="item_type">Item type</label>
|
||||||
|
<select class="u-full-width" id="item_type" name="item_type" value="{{ item.type }}">
|
||||||
|
<option value="cpu">Processor</option>
|
||||||
|
<option value="motherboard">Motherboard</option>
|
||||||
|
<option value="memory">Memory (RAM)</option>
|
||||||
|
<option value="psu">Power Supply</option>
|
||||||
|
<option value="case">Case</option>
|
||||||
|
<option value="storage">Storage Device</option>
|
||||||
|
<option value="gpu">Graphics Card</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input class="button-primary u-full-width" type="submit" value="Submit">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{% endblock %}
|
47
views/item/view.twig
Normal file
47
views/item/view.twig
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
{% extends 'layout.twig' %}
|
||||||
|
|
||||||
|
{% block title %}{{ item.name }}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<!-- page header -->
|
||||||
|
<header id="item-header" class="row">
|
||||||
|
<div class="columns twelve">
|
||||||
|
<span>
|
||||||
|
<h1>{{ item.name }}</h1>
|
||||||
|
<p><a href="/item/{{ item.id }}/edit"><i class="fa-solid fa-pen-to-square"></i> Edit</a></p>
|
||||||
|
</span>
|
||||||
|
<h4 class="item-added-date">Item added at: {{ item.createdAt }}</h4>
|
||||||
|
<h4 class="item-updated-date">Last updated at: {{ item.updatedAt }}</h4>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<!-- item information -->
|
||||||
|
<section class="row">
|
||||||
|
<table class="columns twelve">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Product name</th>
|
||||||
|
<th>Serial number</th>
|
||||||
|
<th>SKU Number</th>
|
||||||
|
<th>Manufacturer</th>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Seller</th>
|
||||||
|
<th>Purchase date</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>{{ item.name }}</td>
|
||||||
|
<td>{{ item.serialNumber ? item.serialNumber : 'N/a' }}</td>
|
||||||
|
<td>{{ item.skuNumber ? item.skuNumber : 'N/a' }}</td>
|
||||||
|
<td>{{ item.manufacturer ? item.manufacturer : 'N/a' }}</td>
|
||||||
|
<td>{{ item.type }}</td>
|
||||||
|
<td>{{ item.purchasedFrom ? item.purchasedFrom : 'N/a' }}</td>
|
||||||
|
<td>{{ item.purchasedAt | date("m/d/Y h:i:s A") }}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{% endblock %}
|
38
views/layout.twig
Normal file
38
views/layout.twig
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>{% block title %}{% endblock %} | Overseer</title>
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css">
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
|
||||||
|
<link rel="stylesheet" href="/css/gargoyle.css">
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
|
||||||
|
<script src="/js/nechryael.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- global navigation -->
|
||||||
|
<nav id="nav-bar">
|
||||||
|
<div class="nav-bar-left">
|
||||||
|
<ul>
|
||||||
|
<li class="site-logo">Overseer</li>
|
||||||
|
<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>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
{% if flash != null %}
|
||||||
|
<div class="flash-message {{ flash.type }}">
|
||||||
|
<p>{{ flash.msg }}</p>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- main content -->
|
||||||
|
<div id="main-content" class="container fluid">
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user