diff --git a/app/modules/telefoni/templates/log.html b/app/modules/telefoni/templates/log.html
index 2782c5f..24edc0b 100644
--- a/app/modules/telefoni/templates/log.html
+++ b/app/modules/telefoni/templates/log.html
@@ -61,7 +61,7 @@
{% if initial_calls and initial_calls|length > 0 %}
{% for call in initial_calls %}
-
+
| {{ call.started_at or '-' }} |
{{ call.full_name or call.username or '-' }} |
{% if call.direction == 'outbound' %}Udgående{% else %}Indgående{% endif %} |
@@ -846,9 +846,28 @@ async function loadUsers() {
}
}
-async function loadCalls() {
+function hasExistingCallRows(tbody) {
+ return Boolean(tbody && tbody.querySelector('tr[data-call-id]'));
+}
+
+function hasActiveCallFilters() {
+ const userId = document.getElementById('filterUser')?.value;
+ const from = document.getElementById('filterFrom')?.value;
+ const to = document.getElementById('filterTo')?.value;
+ const withoutCase = document.getElementById('filterWithoutCase')?.checked;
+ return Boolean(userId || from || to || withoutCase);
+}
+
+async function loadCalls(options = {}) {
+ const preserveOnEmpty = Boolean(options.preserveOnEmpty);
+ const skipLoadingState = Boolean(options.skipLoadingState);
const tbody = document.getElementById('telefoniRows');
- tbody.innerHTML = '
| Indlæser... |
';
+ const hadRowsBeforeLoad = hasExistingCallRows(tbody);
+ const noActiveFilters = !hasActiveCallFilters();
+
+ if (!skipLoadingState) {
+ tbody.innerHTML = '| Indlæser... |
';
+ }
const userId = document.getElementById('filterUser').value;
const from = document.getElementById('filterFrom').value;
@@ -865,6 +884,10 @@ async function loadCalls() {
const res = await fetch('/api/v1/telefoni/calls?' + qs.toString(), { credentials: 'include' });
if (!res.ok) {
const t = await res.text();
+ if (preserveOnEmpty && hadRowsBeforeLoad && noActiveFilters) {
+ console.warn('Telefoni: bevarer SSR-rækker efter tom/fejlende auto-refresh');
+ return;
+ }
tbody.innerHTML = `| Fejl: ${escapeHtml(t)} |
`;
return;
}
@@ -872,6 +895,10 @@ async function loadCalls() {
telefoniCallMap.clear();
(rows || []).forEach(r => telefoniCallMap.set(Number(r.id), r));
if (!rows || rows.length === 0) {
+ if (preserveOnEmpty && hadRowsBeforeLoad && noActiveFilters) {
+ console.warn('Telefoni: API returnerede 0 rækker, bevarer eksisterende SSR-visning');
+ return;
+ }
tbody.innerHTML = '| Ingen opkald fundet |
';
return;
}
@@ -928,7 +955,7 @@ async function loadCalls() {
: 'Ingen sag');
return `
-
+
| ${escapeHtml(dateTxt)} |
${userTxt} |
${escapeHtml(dirTxt)} |
@@ -941,6 +968,10 @@ async function loadCalls() {
}).join('');
} catch (e) {
console.error('Failed loading calls', e);
+ if (preserveOnEmpty && hadRowsBeforeLoad && noActiveFilters) {
+ console.warn('Telefoni: bevarer SSR-rækker efter exception i auto-refresh');
+ return;
+ }
tbody.innerHTML = '
| Kunne ikke hente opkald |
';
}
}
@@ -1017,7 +1048,7 @@ document.addEventListener('DOMContentLoaded', async () => {
document.getElementById('filterFrom').addEventListener('change', loadCalls);
document.getElementById('filterTo').addEventListener('change', loadCalls);
document.getElementById('filterWithoutCase').addEventListener('change', loadCalls);
- await loadCalls();
+ await loadCalls({ preserveOnEmpty: true, skipLoadingState: true });
});
{% endblock %}