parent
10ad412382
commit
70333d72c8
|
@ -1,4 +1,4 @@
|
|||
// Forces NodeJS to disable "Silent errors", in other words, don't
|
||||
// Forces NodeJS to disable "Silent errors"
|
||||
'use strict';
|
||||
|
||||
// Import things
|
||||
|
@ -14,8 +14,8 @@ var site;
|
|||
// TODO: Add stuff for MySQL
|
||||
|
||||
var connection = mysql.createConnection({
|
||||
host : '127.0.0.1',
|
||||
user : 'demo',
|
||||
host : '192.168.0.56',
|
||||
user : 'mangosdemo',
|
||||
password : 'lqklvok',
|
||||
database : 'mangoshelfdb'
|
||||
});
|
||||
|
@ -24,7 +24,7 @@ var connection = mysql.createConnection({
|
|||
connection.query('SELECT * FROM stock', function (error, results, fields) {
|
||||
if (error) throw error;
|
||||
// connected!
|
||||
console.log(results);
|
||||
console.log('MySQL connected!');
|
||||
});
|
||||
|
||||
// Set the templates folder for the thingy
|
||||
|
@ -38,9 +38,7 @@ app.use(express.static(__dirname + '/../Public'));
|
|||
|
||||
// Main page
|
||||
app.get('/', function(req, res){
|
||||
console.log('🌐 Client requested ' + req.url);
|
||||
res.render('index', { results, site: 1 });
|
||||
console.log('✅ Client recieved ' + req.url);
|
||||
res.redirect('/stock')
|
||||
// console.log(test.cars.Nissan[1].model)
|
||||
});
|
||||
|
||||
|
@ -49,17 +47,16 @@ app.get('/stock', function(req, res){
|
|||
connection.query('SELECT * FROM stock', function (error, results, fields) {
|
||||
if (error) throw error;
|
||||
// connected!
|
||||
console.log(results);
|
||||
//console.log(results);
|
||||
res.render('index', { results, site: 2 });
|
||||
console.log('✅ Client recieved ' + req.url);
|
||||
});
|
||||
// console.log(test.cars.Nissan[1].model)
|
||||
});
|
||||
|
||||
app.get('/subbb', function(req, res){
|
||||
app.get('/stock/new', function(req, res){
|
||||
var results = null;
|
||||
console.log('🌐 Client requested ' + req.url);
|
||||
res.render('additem');
|
||||
console.log('✅ Client recieved ' + req.url);
|
||||
res.render('index', { results, site: 21 });
|
||||
// console.log(test.cars.Nissan[1].model)
|
||||
});
|
||||
|
||||
|
@ -73,16 +70,33 @@ app.post('/api/live/inventory/add', function(req, res){
|
|||
let orderid = req.body.orderid;
|
||||
let notes = req.body.notes;
|
||||
console.log('🌐 Client requested ' + req.url + ' with id ' + req.params.id);
|
||||
res.render('index', { test, site: 1 });
|
||||
console.log('✅ Client recieved ' + req.url);
|
||||
|
||||
connection.query("INSERT INTO `stock` (`name`, `description`, `status`, `category`, `amount`, `location`, `expiry`, `lastupdate`, `orderid`, `notes`) VALUES (${name}, '${desc}', ${status}, ${category}, ${amount}, ${location}, NULL, ${Date.now()}, ${orderid}, '${notes}');", function(error) {if (error){throw error;}})
|
||||
var sql = "INSERT INTO stock (name, description, status, category, amount, location, orderid, notes) VALUES (?)";
|
||||
var values = [name, desc, status, category, amount, location, orderid, notes];
|
||||
connection.query(sql, [values], function (err, result) {
|
||||
if (err) throw err;
|
||||
console.log("Number of records inserted: " + result.affectedRows);
|
||||
res.redirect('/stock');
|
||||
});
|
||||
if (name && desc && status && category && amount && location && orderid && notes) {
|
||||
console.log('boop!');
|
||||
}
|
||||
// console.log(test.cars.Nissan[1].model)
|
||||
});
|
||||
|
||||
app.get('/api/live/inventory/delete/:thinGid', function(req, res){
|
||||
var idtodelete = req.params.thinGid;
|
||||
console.log(idtodelete);
|
||||
var sql = "DELETE FROM stock WHERE id = ?";
|
||||
var values = [idtodelete];
|
||||
connection.query(sql, [values], function (err, result) {
|
||||
if (err) throw err;
|
||||
console.log("Number of records inserted: " + result.affectedRows);
|
||||
res.redirect('/stock');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Simple way to expose a function
|
||||
exports = module.exports = rws;
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Use node as the "base" for our project
|
||||
FROM node:17
|
||||
# Create app directory
|
||||
WORKDIR /usr/src/app
|
||||
# Enviroment variables
|
||||
# (https://docs.docker.com/engine/reference/builder/ go here and scroll down bla bla bla)
|
||||
# Install app dependencies
|
||||
# A wildcard is used to ensure both package.json AND package-lock.json are copied
|
||||
COPY package*.json ./
|
||||
RUN npm i
|
||||
# If you are building your code for production
|
||||
# RUN npm ci --only=production
|
||||
# Bundle app source
|
||||
COPY . .
|
||||
# Expose port 3000
|
||||
EXPOSE 3430
|
||||
# Run it.
|
||||
CMD [ "node", "index.js" ]
|
|
@ -1,30 +0,0 @@
|
|||
<!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>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="/api/live/inventory/add" method="post">
|
||||
<label for="name">name</label>
|
||||
<input type="text" name="name" placeholder="Name" id="name" required>
|
||||
<label for="desc">desc</label>
|
||||
<input type="text" name="desc" placeholder="Description" id="desc" required>
|
||||
<label for="status">status</label>
|
||||
<input type="text" name="status" placeholder="Status" id="status" required>
|
||||
<label for="category">category</label>
|
||||
<input type="text" name="category" placeholder="Category" id="category" required>
|
||||
<label for="amount">amount</label>
|
||||
<input type="text" name="amount" placeholder="Amount" id="amount" required>
|
||||
<label for="location">location</label>
|
||||
<input type="text" name="location" placeholder="Location" id="location" required>
|
||||
<label for="orderid">order id</label>
|
||||
<input type="text" name="orderid" placeholder="Order id" id="orderid" required>
|
||||
<label for="notes">notes</label>
|
||||
<input type="text" name="notes" placeholder="Notes" id="notes" required>
|
||||
<input type="submit" value="Publish">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
|
@ -19,21 +19,83 @@
|
|||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
|
||||
<div class="navbar-nav">
|
||||
<a class="nav-link active" aria-current="page" href="/dashboard">Dashboard</a>
|
||||
<a class="nav-link" href="/stock">Stock</a>
|
||||
<a class="nav-link" href="/parts">Parts</a>
|
||||
<a class="nav-link" href="/assets">Assets</a>
|
||||
<a class="nav-link" href="/orders">Ordes</a>
|
||||
<a class="nav-link" href="/admin">Admin</a>
|
||||
<a class="nav-link disabled"> Logged in as: <%= results[0].name %></a>
|
||||
<a class="nav-link disabled" aria-current="page" href="/dashboard">Dashboard</a>
|
||||
<a class="nav-link active" href="/stock">Stock</a>
|
||||
<a class="nav-link disabled" href="/parts">Parts</a>
|
||||
<a class="nav-link disabled" href="/assets">Assets</a>
|
||||
<a class="nav-link disabled" href="/orders">Ordes</a>
|
||||
<a class="nav-link disabled" href="/admin">Admin</a>
|
||||
<a class="nav-link disabled"> Logged in as: Demo</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container-fluid">
|
||||
<% if(site == 21) { %>
|
||||
<h1>New item in stock</h1>
|
||||
<br>
|
||||
<form action="/api/live/inventory/add" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name">
|
||||
<div id="nameHelp" class="form-text">Name for the item.</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="desc" class="form-label">Description</label>
|
||||
<input type="text" class="form-control" id="desc" name="desc">
|
||||
<div id="descHelp" class="form-text">Description for the item.</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="status" class="form-label">Status</label>
|
||||
<select id="status" class="form-select" name="status">
|
||||
<option value="0">No more left (0)</option>
|
||||
<option value="1">Waiting for order (1)</option>
|
||||
<option value="2">Damaged (2)</option>
|
||||
<option value="3">OK (3)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="category" class="form-label">Category</label>
|
||||
<select id="category" class="form-select" name="category">
|
||||
<option value="0">No category (0)</option>
|
||||
<option value="1">Furniture (1)</option>
|
||||
<option value="2">Digital only (2)</option>
|
||||
<option value="3">Electronics (3)</option>
|
||||
<option value="4">Gaming equipment (4)</option>
|
||||
<option value="5">Audio equipment (5)</option>
|
||||
<option value="6">???? (6)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="amount" class="form-label">Amount</label>
|
||||
<input type="text" class="form-control" id="amount" name="amount">
|
||||
<div id="amountHelp" class="form-text">Amount of this item.</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="location" class="form-label">Location</label>
|
||||
<select id="location" class="form-select" name="location">
|
||||
<option value="0">Home (0)</option>
|
||||
<option value="1">Office in the middle of nowhere (1)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="orderid" class="form-label">Order ID</label>
|
||||
<input type="text" class="form-control" id="orderid" name="orderid">
|
||||
<div id="orderidHelp" class="form-text">Amount of this item.</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="notes" class="form-label">Notes</label>
|
||||
<input type="text" class="form-control" id="notes" name="notes">
|
||||
<div id="noteHelp" class="form-text">Write a note for the item.</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
||||
<% } %>
|
||||
<% if(site == 2) { %>
|
||||
<h1>Inventory</h1>
|
||||
<br>
|
||||
<button type="button" class="btn btn-primary" onclick='location.href="/stock/new"'>New Item</button>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -65,7 +127,7 @@
|
|||
<td><%= results[i].lastupdate %></td>
|
||||
<td><%= results[i].orderid %></td>
|
||||
<td><%= results[i].notes %></td>
|
||||
<td><button type="button" class="btn btn-warning">Edit</button> <button type="button" class="btn btn-danger" onclick='location.href="/api/live/inventory/delete/<%= i %>"'>Delete</button></td>
|
||||
<td> <button type="button" class="btn btn-danger" onclick='location.href="/api/live/inventory/delete/<%= results[i].id %>"'>Delete</button></td>
|
||||
</tr>
|
||||
<% } %>
|
||||
</tbody>
|
||||
|
|
Loading…
Reference in New Issue