Refactored codebase & auth bug fix

This commit is contained in:
2025-05-15 13:33:58 +03:00
parent 36226dbbac
commit eeda1b500d
13 changed files with 424 additions and 347 deletions
+52
View File
@@ -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;
}
+67
View File
@@ -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"));
}
};
}
+102
View File
@@ -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--;
}
};
}
+59
View File
@@ -0,0 +1,59 @@
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, () => {
window.location.href = `${window.location.protocol}//logout@${window.location.host}/`;
});
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}`;
});
}