bing
parent
8f88bdbc4c
commit
10ad412382
|
@ -1,16 +1,37 @@
|
|||
// Forces NodeJS to disable "Silent errors", in other words, don't
|
||||
'use strict';
|
||||
|
||||
// Import things
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const server = require('http').createServer(app);
|
||||
const port = process.env.PORT || 3430;
|
||||
const test = require('../testdatabase.json');
|
||||
const bodyParser = require("body-parser");
|
||||
var mysql = require('mysql');
|
||||
|
||||
var site;
|
||||
// TODO: Add stuff for MySQL
|
||||
|
||||
var connection = mysql.createConnection({
|
||||
host : '127.0.0.1',
|
||||
user : 'demo',
|
||||
password : 'lqklvok',
|
||||
database : 'mangoshelfdb'
|
||||
});
|
||||
|
||||
|
||||
connection.query('SELECT * FROM stock', function (error, results, fields) {
|
||||
if (error) throw error;
|
||||
// connected!
|
||||
console.log(results);
|
||||
});
|
||||
|
||||
// Set the templates folder for the thingy
|
||||
app.set('views', __dirname + '/../Templates');
|
||||
app.set('view engine', 'ejs');
|
||||
app.use(bodyParser.urlencoded({ extended: false }));
|
||||
app.use(bodyParser.json());
|
||||
|
||||
// Makes it so that the Public folder mounts under /
|
||||
app.use(express.static(__dirname + '/../Public'));
|
||||
|
@ -18,18 +39,51 @@ app.use(express.static(__dirname + '/../Public'));
|
|||
// Main page
|
||||
app.get('/', function(req, res){
|
||||
console.log('🌐 Client requested ' + req.url);
|
||||
res.render('index', { test, site: 1 });
|
||||
res.render('index', { results, site: 1 });
|
||||
console.log('✅ Client recieved ' + req.url);
|
||||
// console.log(test.cars.Nissan[1].model)
|
||||
});
|
||||
|
||||
app.get('/inventory', function(req, res){
|
||||
app.get('/stock', function(req, res){
|
||||
console.log('🌐 Client requested ' + req.url);
|
||||
res.render('index', { test, site: 2 });
|
||||
connection.query('SELECT * FROM stock', function (error, results, fields) {
|
||||
if (error) throw error;
|
||||
// connected!
|
||||
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){
|
||||
console.log('🌐 Client requested ' + req.url);
|
||||
res.render('additem');
|
||||
console.log('✅ Client recieved ' + req.url);
|
||||
// console.log(test.cars.Nissan[1].model)
|
||||
});
|
||||
|
||||
app.post('/api/live/inventory/add', function(req, res){
|
||||
let name = req.body.name;
|
||||
let desc = req.body.desc;
|
||||
let status = req.body.status;
|
||||
let category = req.body.category;
|
||||
let amount = req.body.amount;
|
||||
let location = req.body.location;
|
||||
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;}})
|
||||
if (name && desc && status && category && amount && location && orderid && notes) {
|
||||
console.log('boop!');
|
||||
}
|
||||
// console.log(test.cars.Nissan[1].model)
|
||||
});
|
||||
|
||||
|
||||
// Simple way to expose a function
|
||||
exports = module.exports = rws;
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<!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,10 +19,13 @@
|
|||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
|
||||
<div class="navbar-nav">
|
||||
<a class="nav-link active" aria-current="page" href="/">Dashboard</a>
|
||||
<a class="nav-link" href="/inventory">Inventory</a>
|
||||
<a class="nav-link" href="#"><%= site %></a>
|
||||
<a class="nav-link disabled"><%= test.mangoshelf.Items[1].Location %></a>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -36,26 +39,40 @@
|
|||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Name</th>
|
||||
<th scope="col">Location</th>
|
||||
<th scope="col">Description</th>
|
||||
<th scope="col">Status</th>
|
||||
<th scope="col">Category</th>
|
||||
<th scope="col">Amount</th>
|
||||
<th scope="col">Tools</th>
|
||||
<th scope="col">Location</th>
|
||||
<th scope="col">Expiry date</th>
|
||||
<th scope="col">Last updated</th>
|
||||
<th scope="col">Order id</th>
|
||||
<th scope="col">Notes</th>
|
||||
<th scope="col">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% for (let i = 0; i < test.mangoshelf.Items.length; i++) { %>
|
||||
<% for (let i = 0; i < results.length; i++) { %>
|
||||
<tr>
|
||||
<th scope="row"><%= i + 1 %></th>
|
||||
<td><%= test.mangoshelf.Items[i].Name %></td>
|
||||
<td><%= test.mangoshelf.Items[i].Location %></td>
|
||||
<td><%= test.mangoshelf.Items[i].Amount %></td>
|
||||
<td><button type="button" class="btn btn-warning">Edit</button> <button type="button" class="btn btn-danger">Delete</button></td>
|
||||
<td><%= results[i].name %></td>
|
||||
<td><%= results[i].description %></td>
|
||||
<td><%= results[i].status %></td>
|
||||
<td><%= results[i].category %></td>
|
||||
<td><%= results[i].amount %></td>
|
||||
<td><%= results[i].location %></td>
|
||||
<td><%= results[i].expiry %></td>
|
||||
<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>
|
||||
</tr>
|
||||
<% } %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% } %>
|
||||
</div>
|
||||
|
||||
<script src="script.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-u1OknCvxWvY5kfmNBILK2hRnQC3Pr17a+RTT6rIHI7NnikvbZlHgTPOOmMi466C8" crossorigin="anonymous"></script>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,9 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"ejs": "^3.1.8",
|
||||
"express": "^4.18.1"
|
||||
"body-parser": "^1.20.0",
|
||||
"ejs": "^3.1.8",
|
||||
"ejs-lint": "^1.2.2",
|
||||
"express": "^4.18.1",
|
||||
"mysql": "^2.18.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue