Add dismissible performance warning for large collections with persistence

This commit is contained in:
Ross
2026-02-09 12:45:46 +00:00
parent add7a1cf38
commit 08c3558861
+23 -2
View File
@@ -20,9 +20,9 @@
{% include 'exam_notes.html' %}
{% if casesdetails|length > 20 %}
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<div id="collection-warning-{{ collection.pk }}" class="alert alert-warning alert-dismissible fade show" role="alert">
<strong>Performance warning:</strong> This collection contains {{ casesdetails|length }} cases — in some situations this may adversely affect performance, all features will still work but page loading may be slower. Consider splitting into smaller collections if performance is an issue.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
<button id="collection-warning-close-{{ collection.pk }}" type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endif %}
@@ -164,4 +164,25 @@
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
try {
var pk = '{{ collection.pk }}';
var key = 'collection_warning_dismissed_' + pk;
var alertEl = document.getElementById('collection-warning-' + pk);
if (!alertEl) return;
if (localStorage.getItem(key) === '1') {
alertEl.remove();
return;
}
var btn = document.getElementById('collection-warning-close-' + pk);
if (btn) {
btn.addEventListener('click', function() {
try { localStorage.setItem(key, '1'); } catch (e) { /* ignore */ }
});
}
} catch (e) { console.warn('collection warning persistence error', e); }
});
</script>
{% endblock %}