Initial commit
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
module.exports = {
|
||||
name: "CRTelemetry",
|
||||
port: 80,
|
||||
logger: {
|
||||
level: "info",
|
||||
error_path: "/app/logs/error.log",
|
||||
full_path: "/app/logs/combined.log"
|
||||
},
|
||||
timestamp_format: "HH:mm:ss DD-MM-YYYY",
|
||||
views_directory: "/app/views/",
|
||||
temp_directory: "/app/temp/",
|
||||
web_paths: {
|
||||
css: "/app/src/css",
|
||||
js: "/app/src/javascript"
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
path: "./sensors.db",
|
||||
table_name: "sensors"
|
||||
};
|
||||
@@ -0,0 +1,52 @@
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #121212;
|
||||
|
||||
font-family: "Ubuntu", sans-serif;
|
||||
font-weight: 500;
|
||||
font-style: normal;
|
||||
|
||||
-webkit-user-select: none; /* Safari */
|
||||
-ms-user-select: none; /* IE 10 and IE 11 */
|
||||
user-select: none; /* Standard syntax */
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: white;
|
||||
background-color: blue;
|
||||
}
|
||||
|
||||
.control_div {
|
||||
color: #ececec;
|
||||
background-color: #272727;
|
||||
margin: 3px;
|
||||
padding: 5px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.main_div {
|
||||
color: #ececec;
|
||||
background-color: #272727;
|
||||
margin: 3px;
|
||||
padding: 5px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
table {
|
||||
background-color: #272727;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
border: 2px solid black;
|
||||
padding-top: 5px;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
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";
|
||||
}
|
||||
commit.onmouseleave = async function () {
|
||||
this.style.backgroundColor = "";
|
||||
};
|
||||
commit.onmousedown = async function () {
|
||||
this.style.backgroundColor = "red";
|
||||
};
|
||||
commit.ondblclick = async function () {
|
||||
if (sql_row[1].cells[0].firstChild.value) {
|
||||
let req_body = {};
|
||||
|
||||
for (let i = 1; i < sql_row[1].cells.length; i++) {
|
||||
req_body[sql_row[0].cells[i].firstChild.textContent] = sql_row[1].cells[i].firstChild[sql_row[1].cells[i].firstChild.selectedIndex].text;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/app/add?element=${sql_row[1].cells[0].firstChild.value}`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(req_body),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Response status: ${response.status}`);
|
||||
} else {
|
||||
this.style.backgroundColor = "blue";
|
||||
window.location.href = "/app";
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (let i = 1; i < sql_row[1].cells.length; i++) {
|
||||
let opts = column_options[sql_row[0].cells[i].textContent];
|
||||
|
||||
if (opts != null) {
|
||||
for (o of opts) {
|
||||
sql_row[1].cells[i].firstChild.add(new Option(o, o));
|
||||
}
|
||||
}
|
||||
|
||||
sql_row[1].cells[i].firstChild.oncontextmenu = async function (ev) {
|
||||
ev.preventDefault();
|
||||
let new_value = prompt("Enter a new value");
|
||||
if ((new_value != null) && (new_value != "")) {
|
||||
if (this[this.length - 1].value != "custom") {
|
||||
this.add(new Option(new_value, "custom"));
|
||||
} else {
|
||||
this[this.length - 1].text = new_value;
|
||||
}
|
||||
this.value = "custom";
|
||||
this.dispatchEvent(new Event("change"));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
const sql_table = document.getElementById("sql_table");
|
||||
const sql_row = sql_table.rows;
|
||||
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";
|
||||
};
|
||||
element.onmouseleave = async function () {
|
||||
this.style.backgroundColor = "";
|
||||
};
|
||||
element.onmousedown = async function () {
|
||||
this.style.backgroundColor = "red";
|
||||
};
|
||||
element.ondblclick = async function () {
|
||||
cb();
|
||||
this.style.backgroundColor = "blue";
|
||||
};
|
||||
}
|
||||
|
||||
setEventListeners(remove, async () => {
|
||||
try {
|
||||
const response = await fetch(`/app/remove?element=${sql_row[1].cells[0].firstChild.textContent}`, {
|
||||
method: "DELETE"
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Response status: ${response.status}`);
|
||||
} else {
|
||||
window.location.href = "/app";
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
}
|
||||
});
|
||||
|
||||
setEventListeners(commit, async () => {
|
||||
if (changes) {
|
||||
let req_body = {};
|
||||
|
||||
for (let i = 1; i < sql_row[1].cells.length; i++) {
|
||||
if (sql_row[1].cells[i].firstChild.selectedIndex != 0) {
|
||||
req_body[sql_row[0].cells[i].firstChild.textContent] = sql_row[1].cells[i].firstChild[sql_row[1].cells[i].firstChild.selectedIndex].text;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/app/edit?element=${sql_row[1].cells[0].firstChild.textContent}`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(req_body),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Response status: ${response.status}`);
|
||||
} else {
|
||||
window.location.href = "/app";
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (let i = 1; i < sql_row[1].cells.length; i++) {
|
||||
let opts = column_options[sql_row[0].cells[i].textContent];
|
||||
|
||||
if (opts != null) {
|
||||
for (o of opts) {
|
||||
sql_row[1].cells[i].firstChild.add(new Option(o, o));
|
||||
}
|
||||
}
|
||||
|
||||
sql_row[1].cells[i].firstChild.oncontextmenu = async function (ev) {
|
||||
ev.preventDefault();
|
||||
let new_value = prompt("Enter a new value");
|
||||
if ((new_value != null) && (new_value != "")) {
|
||||
if (this[this.length - 1].value != "custom") {
|
||||
this.add(new Option(new_value, "custom"));
|
||||
} else {
|
||||
this[this.length - 1].text = new_value;
|
||||
}
|
||||
this.value = "custom";
|
||||
this.dispatchEvent(new Event("change"));
|
||||
}
|
||||
};
|
||||
|
||||
sql_row[1].cells[i].firstChild.onchange = async function () {
|
||||
if (this.selectedIndex) {
|
||||
console.log(this);
|
||||
this.parentElement.style.backgroundColor = "blue";
|
||||
changes++;
|
||||
} else {
|
||||
this.parentElement.style.backgroundColor = "";
|
||||
changes--;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
const sql_table = document.getElementById("sql_table");
|
||||
const upload = document.getElementById("upload");
|
||||
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";
|
||||
};
|
||||
element.onmouseleave = async function () {
|
||||
this.style.backgroundColor = "";
|
||||
};
|
||||
element.onmousedown = async function () {
|
||||
this.style.backgroundColor = "red";
|
||||
};
|
||||
element.ondblclick = async function () {
|
||||
this.style.backgroundColor = "blue";
|
||||
cb();
|
||||
};
|
||||
}
|
||||
|
||||
setEventListeners(upload, async () => {
|
||||
const input = document.getElementById("file_input");
|
||||
const upload = (file) => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
fetch('/app/upload', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
}).then((response) => {
|
||||
location.reload();
|
||||
});
|
||||
}
|
||||
const onSelectFile = () => upload(input.files[0]);
|
||||
input.addEventListener('change', onSelectFile, false);
|
||||
input.click();
|
||||
});
|
||||
|
||||
setEventListeners(add, () => {
|
||||
window.location.href = "/app/add";
|
||||
});
|
||||
|
||||
setEventListeners(download, () => {
|
||||
window.location.href = "/app/download";
|
||||
});
|
||||
|
||||
setEventListeners(logout, () => {
|
||||
// fetch logout
|
||||
// check response type
|
||||
// redirect to auth
|
||||
});
|
||||
|
||||
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}`;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>
|
||||
<%= page_title %>
|
||||
</title>
|
||||
|
||||
<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 %>">
|
||||
<script src="<%= js_path %>" defer></script>
|
||||
<script defer>
|
||||
var column_options = '<%- column_options %>';
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="control_div">
|
||||
<label style="font-size: 200%;">CRTelemetry SQLite3</label>
|
||||
</div>
|
||||
<div class="main_div">
|
||||
<table id="sql_table" style="text-align: center;">
|
||||
<tr>
|
||||
<%- table_header %>
|
||||
</tr>
|
||||
<%- table_data %>
|
||||
</table>
|
||||
<div style="display: flex; flex-direction: row; justify-content: space-between;">
|
||||
<a href="/app"><span>🢀 </span>Return</a>
|
||||
<label id="commit" style="cursor: pointer;"><span>✅ </span>Commit</label>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>
|
||||
<%= page_title %>
|
||||
</title>
|
||||
|
||||
<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 %>">
|
||||
<script src="<%= js_path %>" defer></script>
|
||||
<script defer>
|
||||
var column_options = '<%- column_options %>';
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="control_div" style="display: flex; flex-direction: row; justify-content: space-between;">
|
||||
<label style="font-size: 200%;">CRTelemetry SQLite3</label>
|
||||
<div style="display: flex;align-items: center;">
|
||||
<label id="remove" style="cursor: pointer; margin-right: 10px;"><span>- </span>Remove</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="main_div">
|
||||
<table id="sql_table" style="text-align: center;">
|
||||
<tr>
|
||||
<%- table_header %>
|
||||
</tr>
|
||||
<%- table_data %>
|
||||
</table>
|
||||
<div style="display: flex; flex-direction: row; justify-content: space-between;">
|
||||
<a href="/app"><span>🢀 </span>Return</a>
|
||||
<label id="commit" style="cursor: pointer;"><span>✅ </span>Commit</label>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>
|
||||
<%= page_title %>
|
||||
</title>
|
||||
|
||||
<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%;'>CRTelemetry
|
||||
SQLite3</label>
|
||||
</div>
|
||||
<div class="main_div">
|
||||
<label style="font-size: 150%;">
|
||||
<span>
|
||||
<%- error_emoji %>
|
||||
</span>
|
||||
<%= error_message %>
|
||||
</label>
|
||||
<br>
|
||||
<a href="/app"><span>🢀 </span>Return</a>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>
|
||||
<%= page_title %>
|
||||
</title>
|
||||
|
||||
<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 %>">
|
||||
<script src="<%= js_path %>" defer></script>
|
||||
</head>
|
||||
|
||||
<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>
|
||||
<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>🡅 </span>Upload</label>
|
||||
<label id="download" style="cursor: pointer; margin-left: 10px; margin-right: 10px;"><span>🡇 </span>Download</label>
|
||||
<label id="logout" style="cursor: pointer; margin-left: 10px;"><span>🡄 </span>Logout</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="main_div">
|
||||
<table id="sql_table">
|
||||
<tr>
|
||||
<%- table_header %>
|
||||
</tr>
|
||||
<%- table_data %>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user