Add dismissible performance warning for large collections with persistence
This commit is contained in:
@@ -20,9 +20,9 @@
|
|||||||
|
|
||||||
{% include 'exam_notes.html' %}
|
{% include 'exam_notes.html' %}
|
||||||
{% if casesdetails|length > 20 %}
|
{% 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.
|
<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>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
@@ -164,4 +164,25 @@
|
|||||||
</div>
|
</div>
|
||||||
</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 %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user