new&renamed buttons, fixed quit button

This commit is contained in:
Skylar Grant 2023-11-14 18:06:09 -05:00
parent db763223c6
commit 67a9fc19ec
4 changed files with 30 additions and 10 deletions

View File

@ -10,6 +10,7 @@
// Modules
const express = require('express');
const http = require('http');
const fs = require('fs');
const fn = require('./functions.js').functions;
const { dbfn } = require('./functions.js');
@ -39,21 +40,23 @@ app.get('/', (req, res) => {
// A POST form submission to the root page
app.post('/', (req, response) => {
if (req.body.start != undefined) {
fn.commands.startup();
if (req.body.augerOn != undefined) {
fn.commands.augerOn();
fn.commands.refreshConfig().then(res => {
config = res.config;
response.render('index', { config: JSON.stringify(config) });
return;
});
return;
}
if (req.body.shutdown != undefined) {
fn.commands.shutdown();
if (req.body.augerOff != undefined) {
fn.commands.augerOff();
fn.commands.refreshConfig().then(res => {
config = res.config;
response.render('index', { config: JSON.stringify(config) });
return;
});
return;
}
if (req.body.reload != undefined) {
const updateAugerOffIntervalQuery = `UPDATE intervals SET value = '${2000 - req.body.feedRate}' WHERE key = 'auger_off'`;
@ -69,15 +72,24 @@ app.post('/', (req, response) => {
});
}).catch(err => console.log(`E: ${err}`));
}).catch(err => console.log(`E: ${err}`));
return;
}
if (req.body.quit != undefined) {
fn.commands.quit();
fs.appendFile('quit', ".", err => {
if (err) console.error(err);
});
fn.commands.refreshConfig().then(res => {
config = res.config;
response.render('index', { config: JSON.stringify(config) });
return;
});
return;
}
fn.commands.refreshConfig().then(res => {
config = res.config;
response.render('index', { config: JSON.stringify(config) });
return;
});
});
module.exports = {

View File

@ -86,7 +86,7 @@ const functions = {
},
commands: {
// Prepare the stove for starting
startup() {
augerOn() { // FKA startup()
// Basic startup just enables the auger
const enableAugerQuery = "UPDATE status SET value = 1 WHERE key = 'auger'";
dbfn.run(enableAugerQuery).then(res => {
@ -94,7 +94,7 @@ const functions = {
return;
}).catch(err => console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${err}`));
},
shutdown() {
augerOff() { // FKA shutdown()
// Basic shutdown only needs to disable the auger
const disableAugerQuery = "UPDATE status SET value = 0 WHERE key = 'auger'";
dbfn.run(disableAugerQuery).then(res => {

View File

@ -100,3 +100,7 @@ table, th, td {
th, td {
width: 50%;
}
#quit {
/* visibility: hidden; */
}

View File

@ -43,8 +43,12 @@
<form action="/" method="post">
<!-- Start | Shutdown | Reload Settings -->
<div class="button-container d-flex justify-content-between">
<input class="btn btn-outline-secondary" type="submit" id="ignite" value="Enable Auger" name="start">
<input class="btn btn-outline-secondary" type="submit" id="shutdown" value="Disable Auger" name="shutdown">
<input class="btn btn-outline-secondary" type="submit" id="auger-on" value="Enable Auger" name="augerOn">
<input class="btn btn-outline-secondary" type="submit" id="auger-off" value="Disable Auger" name="augerOff">
<input class="btn btn-outline-secondary" type="submit" id="igniter-on" value="Enable Igniter" name="igniterOn">
<input class="btn btn-outline-secondary" type="submit" id="igniter-off" value="Disable Igniter" name="igniterOff">
<input class="btn btn-outline-secondary" type="submit" id="exhaust-on" value="Enable Exhaust" name="exhaustOn">
<input class="btn btn-outline-secondary" type="submit" id="exhaust-off" value="Disable Exhaust" name="exhaustOff">
</div>
<!-- Set feed rates -->
<div class="form-group">
@ -67,7 +71,7 @@
</div> -->
<div class="controls-container">
<form action="/" method="POST">
<input class="btn btn-danger" type="submit" id="quit" value="Quit!!" name="quit" style="visibility: hidden;">
<input class="btn btn-danger" type="submit" id="quit" value="Quit!!" name="quit">
</form>
</div>
<!-- <script src="./main.js"></script> -->