Code refactor
This commit is contained in:
@@ -13,6 +13,7 @@ const router = express.Router();
|
|||||||
function errorPageRenderer(res, emoji, message) {
|
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,
|
||||||
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,
|
||||||
@@ -180,6 +181,7 @@ router.get("/add", async (req, res) => {
|
|||||||
table_data += "</tr>";
|
table_data += "</tr>";
|
||||||
res.render("add", {
|
res.render("add", {
|
||||||
page_title: app_conf.name,
|
page_title: app_conf.name,
|
||||||
|
program: app_conf.program,
|
||||||
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"),
|
||||||
column_options: JSON.stringify(column_options),
|
column_options: JSON.stringify(column_options),
|
||||||
@@ -246,6 +248,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,
|
||||||
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"),
|
||||||
column_options: JSON.stringify(column_options),
|
column_options: JSON.stringify(column_options),
|
||||||
@@ -293,6 +296,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,
|
||||||
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"),
|
||||||
table_header: table_header,
|
table_header: table_header,
|
||||||
@@ -310,6 +314,7 @@ router.get("/", async (req, res) => {
|
|||||||
router.get("/about", (req, res) => {
|
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,
|
||||||
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
|
||||||
});
|
});
|
||||||
|
|||||||
+4
-1
@@ -17,7 +17,10 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="control_div" style="display: flex; flex-direction: row; justify-content: space-between;">
|
<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>
|
||||||
<div class="main_div">
|
<div class="main_div">
|
||||||
<center>
|
<center>
|
||||||
|
|||||||
+7
-1
@@ -21,7 +21,10 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="control_div">
|
<div class="control_div">
|
||||||
<label style="font-size: 200%;">CRTelemetry SQLite3</label>
|
<label style="font-size: 200%;">
|
||||||
|
<%= page_title%>
|
||||||
|
<%= program %>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="main_div">
|
<div class="main_div">
|
||||||
<center><label>Add record</label></center>
|
<center><label>Add record</label></center>
|
||||||
@@ -36,6 +39,9 @@
|
|||||||
<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">
|
||||||
|
<center><a href="/app/about">About</label></center>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
+7
-1
@@ -21,7 +21,10 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="control_div" style="display: flex; flex-direction: row; justify-content: space-between;">
|
<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;">
|
<div style="display: flex;align-items: center;">
|
||||||
<label id="remove" style="cursor: pointer; margin-right: 10px;"><span>- </span>Remove</label>
|
<label id="remove" style="cursor: pointer; margin-right: 10px;"><span>- </span>Remove</label>
|
||||||
</div>
|
</div>
|
||||||
@@ -39,6 +42,9 @@
|
|||||||
<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">
|
||||||
|
<center><a href="/app/about">About</label></center>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
+4
-1
@@ -19,7 +19,10 @@
|
|||||||
<body>
|
<body>
|
||||||
<input type="file" id="file_input" accept=".db" style="display: none;" />
|
<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;">
|
<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;">
|
<div style="display: flex;align-items: center;">
|
||||||
<label id="upload" style="cursor: pointer; margin-left: 10px; margin-right: 10px;"><span>🡅
|
<label id="upload" style="cursor: pointer; margin-left: 10px; margin-right: 10px;"><span>🡅
|
||||||
</span>Upload</label>
|
</span>Upload</label>
|
||||||
|
|||||||
+4
-1
@@ -19,7 +19,10 @@
|
|||||||
<body>
|
<body>
|
||||||
<input type="file" id="file_input" accept=".db" style="display: none;" />
|
<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;">
|
<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;">
|
<div style="display: flex;align-items: center;">
|
||||||
<label id="add" style="cursor: pointer; margin-right: 10px;"><span>+ </span>Add</label>
|
<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>🡅
|
<label id="upload" style="cursor: pointer; margin-left: 10px; margin-right: 10px;"><span>🡅
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
version: "1.0",
|
version: "1.0",
|
||||||
name: "CRTelemetry",
|
name: "CRTelemetry",
|
||||||
|
program: "SQLite3",
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
protocol: "http",
|
protocol: "http",
|
||||||
port: 80,
|
port: 80,
|
||||||
|
|||||||
@@ -2,9 +2,6 @@ const sql_table = document.getElementById("sql_table");
|
|||||||
const sql_row = sql_table.rows;
|
const sql_row = sql_table.rows;
|
||||||
const commit = document.getElementById("commit");
|
const commit = document.getElementById("commit");
|
||||||
|
|
||||||
column_options = JSON.parse(column_options);
|
|
||||||
console.log(column_options);
|
|
||||||
|
|
||||||
commit.onmouseenter = async function () {
|
commit.onmouseenter = async function () {
|
||||||
this.style.backgroundColor = "blue";
|
this.style.backgroundColor = "blue";
|
||||||
}
|
}
|
||||||
@@ -31,7 +28,6 @@ commit.ondblclick = async function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
alert(`Add unsuccessful. ${response.status}`);
|
|
||||||
throw new Error(`Response status: ${response.status}`);
|
throw new Error(`Response status: ${response.status}`);
|
||||||
} else {
|
} else {
|
||||||
this.style.backgroundColor = "blue";
|
this.style.backgroundColor = "blue";
|
||||||
@@ -39,13 +35,14 @@ commit.ondblclick = async function () {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(`Add unsuccessful. ${error.message}`);
|
alert(`Add unsuccessful. ${error.message}`);
|
||||||
console.error(error.message);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
alert("Sensor name can't be null.");
|
alert("Sensor name can't be null.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
column_options = JSON.parse(column_options);
|
||||||
|
|
||||||
for (let i = 1; i < sql_row[1].cells.length; i++) {
|
for (let i = 1; i < sql_row[1].cells.length; i++) {
|
||||||
let opts = column_options[sql_row[0].cells[i].textContent];
|
let opts = column_options[sql_row[0].cells[i].textContent];
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ const commit = document.getElementById("commit");
|
|||||||
const remove = document.getElementById("remove");
|
const remove = document.getElementById("remove");
|
||||||
var changes = 0;
|
var changes = 0;
|
||||||
|
|
||||||
column_options = JSON.parse(column_options);
|
|
||||||
|
|
||||||
function setEventListeners(element, cb) {
|
function setEventListeners(element, cb) {
|
||||||
element.onmouseenter = async function () {
|
element.onmouseenter = async function () {
|
||||||
this.style.backgroundColor = "blue";
|
this.style.backgroundColor = "blue";
|
||||||
@@ -28,14 +26,12 @@ setEventListeners(remove, async () => {
|
|||||||
method: "DELETE"
|
method: "DELETE"
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
alert(`Remove unsuccessful. ${response.status}`);
|
|
||||||
throw new Error(`Response status: ${response.status}`);
|
throw new Error(`Response status: ${response.status}`);
|
||||||
} else {
|
} else {
|
||||||
window.location.href = "/app";
|
window.location.href = "/app";
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(`Remove unsuccessful. ${error.message}`);
|
alert(`Remove unsuccessful. ${error.message}`);
|
||||||
console.error(error.message);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -58,20 +54,20 @@ setEventListeners(commit, async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
alert(`Edit unsuccessful. ${response.status}`);
|
|
||||||
throw new Error(`Response status: ${response.status}`);
|
throw new Error(`Response status: ${response.status}`);
|
||||||
} else {
|
} else {
|
||||||
window.location.href = "/app";
|
window.location.href = "/app";
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(`Edit unsuccessful. ${error.message}`);
|
alert(`Edit unsuccessful. ${error.message}`);
|
||||||
console.error(error.message);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
alert("Nothing to commit.");
|
alert("Nothing to commit.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
column_options = JSON.parse(column_options);
|
||||||
|
|
||||||
for (let i = 1; i < sql_row[1].cells.length; i++) {
|
for (let i = 1; i < sql_row[1].cells.length; i++) {
|
||||||
let opts = column_options[sql_row[0].cells[i].textContent];
|
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 () {
|
sql_row[1].cells[i].firstChild.onchange = async function () {
|
||||||
if (this.selectedIndex) {
|
if (this.selectedIndex) {
|
||||||
console.log(this);
|
|
||||||
this.parentElement.style.backgroundColor = "blue";
|
this.parentElement.style.backgroundColor = "blue";
|
||||||
changes++;
|
changes++;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ const download = document.getElementById("download");
|
|||||||
const logout = document.getElementById("logout");
|
const logout = document.getElementById("logout");
|
||||||
const add = document.getElementById("add");
|
const add = document.getElementById("add");
|
||||||
|
|
||||||
const sql_rows = sql_table.rows;
|
|
||||||
|
|
||||||
function setEventListeners(element, cb) {
|
function setEventListeners(element, cb) {
|
||||||
element.onmouseenter = async function () {
|
element.onmouseenter = async function () {
|
||||||
this.style.backgroundColor = "blue";
|
this.style.backgroundColor = "blue";
|
||||||
@@ -56,6 +54,8 @@ setEventListeners(logout, () => {
|
|||||||
window.location.href = `${window.location.protocol}//logout@${window.location.host}/`;
|
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++) {
|
for (let i = 1; i < sql_rows.length; i++) {
|
||||||
setEventListeners(sql_rows[i], () => {
|
setEventListeners(sql_rows[i], () => {
|
||||||
window.location.href = `/app/edit?element=${sql_rows[i].cells[0].innerText}`;
|
window.location.href = `/app/edit?element=${sql_rows[i].cells[0].innerText}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user