From f6b78f93eb718b0894a38c8dc0350c508811ec15 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 5 May 2026 07:14:51 +0200 Subject: [PATCH] fix: show sanitized phone details in sag contact search results --- VERSION | 2 +- app/modules/sag/templates/detail.html | 30 +++++++++++++++++++--- app/modules/sag/templates/detail_v3.html | 32 ++++++++++++++++++------ app/modules/search/backend/router.py | 18 +++++++++---- 4 files changed, 66 insertions(+), 16 deletions(-) diff --git a/VERSION b/VERSION index 0a58e8e..b1a306a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.92 +2.2.93 diff --git a/app/modules/sag/templates/detail.html b/app/modules/sag/templates/detail.html index 0e7a77d..6296e1e 100644 --- a/app/modules/sag/templates/detail.html +++ b/app/modules/sag/templates/detail.html @@ -4766,11 +4766,35 @@ resultsDiv.innerHTML = '
Ingen kontakter fundet
'; } else { resultsDiv.innerHTML = contacts.map(c => ` + ${(() => { + const clean = (v) => { + if (v === null || v === undefined) return ''; + const s = String(v).trim(); + if (!s || s.toLowerCase() === 'null' || s.toLowerCase() === 'none') return ''; + return s; + }; + const firstName = clean(c.first_name); + const lastName = clean(c.last_name); + const fullName = [firstName, lastName].filter(Boolean).join(' ') || `Kontakt #${c.id}`; + const email = clean(c.email); + const company = clean(c.user_company); + const phones = Array.from(new Set([ + clean(c.mobile) ? `Mobil: ${clean(c.mobile)}` : '', + clean(c.phone) ? `Telefon: ${clean(c.phone)}` : '', + clean(c.user_company_phone) ? `Firma: ${clean(c.user_company_phone)}` : '' + ].filter(Boolean))); + + return `
- ${c.first_name} ${c.last_name} -
${c.email || ''} ${c.user_company ? '(' + c.user_company + ')' : ''}
+ onclick="addContact(${caseId}, ${c.id}, '${fullName.replace(/'/g, "\\'")}')"> + ${fullName} +
${[email, company ? '(' + company + ')' : ''].filter(Boolean).join(' ')}
+
+ ${phones.join(' · ') || 'Intet telefonnummer'} +
+ `; + })()} `).join(''); } } catch (err) { diff --git a/app/modules/sag/templates/detail_v3.html b/app/modules/sag/templates/detail_v3.html index 6bb73f3..87ab25f 100644 --- a/app/modules/sag/templates/detail_v3.html +++ b/app/modules/sag/templates/detail_v3.html @@ -5263,17 +5263,35 @@ resultsDiv.innerHTML = '
Ingen kontakter fundet
'; } else { resultsDiv.innerHTML = contacts.map(c => ` + ${(() => { + const clean = (v) => { + if (v === null || v === undefined) return ''; + const s = String(v).trim(); + if (!s || s.toLowerCase() === 'null' || s.toLowerCase() === 'none') return ''; + return s; + }; + const firstName = clean(c.first_name); + const lastName = clean(c.last_name); + const fullName = [firstName, lastName].filter(Boolean).join(' ') || `Kontakt #${c.id}`; + const email = clean(c.email); + const company = clean(c.user_company); + const phones = Array.from(new Set([ + clean(c.mobile) ? `Mobil: ${clean(c.mobile)}` : '', + clean(c.phone) ? `Telefon: ${clean(c.phone)}` : '', + clean(c.user_company_phone) ? `Firma: ${clean(c.user_company_phone)}` : '' + ].filter(Boolean))); + + return `
- ${c.first_name} ${c.last_name} -
${c.email || ''} ${c.user_company ? '(' + c.user_company + ')' : ''}
+ onclick="addContact(${caseId}, ${c.id}, '${fullName.replace(/'/g, "\\'")}')"> + ${fullName} +
${[email, company ? '(' + company + ')' : ''].filter(Boolean).join(' ')}
- ${Array.from(new Set([ - c.mobile ? `Mobil: ${c.mobile}` : '', - c.phone ? `Telefon: ${c.phone}` : '' - ].filter(Boolean))).join(' · ') || 'Intet telefonnummer'} + ${phones.join(' · ') || 'Intet telefonnummer'}
+ `; + })()} `).join(''); } } catch (err) { diff --git a/app/modules/search/backend/router.py b/app/modules/search/backend/router.py index 9c49f16..9f07392 100644 --- a/app/modules/search/backend/router.py +++ b/app/modules/search/backend/router.py @@ -26,7 +26,7 @@ async def search_customers(q: str = Query(..., min_length=2)): async def search_contacts(q: str = Query(..., min_length=2)): """ Autocomplete search for contacts. - Returns list of {id, first_name, last_name, email, phone, mobile, user_company} + Returns list of {id, first_name, last_name, email, phone, mobile, user_company, user_company_phone} Supports: first name, last name, email, combined "Fornavn Efternavn", phone, mobile. """ sql = """ @@ -34,9 +34,9 @@ async def search_contacts(q: str = Query(..., min_length=2)): c.id, c.first_name, c.last_name, - c.email, - c.phone, - c.mobile, + NULLIF(NULLIF(TRIM(c.email), ''), 'null') AS email, + NULLIF(NULLIF(TRIM(c.phone), ''), 'null') AS phone, + NULLIF(NULLIF(TRIM(c.mobile), ''), 'null') AS mobile, ( SELECT cu.name FROM contact_companies cc @@ -44,7 +44,15 @@ async def search_contacts(q: str = Query(..., min_length=2)): WHERE cc.contact_id = c.id ORDER BY cc.is_primary DESC NULLS LAST, cc.id ASC LIMIT 1 - ) AS user_company + ) AS user_company, + ( + SELECT NULLIF(NULLIF(TRIM(COALESCE(cu.mobile_phone, cu.phone)), ''), 'null') + FROM contact_companies cc + JOIN customers cu ON cu.id = cc.customer_id + WHERE cc.contact_id = c.id + ORDER BY cc.is_primary DESC NULLS LAST, cc.id ASC + LIMIT 1 + ) AS user_company_phone FROM contacts c WHERE c.first_name ILIKE %s