Code refactor
This commit is contained in:
@@ -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
@@ -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
@@ -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>✅ </span>Commit</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="about_div">
|
||||
<center><a href="/app/about">About</label></center>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
+7
-1
@@ -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>- </span>Remove</label>
|
||||
</div>
|
||||
@@ -39,6 +42,9 @@
|
||||
<label id="commit" style="cursor: pointer;"><span>✅ </span>Commit</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="about_div">
|
||||
<center><a href="/app/about">About</label></center>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
+4
-1
@@ -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>🡅
|
||||
</span>Upload</label>
|
||||
|
||||
+4
-1
@@ -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>+ </span>Add</label>
|
||||
<label id="upload" style="cursor: pointer; margin-left: 10px; margin-right: 10px;"><span>🡅
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module.exports = {
|
||||
version: "1.0",
|
||||
name: "CRTelemetry",
|
||||
program: "SQLite3",
|
||||
host: "localhost",
|
||||
protocol: "http",
|
||||
port: 80,
|
||||
|
||||
@@ -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];
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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}`;
|
||||
|
||||
Reference in New Issue
Block a user