This commit is contained in:
oliver
2026-08-03 09:24:56 -03:00
parent d9f3c8a747
commit 738e44e1a0
3 changed files with 33 additions and 19 deletions
+21 -16
View File
@@ -488,7 +488,7 @@ function switchTab(tab) {
}); });
if (tab === "batches") { if (tab === "batches") {
batchStateFilter.value = "!done"; batchStateFilter.value = "!done";
sortField = "name"; sortField = "batch_id";
sortAsc = true; sortAsc = true;
loadBatches(); loadBatches();
} }
@@ -523,15 +523,11 @@ async function loadBatches() {
const data = await parseJson(res); const data = await parseJson(res);
console.log("[HR] Batches response:", data); console.log("[HR] Batches response:", data);
// Response can be { data: [...] } or an array wrapping it // Response is a flat array of batch objects
if (data && Array.isArray(data.data)) { if (Array.isArray(data)) {
allBatches = data;
} else if (data && Array.isArray(data.data)) {
allBatches = data.data; allBatches = data.data;
} else if (
Array.isArray(data) &&
data.length > 0 &&
Array.isArray(data[0].data)
) {
allBatches = data[0].data;
} else { } else {
allBatches = []; allBatches = [];
} }
@@ -544,6 +540,14 @@ async function loadBatches() {
} }
} }
// Description can be a string or an object like { en_US: "...", de_DE: "..." }
function getDescription(desc) {
if (!desc) return "";
if (typeof desc === "string") return desc;
// Prefer de_DE, fall back to en_US, then any value
return desc.de_DE || desc.en_US || Object.values(desc)[0] || "";
}
function sortBatches(field) { function sortBatches(field) {
if (sortField === field) { if (sortField === field) {
sortAsc = !sortAsc; sortAsc = !sortAsc;
@@ -568,10 +572,10 @@ function renderBatches() {
// Text search // Text search
if (!query) return true; if (!query) return true;
const desc = getDescription(b.description);
return ( return (
(b.name && b.name.toLowerCase().includes(query)) || (b.batch_id && b.batch_id.toLowerCase().includes(query)) ||
(b.description && b.description.toLowerCase().includes(query)) || (desc && desc.toLowerCase().includes(query))
(b.carrier && b.carrier.toLowerCase().includes(query))
); );
}); });
@@ -590,7 +594,7 @@ function renderBatches() {
if (filtered.length === 0) { if (filtered.length === 0) {
batchList.innerHTML = batchList.innerHTML =
'<tr><td colspan="4" class="batch-empty">No batches match</td></tr>'; '<tr><td colspan="5" class="batch-empty">No batches match</td></tr>';
return; return;
} }
@@ -598,10 +602,11 @@ function renderBatches() {
.map( .map(
(b) => ` (b) => `
<tr class="${b.state === "done" ? "batch-row-done" : ""}"> <tr class="${b.state === "done" ? "batch-row-done" : ""}">
<td><span class="batch-charge-cell">${esc(b.name)}</span></td> <td><span class="batch-charge-cell">${esc(b.batch_id)}</span></td>
<td><span class="batch-name-cell">${esc(b.description || "")}</span></td> <td><span class="batch-name-cell">${esc(getDescription(b.description))}</span></td>
<td><span class="batch-carrier-cell">${esc(b.carrier || "")}</span></td>
<td><span class="batch-state-cell batch-state-${esc(b.state || "open")}">${esc(b.state || "open")}</span></td> <td><span class="batch-state-cell batch-state-${esc(b.state || "open")}">${esc(b.state || "open")}</span></td>
<td><span class="batch-num-cell">${esc(String(b.gepackt ?? ""))}</span></td>
<td><span class="batch-num-cell">${esc(String(b.ungepackt ?? ""))}</span></td>
</tr>`, </tr>`,
) )
.join(""); .join("");
+4 -3
View File
@@ -250,17 +250,16 @@
<table class="batch-table"> <table class="batch-table">
<thead> <thead>
<tr> <tr>
<th>Charge</th>
<th <th
class="batch-th-sort" class="batch-th-sort"
onclick="sortBatches('name')" onclick="sortBatches('batch_id')"
> >
Name Name
<span class="sort-arrow" id="sortArrowName" <span class="sort-arrow" id="sortArrowName"
></span ></span
> >
</th> </th>
<th>Transport</th> <th>Beschreibung</th>
<th <th
class="batch-th-sort" class="batch-th-sort"
onclick="sortBatches('state')" onclick="sortBatches('state')"
@@ -271,6 +270,8 @@
id="sortArrowState" id="sortArrowState"
></span> ></span>
</th> </th>
<th>Send</th>
<th>Offen</th>
</tr> </tr>
</thead> </thead>
<tbody id="batchList"> <tbody id="batchList">
+8
View File
@@ -1169,6 +1169,14 @@ tbody td {
color: #92400e; color: #92400e;
} }
.batch-num-cell {
font-size: 13px;
font-weight: 600;
color: var(--text);
text-align: center;
white-space: nowrap;
}
.batch-empty { .batch-empty {
text-align: center; text-align: center;
color: var(--text-muted); color: var(--text-muted);