Workbench: backend target aktualisiert
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Station Config</title>
|
||||
|
||||
<link rel="stylesheet" href="/backend/handsontable/handsontable/dist/handsontable.full.min.css">
|
||||
<script src="/backend/handsontable/handsontable/dist/handsontable.full.min.js"></script>
|
||||
|
||||
<style>
|
||||
<meta charset="UTF-8">
|
||||
<title>Station Config</title>
|
||||
|
||||
<style>
|
||||
/* ===== BASE THEME (wie Workbench / HMI) ===== */
|
||||
:root{
|
||||
--bg:#0b1020;
|
||||
@@ -93,22 +90,40 @@ button:hover{
|
||||
filter:brightness(1.1);
|
||||
}
|
||||
|
||||
/* ===== HANDSONTABLE INTEGRATION ===== */
|
||||
#hot{
|
||||
flex:1;
|
||||
overflow:hidden;
|
||||
border-radius:14px;
|
||||
border:1px solid var(--border);
|
||||
}
|
||||
|
||||
.handsontable{
|
||||
background:transparent;
|
||||
}
|
||||
|
||||
.ht_master .wtHolder{
|
||||
background:transparent;
|
||||
}
|
||||
</style>
|
||||
#hot{
|
||||
flex:1;
|
||||
overflow:auto;
|
||||
border-radius:14px;
|
||||
border:1px solid var(--border);
|
||||
}
|
||||
|
||||
.config-table {
|
||||
width: 100%;
|
||||
min-width: 980px;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
}
|
||||
|
||||
.config-table th,
|
||||
.config-table td {
|
||||
padding: 9px 12px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.config-table input[type="text"] {
|
||||
width: 100%;
|
||||
min-width: 160px;
|
||||
padding: 7px 9px;
|
||||
}
|
||||
|
||||
.config-table input[type="checkbox"] {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="/backend/ios.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -414,73 +429,71 @@ function transformData(rawArray) {
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
3) Custom Renderer: boolean => Checkbox, sonst => Text
|
||||
*/
|
||||
function booleanOrTextRenderer(hotInstance, td, row, col, prop, value, cellProperties) {
|
||||
if (typeof value === "boolean") {
|
||||
// Standard-CheckboxRenderer => klickbare Checkbox
|
||||
Handsontable.renderers.CheckboxRenderer.apply(this, arguments);
|
||||
} else {
|
||||
// Andernfalls normaler Text
|
||||
Handsontable.renderers.TextRenderer.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
4) Handsontable initialisieren
|
||||
*/
|
||||
let hot;
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const container = document.getElementById('hot');
|
||||
// Start mit transformierten localData
|
||||
const transformedData = transformData(myDataRaw);
|
||||
|
||||
hot = new Handsontable(container, {
|
||||
data: transformedData,
|
||||
rowHeaders: true,
|
||||
colHeaders: [
|
||||
"code_nr",
|
||||
"Description",
|
||||
"code_wert",
|
||||
"Change by",
|
||||
"Changed Date",
|
||||
"used (checkbox)"
|
||||
],
|
||||
columns: [
|
||||
{
|
||||
data: "code_nr",
|
||||
type: "numeric",
|
||||
readOnly: true
|
||||
},
|
||||
{
|
||||
data: "description",
|
||||
type: "text",
|
||||
readOnly: true
|
||||
},
|
||||
{
|
||||
data: "code_wert",
|
||||
renderer: booleanOrTextRenderer
|
||||
},
|
||||
{
|
||||
data: "changedby",
|
||||
type: "text",
|
||||
readOnly: true
|
||||
},
|
||||
{
|
||||
data: "timestamp",
|
||||
type: "text",
|
||||
readOnly: true
|
||||
},
|
||||
{
|
||||
data: "used",
|
||||
renderer: booleanOrTextRenderer
|
||||
}
|
||||
],
|
||||
licenseKey: "non-commercial-and-evaluation"
|
||||
});
|
||||
|
||||
});
|
||||
let configRows = [];
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value ?? "")
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
function renderConfigTable(rows) {
|
||||
configRows = rows;
|
||||
const container = document.getElementById("hot");
|
||||
container.innerHTML = `
|
||||
<table class="config-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>code_nr</th>
|
||||
<th>Description</th>
|
||||
<th>code_wert</th>
|
||||
<th>Change by</th>
|
||||
<th>Changed Date</th>
|
||||
<th>used</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${rows.map((row, index) => `
|
||||
<tr>
|
||||
<td>${escapeHtml(row.code_nr)}</td>
|
||||
<td>${escapeHtml(row.description)}</td>
|
||||
<td>${renderValueCell(row, index)}</td>
|
||||
<td>${escapeHtml(row.changedby)}</td>
|
||||
<td>${escapeHtml(row.timestamp)}</td>
|
||||
<td><input type="checkbox" data-row="${index}" data-field="used" ${row.used ? "checked" : ""}></td>
|
||||
</tr>
|
||||
`).join("")}
|
||||
</tbody>
|
||||
</table>
|
||||
`;
|
||||
|
||||
container.querySelectorAll("input[data-row]").forEach(input => {
|
||||
input.addEventListener("change", updateConfigRow);
|
||||
input.addEventListener("input", updateConfigRow);
|
||||
});
|
||||
}
|
||||
|
||||
function renderValueCell(row, index) {
|
||||
if (typeof row.code_wert === "boolean") {
|
||||
return `<input type="checkbox" data-row="${index}" data-field="code_wert" ${row.code_wert ? "checked" : ""}>`;
|
||||
}
|
||||
return `<input type="text" data-row="${index}" data-field="code_wert" value="${escapeHtml(row.code_wert)}">`;
|
||||
}
|
||||
|
||||
function updateConfigRow(event) {
|
||||
const input = event.target;
|
||||
const rowIndex = Number(input.dataset.row);
|
||||
const field = input.dataset.field;
|
||||
configRows[rowIndex][field] = input.type === "checkbox" ? input.checked : input.value;
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const transformedData = transformData(myDataRaw);
|
||||
renderConfigTable(transformedData);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -522,9 +535,8 @@ function getConfig() {
|
||||
}
|
||||
});
|
||||
|
||||
// Neu transformieren & in Handsontable laden
|
||||
const newData = transformData(myDataRaw);
|
||||
hot.loadData(newData);
|
||||
const newData = transformData(myDataRaw);
|
||||
renderConfigTable(newData);
|
||||
|
||||
//alert("Daten gemerged & aktualisiert!");
|
||||
})
|
||||
@@ -555,9 +567,8 @@ function formatTimestampToYMDHMS(timestampNumber) {
|
||||
wandelt true => "USED" etc.
|
||||
=> sendet an '/backend/api/setStationConfig'
|
||||
*/
|
||||
function setConfig() {
|
||||
// 1) Daten aus Handsontable
|
||||
const allRows = hot.getSourceData();
|
||||
function setConfig() {
|
||||
const allRows = configRows;
|
||||
|
||||
// 2) Filtern: Nur used === true
|
||||
const usedRows = allRows.filter(row => row.used === true);
|
||||
|
||||
Reference in New Issue
Block a user