Code refactor

This commit is contained in:
2025-06-07 10:12:47 +02:00
parent c85b918f71
commit 1e5cd0790b
10 changed files with 38 additions and 19 deletions
+5
View File
@@ -13,6 +13,7 @@ const router = express.Router();
function errorPageRenderer(res, emoji, message) {
res.render("error", {
page_title: app_conf.name,
program: app_conf.program,
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
js_path: path.join(app_conf.paths.js.web, "error.js"),
error_emoji: emoji,
@@ -180,6 +181,7 @@ router.get("/add", async (req, res) => {
table_data += "</tr>";
res.render("add", {
page_title: app_conf.name,
program: app_conf.program,
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
js_path: path.join(app_conf.paths.js.web, "add.js"),
column_options: JSON.stringify(column_options),
@@ -246,6 +248,7 @@ router.get("/edit", async (req, res) => {
res.render("edit", {
page_title: app_conf.name,
program: app_conf.program,
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
js_path: path.join(app_conf.paths.js.web, "edit.js"),
column_options: JSON.stringify(column_options),
@@ -293,6 +296,7 @@ router.get("/", async (req, res) => {
res.render("index", {
page_title: app_conf.name,
program: app_conf.program,
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
js_path: path.join(app_conf.paths.js.web, "index.js"),
table_header: table_header,
@@ -310,6 +314,7 @@ router.get("/", async (req, res) => {
router.get("/about", (req, res) => {
res.render("about", {
page_title: app_conf.name,
program: app_conf.program,
css_path: path.join(app_conf.paths.css.web, "stylesheet.css"),
version: app_conf.version
});
+4 -1
View File
@@ -17,7 +17,10 @@
<body>
<div class="control_div" style="display: flex; flex-direction: row; justify-content: space-between;">
<label style="font-size: 200%;">CRTelemetry SQLite3</label>
<label style="font-size: 200%;">
<%= page_title%>
<%= program %>
</label>
</div>
<div class="main_div">
<center>
+7 -1
View File
@@ -21,7 +21,10 @@
<body>
<div class="control_div">
<label style="font-size: 200%;">CRTelemetry SQLite3</label>
<label style="font-size: 200%;">
<%= page_title%>
<%= program %>
</label>
</div>
<div class="main_div">
<center><label>Add record</label></center>
@@ -36,6 +39,9 @@
<label id="commit" style="cursor: pointer;"><span>&#9989; </span>Commit</label>
</div>
</div>
<div class="about_div">
<center><a href="/app/about">About</label></center>
</div>
</body>
</html>
+7 -1
View File
@@ -21,7 +21,10 @@
<body>
<div class="control_div" style="display: flex; flex-direction: row; justify-content: space-between;">
<label style="font-size: 200%;">CRTelemetry SQLite3</label>
<label style="font-size: 200%;">
<%= page_title%>
<%= program %>
</label>
<div style="display: flex;align-items: center;">
<label id="remove" style="cursor: pointer; margin-right: 10px;"><span>&#45; </span>Remove</label>
</div>
@@ -39,6 +42,9 @@
<label id="commit" style="cursor: pointer;"><span>&#9989; </span>Commit</label>
</div>
</div>
<div class="about_div">
<center><a href="/app/about">About</label></center>
</div>
</body>
</html>
+4 -1
View File
@@ -19,7 +19,10 @@
<body>
<input type="file" id="file_input" accept=".db" style="display: none;" />
<div class="control_div" style="display: flex; flex-direction: row; justify-content: space-between;">
<label style="font-size: 200%;">CRTelemetry SQLite3</label>
<label style="font-size: 200%;">
<%= page_title%>
<%= program %>
</label>
<div style="display: flex;align-items: center;">
<label id="upload" style="cursor: pointer; margin-left: 10px; margin-right: 10px;"><span>&#129093;
</span>Upload</label>
+4 -1
View File
@@ -19,7 +19,10 @@
<body>
<input type="file" id="file_input" accept=".db" style="display: none;" />
<div class="control_div" style="display: flex; flex-direction: row; justify-content: space-between;">
<label style="font-size: 200%;">CRTelemetry SQLite3</label>
<label style="font-size: 200%;">
<%= page_title%>
<%= program %>
</label>
<div style="display: flex;align-items: center;">
<label id="add" style="cursor: pointer; margin-right: 10px;"><span>&#43; </span>Add</label>
<label id="upload" style="cursor: pointer; margin-left: 10px; margin-right: 10px;"><span>&#129093;
+1
View File
@@ -1,6 +1,7 @@
module.exports = {
version: "1.0",
name: "CRTelemetry",
program: "SQLite3",
host: "localhost",
protocol: "http",
port: 80,
+2 -5
View File
@@ -2,9 +2,6 @@ const sql_table = document.getElementById("sql_table");
const sql_row = sql_table.rows;
const commit = document.getElementById("commit");
column_options = JSON.parse(column_options);
console.log(column_options);
commit.onmouseenter = async function () {
this.style.backgroundColor = "blue";
}
@@ -31,7 +28,6 @@ commit.ondblclick = async function () {
}
});
if (!response.ok) {
alert(`Add unsuccessful. ${response.status}`);
throw new Error(`Response status: ${response.status}`);
} else {
this.style.backgroundColor = "blue";
@@ -39,13 +35,14 @@ commit.ondblclick = async function () {
}
} catch (error) {
alert(`Add unsuccessful. ${error.message}`);
console.error(error.message);
}
} else {
alert("Sensor name can't be null.");
}
};
column_options = JSON.parse(column_options);
for (let i = 1; i < sql_row[1].cells.length; i++) {
let opts = column_options[sql_row[0].cells[i].textContent];
+2 -7
View File
@@ -4,8 +4,6 @@ const commit = document.getElementById("commit");
const remove = document.getElementById("remove");
var changes = 0;
column_options = JSON.parse(column_options);
function setEventListeners(element, cb) {
element.onmouseenter = async function () {
this.style.backgroundColor = "blue";
@@ -28,14 +26,12 @@ setEventListeners(remove, async () => {
method: "DELETE"
});
if (!response.ok) {
alert(`Remove unsuccessful. ${response.status}`);
throw new Error(`Response status: ${response.status}`);
} else {
window.location.href = "/app";
}
} catch (error) {
alert(`Remove unsuccessful. ${error.message}`);
console.error(error.message);
}
});
@@ -58,20 +54,20 @@ setEventListeners(commit, async () => {
}
});
if (!response.ok) {
alert(`Edit unsuccessful. ${response.status}`);
throw new Error(`Response status: ${response.status}`);
} else {
window.location.href = "/app";
}
} catch (error) {
alert(`Edit unsuccessful. ${error.message}`);
console.error(error.message);
}
} else {
alert("Nothing to commit.");
}
});
column_options = JSON.parse(column_options);
for (let i = 1; i < sql_row[1].cells.length; i++) {
let opts = column_options[sql_row[0].cells[i].textContent];
@@ -97,7 +93,6 @@ for (let i = 1; i < sql_row[1].cells.length; i++) {
sql_row[1].cells[i].firstChild.onchange = async function () {
if (this.selectedIndex) {
console.log(this);
this.parentElement.style.backgroundColor = "blue";
changes++;
} else {
+2 -2
View File
@@ -4,8 +4,6 @@ const download = document.getElementById("download");
const logout = document.getElementById("logout");
const add = document.getElementById("add");
const sql_rows = sql_table.rows;
function setEventListeners(element, cb) {
element.onmouseenter = async function () {
this.style.backgroundColor = "blue";
@@ -56,6 +54,8 @@ setEventListeners(logout, () => {
window.location.href = `${window.location.protocol}//logout@${window.location.host}/`;
});
const sql_rows = sql_table.rows;
for (let i = 1; i < sql_rows.length; i++) {
setEventListeners(sql_rows[i], () => {
window.location.href = `/app/edit?element=${sql_rows[i].cells[0].innerText}`;