\n`;
sql_header.splice(0, 1);
if (row) {
var column_options = {};
for (const key of sql_header) {
table_header += `
${key}
\n`;
const select_distinct = db.prepare(`
SELECT DISTINCT ${key}
FROM ${db_conf.table_name};
`);
values = select_distinct.all();
for (v of values) {
if (column_options[key] == null) {
column_options[key] = Object.values(v);
} else {
column_options[key] = column_options[key].concat(Object.values(v));
}
}
}
var table_data = "";
const sql_row_values = Object.values(row);
table_data += `
\n`;
for (let i = 1; i < sql_row_values.length; i++) {
table_data += `
\n`;
}
table_data += "
";
res.render("add", {
page_title: app_conf.name,
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),
table_header: table_header,
table_data: table_data
});
} else {
errorPageRenderer(res, "❓", "The database is empty.");
}
} catch (error) {
logger.error(error.message);
}
});
router.get("/edit", async (req, res) => {
if (req.query["element"]) {
try {
const select_get = db.prepare(`SELECT * FROM ${db_conf.table_name} WHERE Name='${req.query["element"]}';`);
const row = select_get.get();
if (row) {
const sql_header = Object.keys(row);
var table_header = `
${sql_header[0]}
\n`;
sql_header.splice(0, 1);
var column_options = {};
for (const key of sql_header) {
table_header += `
${key}
\n`;
const select_distinct = db.prepare(`
SELECT DISTINCT ${key}
FROM ${db_conf.table_name}
WHERE ${key} IS NOT NULL
AND ${key} NOT IN (
SELECT ${key}
FROM ${db_conf.table_name}
WHERE Name='${req.query["element"]}'
AND ${key} IS NOT NULL);
`);
values = select_distinct.all();
for (v of values) {
if (column_options[key] == null) {
column_options[key] = Object.values(v);
} else {
column_options[key] = column_options[key].concat(Object.values(v));
}
}
}
var table_data = "";
const sql_row_values = Object.values(row);
table_data += `
${sql_row_values[0]}
\n`;
sql_row_values.splice(0, 1);
for (const v of sql_row_values) {
table_data += `