General refactor
This commit is contained in:
@@ -15,6 +15,7 @@ function errorPageRenderer(res, emoji, message) {
|
|||||||
res.render("error", {
|
res.render("error", {
|
||||||
page_title: app_conf.name,
|
page_title: app_conf.name,
|
||||||
program: app_conf.program,
|
program: app_conf.program,
|
||||||
|
app_url: app_conf.app_url,
|
||||||
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
|
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
|
||||||
js_path: path.join(app_conf.paths.js.web, "error.js"),
|
js_path: path.join(app_conf.paths.js.web, "error.js"),
|
||||||
error_emoji: emoji,
|
error_emoji: emoji,
|
||||||
@@ -124,6 +125,7 @@ router.get("/add", async (req, res) => {
|
|||||||
res.render("add", {
|
res.render("add", {
|
||||||
page_title: app_conf.name,
|
page_title: app_conf.name,
|
||||||
program: app_conf.program,
|
program: app_conf.program,
|
||||||
|
app_url: app_conf.app_url,
|
||||||
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
|
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
|
||||||
js_path: path.join(app_conf.paths.js.web, "add.js"),
|
js_path: path.join(app_conf.paths.js.web, "add.js"),
|
||||||
chartjs: app_conf.paths.chartjs.web + "/chart.umd.js",
|
chartjs: app_conf.paths.chartjs.web + "/chart.umd.js",
|
||||||
@@ -143,6 +145,7 @@ router.get("/edit", async (req, res) => {
|
|||||||
res.render("edit", {
|
res.render("edit", {
|
||||||
page_title: app_conf.name,
|
page_title: app_conf.name,
|
||||||
program: app_conf.program,
|
program: app_conf.program,
|
||||||
|
app_url: app_conf.app_url,
|
||||||
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
|
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
|
||||||
js_path: path.join(app_conf.paths.js.web, "edit.js"),
|
js_path: path.join(app_conf.paths.js.web, "edit.js"),
|
||||||
chartjs: app_conf.paths.chartjs.web + "/chart.umd.js",
|
chartjs: app_conf.paths.chartjs.web + "/chart.umd.js",
|
||||||
@@ -203,6 +206,7 @@ router.get("/", async (req, res) => {
|
|||||||
res.render("index", {
|
res.render("index", {
|
||||||
page_title: app_conf.name,
|
page_title: app_conf.name,
|
||||||
program: app_conf.program,
|
program: app_conf.program,
|
||||||
|
app_url: app_conf.app_url,
|
||||||
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
|
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
|
||||||
js_path: path.join(app_conf.paths.js.web, "index.js"),
|
js_path: path.join(app_conf.paths.js.web, "index.js"),
|
||||||
map_name_msg: (selected_map_name != "" ? "Using: " + selected_map_name : ""),
|
map_name_msg: (selected_map_name != "" ? "Using: " + selected_map_name : ""),
|
||||||
@@ -222,6 +226,7 @@ router.get("/about", (req, res) => {
|
|||||||
res.render("about", {
|
res.render("about", {
|
||||||
page_title: app_conf.name,
|
page_title: app_conf.name,
|
||||||
program: app_conf.program,
|
program: app_conf.program,
|
||||||
|
app_url: app_conf.app_url,
|
||||||
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
|
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
|
||||||
version: app_conf.version
|
version: app_conf.version
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,15 +12,7 @@ router.use(app_conf.paths.chartjs.web, express.static(path.join(path.dirname(req
|
|||||||
* Main endpoint - might implement authentication step here...
|
* Main endpoint - might implement authentication step here...
|
||||||
*/
|
*/
|
||||||
router.get("/", (req, res) => {
|
router.get("/", (req, res) => {
|
||||||
res.render("auth", {
|
res.redirect(`${app_conf.protocol}://${app_conf.host}:${app_conf.port}${app_conf.app_url}`);
|
||||||
page_title: app_conf.name,
|
|
||||||
|
|
||||||
program: app_conf.program,
|
|
||||||
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
|
|
||||||
protocol: app_conf.protocol,
|
|
||||||
host: app_conf.host,
|
|
||||||
port: app_conf.port
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
+1
-1
@@ -30,7 +30,7 @@
|
|||||||
style="font-size: 150%;">GitHub</a>
|
style="font-size: 150%;">GitHub</a>
|
||||||
</center>
|
</center>
|
||||||
<br>
|
<br>
|
||||||
<a href="/app"><span>🢀 </span>Return</a>
|
<a href="<%= app_url %>"><span>🢀 </span>Return</a>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -16,7 +16,7 @@
|
|||||||
<script src="<%= js_path %>" defer></script>
|
<script src="<%= js_path %>" defer></script>
|
||||||
<script src="<%= chartjs %>"></script>
|
<script src="<%= chartjs %>"></script>
|
||||||
<script defer>
|
<script defer>
|
||||||
var steps = '<%= steps %>', max_rpm = '<%= max_rpm %>', max_throttle = '<%= max_throttle %>';
|
var steps = '<%= steps %>', max_rpm = '<%= max_rpm %>', max_throttle = '<%= max_throttle %>', app_url = '<%= app_url %>';
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@@ -55,12 +55,12 @@
|
|||||||
<table id="motor_table" style="text-align: center;"></table>
|
<table id="motor_table" style="text-align: center;"></table>
|
||||||
</div>
|
</div>
|
||||||
<div style="display: flex; flex-direction: row; justify-content: space-between;">
|
<div style="display: flex; flex-direction: row; justify-content: space-between;">
|
||||||
<a href="/app"><span>🢀 </span>Return</a>
|
<a href="<%= app_url %>"><span>🢀 </span>Return</a>
|
||||||
<label id="commit" style="cursor: pointer;"><span>✅ </span>Commit</label>
|
<label id="commit" style="cursor: pointer;"><span>✅ </span>Commit</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="about_div">
|
<div class="about_div">
|
||||||
<center><a href="/app/about">About</label></center>
|
<center><a href="<%= app_url %>/about">About</label></center>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<title>
|
|
||||||
<%= page_title %>
|
|
||||||
</title>
|
|
||||||
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
|
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
||||||
<link
|
|
||||||
href="https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700&display=swap"
|
|
||||||
rel="stylesheet">
|
|
||||||
<link rel="stylesheet" href="<%= css_path %>">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="control_div">
|
|
||||||
<label
|
|
||||||
style='font-family: "Ubuntu", sans-serif; font-weight: 500; font-style: normal; font-size: 200%;'>Centaurus
|
|
||||||
Racing Team</label>
|
|
||||||
</div>
|
|
||||||
<div class="main_div"
|
|
||||||
style="display: flex; flex-direction: column; justify-content: space-between; font-size: 150%; margin-top: 15px; margin-bottom: 15px;">
|
|
||||||
<div style="display: flex; flex-direction: row; justify-content: space-evenly;">
|
|
||||||
<label><%= page_title %> <%= program %></label>
|
|
||||||
<a href="<%= protocol %>://<%= host %>:<%= port %>/app">Enter</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
+3
-3
@@ -16,7 +16,7 @@
|
|||||||
<script type="module" src="<%= js_path %>" defer></script>
|
<script type="module" src="<%= js_path %>" defer></script>
|
||||||
<script src="<%= chartjs %>"></script>
|
<script src="<%= chartjs %>"></script>
|
||||||
<script defer>
|
<script defer>
|
||||||
var map = '<%- map %>', map_meta = '<%- map_meta %>', steps = '<%= steps %>', max_rpm = '<%= max_rpm %>', max_throttle = '<%= max_throttle %>';
|
var map = '<%- map %>', map_meta = '<%- map_meta %>', steps = '<%= steps %>', max_rpm = '<%= max_rpm %>', max_throttle = '<%= max_throttle %>', app_url = '<%= app_url %>';
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@@ -60,12 +60,12 @@
|
|||||||
<table id="motor_table" style="text-align: center;"></table>
|
<table id="motor_table" style="text-align: center;"></table>
|
||||||
</div>
|
</div>
|
||||||
<div style="display: flex; flex-direction: row; justify-content: space-between;">
|
<div style="display: flex; flex-direction: row; justify-content: space-between;">
|
||||||
<a href="/app"><span>🢀 </span>Return</a>
|
<a href="<%= app_url %>"><span>🢀 </span>Return</a>
|
||||||
<label id="commit" style="cursor: pointer;"><span>✅ </span>Commit</label>
|
<label id="commit" style="cursor: pointer;"><span>✅ </span>Commit</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="about_div">
|
<div class="about_div">
|
||||||
<center><a href="/app/about">About</label></center>
|
<center><a href="<%= app_url %>/about">About</label></center>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -14,6 +14,9 @@
|
|||||||
rel="stylesheet">
|
rel="stylesheet">
|
||||||
<link rel="stylesheet" href="<%= css_path %>">
|
<link rel="stylesheet" href="<%= css_path %>">
|
||||||
<script src="<%= js_path %>" defer></script>
|
<script src="<%= js_path %>" defer></script>
|
||||||
|
<script defer>
|
||||||
|
var app_url = '<%= app_url %>';
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@@ -38,7 +41,7 @@
|
|||||||
<%= error_message %>
|
<%= error_message %>
|
||||||
</label>
|
</label>
|
||||||
<br>
|
<br>
|
||||||
<a href="/app"><span>🢀 </span>Return</a>
|
<a href="<%= app_url %>"><span>🢀 </span>Return</a>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -14,6 +14,9 @@
|
|||||||
rel="stylesheet">
|
rel="stylesheet">
|
||||||
<link rel="stylesheet" href="<%= css_path %>">
|
<link rel="stylesheet" href="<%= css_path %>">
|
||||||
<script src="<%= js_path %>" defer></script>
|
<script src="<%= js_path %>" defer></script>
|
||||||
|
<script defer>
|
||||||
|
var app_url = '<%= app_url %>';
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@@ -47,7 +50,7 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="about_div">
|
<div class="about_div">
|
||||||
<center><a href="/app/about">About</label></center>
|
<center><a href="<%= app_url %>/about">About</label></center>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ module.exports = {
|
|||||||
program: "Throttle & Motor Mapping",
|
program: "Throttle & Motor Mapping",
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
protocol: "http",
|
protocol: "http",
|
||||||
port: 8080,
|
port: 8081,
|
||||||
|
app_url: "/app",
|
||||||
username: "admin",
|
username: "admin",
|
||||||
password: "password",
|
password: "password",
|
||||||
logger: {
|
logger: {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
prefix: "map",
|
prefix: "map",
|
||||||
|
extension: "csv",
|
||||||
steps: 10,
|
steps: 10,
|
||||||
max_rpm: 6500,
|
max_rpm: 6500,
|
||||||
max_throttle: 1,
|
max_throttle: 1,
|
||||||
selected_map_path: "app/storage/selected"
|
map_storage_path: "/app/storage"
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@ app.use(fileUpload({
|
|||||||
|
|
||||||
app.use("/", public_routes);
|
app.use("/", public_routes);
|
||||||
|
|
||||||
app.use("/app", basicAuth({
|
app.use(`${app_conf.app_url}`, basicAuth({
|
||||||
users: {
|
users: {
|
||||||
[app_conf.username]: app_conf.password
|
[app_conf.username]: app_conf.password
|
||||||
},
|
},
|
||||||
@@ -39,8 +39,7 @@ app.use("/app", basicAuth({
|
|||||||
app.set("view engine", "ejs");
|
app.set("view engine", "ejs");
|
||||||
app.set("views", path.join(__dirname, app_conf.views_directory));
|
app.set("views", path.join(__dirname, app_conf.views_directory));
|
||||||
const server = app.listen(app_conf.port, (error) => {
|
const server = app.listen(app_conf.port, (error) => {
|
||||||
logger.info("Starting Database Editor.");
|
logger.info(`Starting ${app_conf.name} ${app_conf.program}.`);
|
||||||
|
|
||||||
|
|
||||||
fs.rm(path.join(__dirname, app_conf.temp_directory, "/."), { recursive: true }, (error) => {
|
fs.rm(path.join(__dirname, app_conf.temp_directory, "/."), { recursive: true }, (error) => {
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ setEventListeners(commit, async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/app/add", {
|
const response = await fetch(`${app_url}/add`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(req_body),
|
body: JSON.stringify(req_body),
|
||||||
headers: {
|
headers: {
|
||||||
@@ -69,7 +69,7 @@ setEventListeners(commit, async () => {
|
|||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Response status: ${response.status}`);
|
throw new Error(`Response status: ${response.status}`);
|
||||||
} else {
|
} else {
|
||||||
window.location.href = "/app";
|
window.location.href = app_url;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(`Add unsuccessful. ${error.message}`);
|
alert(`Add unsuccessful. ${error.message}`);
|
||||||
|
|||||||
@@ -32,13 +32,13 @@ setEventListeners(enable, async () => {
|
|||||||
const map_filename = (new URLSearchParams(window.location.search)).get("element");
|
const map_filename = (new URLSearchParams(window.location.search)).get("element");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/app/enable?element=${map_filename}`, {
|
const response = await fetch(`${app_url}/enable?element=${map_filename}`, {
|
||||||
method: "GET"
|
method: "GET"
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Response status: ${response.status}`);
|
throw new Error(`Response status: ${response.status}`);
|
||||||
} else {
|
} else {
|
||||||
window.location.href = "/app";
|
window.location.href = app_url;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(`Could not enable map. ${error.message}`);
|
alert(`Could not enable map. ${error.message}`);
|
||||||
@@ -49,13 +49,13 @@ setEventListeners(remove, async () => {
|
|||||||
const map_filename = (new URLSearchParams(window.location.search)).get("element");
|
const map_filename = (new URLSearchParams(window.location.search)).get("element");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/app/remove?element=${map_filename}`, {
|
const response = await fetch(`${app_url}/remove?element=${map_filename}`, {
|
||||||
method: "DELETE"
|
method: "DELETE"
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Response status: ${response.status}`);
|
throw new Error(`Response status: ${response.status}`);
|
||||||
} else {
|
} else {
|
||||||
window.location.href = "/app";
|
window.location.href = app_url;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(`Remove unsuccessful. ${error.message}`);
|
alert(`Remove unsuccessful. ${error.message}`);
|
||||||
@@ -100,7 +100,7 @@ setEventListeners(commit, async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/app/edit?element=${map_filename}`, {
|
const response = await fetch(`${app_url}/edit?element=${map_filename}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(req_body),
|
body: JSON.stringify(req_body),
|
||||||
headers: {
|
headers: {
|
||||||
@@ -110,7 +110,7 @@ setEventListeners(commit, async () => {
|
|||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Response status: ${response.status}`);
|
throw new Error(`Response status: ${response.status}`);
|
||||||
} else {
|
} else {
|
||||||
window.location.href = "/app";
|
window.location.href = app_url;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(`Edit unsuccessful. ${error.message}`);
|
alert(`Edit unsuccessful. ${error.message}`);
|
||||||
@@ -123,7 +123,7 @@ setEventListeners(commit, async () => {
|
|||||||
setEventListeners(download, () => {
|
setEventListeners(download, () => {
|
||||||
const map_filename = (new URLSearchParams(window.location.search)).get("element");
|
const map_filename = (new URLSearchParams(window.location.search)).get("element");
|
||||||
|
|
||||||
window.location.href = `/app/download?element=${map_filename}`;
|
window.location.href = `${app_url}/download?element=${map_filename}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
var parsed_map = JSON.parse(map);
|
var parsed_map = JSON.parse(map);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ function setEventListeners(element, cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setEventListeners(add, () => {
|
setEventListeners(add, () => {
|
||||||
window.location.href = "/app/add";
|
window.location.href = `${app_url}/add`;
|
||||||
});
|
});
|
||||||
|
|
||||||
setEventListeners(upload, async () => {
|
setEventListeners(upload, async () => {
|
||||||
@@ -27,7 +27,7 @@ setEventListeners(upload, async () => {
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
|
|
||||||
fetch('/app/upload', {
|
fetch(`${app_url}/upload`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
|
|||||||
@@ -22,13 +22,13 @@ function setEventListeners(element, cb) {
|
|||||||
|
|
||||||
setEventListeners(disable, async () => {
|
setEventListeners(disable, async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/app/disable`, {
|
const response = await fetch(`${app_url}/disable`, {
|
||||||
method: "GET"
|
method: "GET"
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Response status: ${response.status}`);
|
throw new Error(`Response status: ${response.status}`);
|
||||||
} else {
|
} else {
|
||||||
window.location.href = "/app";
|
window.location.href = app_url;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(`Could not disable map. ${error.message}`);
|
alert(`Could not disable map. ${error.message}`);
|
||||||
@@ -41,7 +41,7 @@ setEventListeners(upload, async () => {
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
|
|
||||||
fetch('/app/upload', {
|
fetch(`${app_url}/upload`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
@@ -58,7 +58,7 @@ setEventListeners(upload, async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
setEventListeners(add, () => {
|
setEventListeners(add, () => {
|
||||||
window.location.href = "/app/add";
|
window.location.href = `${app_url}/add`;
|
||||||
});
|
});
|
||||||
|
|
||||||
setEventListeners(logout, () => {
|
setEventListeners(logout, () => {
|
||||||
@@ -69,6 +69,6 @@ const map_rows = map_table.rows;
|
|||||||
|
|
||||||
for (let i = 1; i < map_rows.length; i++) {
|
for (let i = 1; i < map_rows.length; i++) {
|
||||||
setEventListeners(map_rows[i], () => {
|
setEventListeners(map_rows[i], () => {
|
||||||
window.location.href = `/app/edit?element=${map_rows[i].cells[0].innerText}`;
|
window.location.href = `${app_url}/edit?element=${map_rows[i].cells[0].innerText}`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user