From 5989046b53fc9fc8538b87a7bd95a89f5d3abd09 Mon Sep 17 00:00:00 2001 From: Falko Date: Fri, 17 Jul 2026 12:44:13 +0200 Subject: [PATCH] =?UTF-8?q?Erweiterte=20Werte=20=C3=BCbernehmen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- public/index.html | 24 +++++++++++++++--------- public/index.js | 9 ++++++++- server.js | 16 ++++++++++++++-- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index bdd7244..5b4f47c 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "dev": "node --env-file=.env server.js & sleep 1 && xdg-open http://localhost:3000", "dev:dry": "node server.js & sleep 1 && xdg-open http://localhost:3000", "start": "node --env-file=.env server.js", - "prod": "NODE_ENV=production node --env-file=.env server.js" + "prod": "NODE_ENV=production node --env-file=.env server.js", + "stop": "pkill -f 'node --env-file=.env server.js' || true" }, "engines": { "node": ">=20" diff --git a/public/index.html b/public/index.html index e7f4c67..0ccd8fa 100644 --- a/public/index.html +++ b/public/index.html @@ -20,20 +20,26 @@ + placeholder="z. B. K-10042 oder Müller">
- @@ -48,7 +54,7 @@
2 Anliegen
- + diff --git a/public/index.js b/public/index.js index 8344816..b838311 100644 --- a/public/index.js +++ b/public/index.js @@ -7,6 +7,7 @@ const advancedToggle = document.getElementById("advancedToggle"); const advancedFields = document.getElementById("advancedFields"); const fieldToggleButtons = Array.from(document.querySelectorAll(".field-toggle")); + const applyExtraValuesToggle = document.getElementById("applyExtraValues"); const customerChip = document.getElementById("customerChip"); const chipNumber = document.getElementById("chipNumber"); const chipName = document.getElementById("chipName"); @@ -86,6 +87,9 @@ appendHighlighted(numberSpan, customer.number, currentQuery); const nameSpan = document.createElement("span"); appendHighlighted(nameSpan, customer.name, currentQuery); + if (customer.extraMatches && customer.extraMatches.length > 0) { + nameSpan.appendChild(document.createTextNode(` (${customer.extraMatches.join(", ")})`)); + } item.appendChild(numberSpan); item.appendChild(nameSpan); item.addEventListener("click", () => selectCustomer(customer)); @@ -117,7 +121,10 @@ function selectCustomer(customer) { selectedCustomer = customer; chipNumber.textContent = customer.number; - chipName.textContent = customer.name; + const useExtraValues = applyExtraValuesToggle.checked && customer.extraMatches && customer.extraMatches.length > 0; + chipName.textContent = useExtraValues + ? `${customer.name} (${customer.extraMatches.join(", ")})` + : customer.name; customerChip.classList.add("visible"); searchWrap.style.display = "none"; closeSuggestions(); diff --git a/server.js b/server.js index b01e09b..2b3f79e 100644 --- a/server.js +++ b/server.js @@ -81,8 +81,16 @@ function searchCustomers(query, extraFields, limit) { } const haystack = haystackParts.join(" ").toLocaleLowerCase("de-DE"); if (!words.every((word) => haystack.includes(word))) continue; + + // Werte aller ausgewählten erweiterten Felder, unabhängig davon, welches Wort den Treffer ausgelöst hat + const extraMatches = extraFields + .map((field) => customer[field]) + .filter((value) => value !== undefined && value !== null && String(value).trim() !== "") + .map((value) => String(value)); + + const match = { number: customer.number, name: customer.name, extraMatches }; const isStartMatch = words.every((word) => haystack.startsWith(word) || haystack.includes(` ${word}`)); - if (isStartMatch) { startMatches.push(customer); } else { partialMatches.push(customer); } + if (isStartMatch) { startMatches.push(match); } else { partialMatches.push(match); } if (startMatches.length >= limit) break; } @@ -136,7 +144,11 @@ app.get("/api/customers", (request, response) => { .map((field) => field.trim()) .filter((field) => ADVANCED_SEARCH_FIELDS.includes(field)); const matches = searchCustomers(query, extraFields, 12); - const results = matches.map((customer) => ({ number: customer.number, name: customer.name })); + const results = matches.map((customer) => ({ + number: customer.number, + name: customer.name, + extraMatches: customer.extraMatches, + })); return response.json({ results, total: customers.length }); });