Refactor case navigation: consolidate previous and next links into a reusable partial for improved maintainability and consistency across templates
This commit is contained in:
@@ -3,15 +3,7 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<div>
|
{% include 'atlas/partials/_viewing_case_as_part_of_collection.html' %}
|
||||||
{% if previous %}
|
|
||||||
<a href="{% url 'atlas:collection_case_details' collection.id previous.id %}">Previous question</a>
|
|
||||||
{% endif %}
|
|
||||||
Viewing question as part of collection: <a href="{% url 'atlas:collection_detail' collection.id %}">{{collection.name}}</a> [{{case_number|add:1}}/{{collection_length}}]
|
|
||||||
{% if next %}
|
|
||||||
<a href="{% url 'atlas:collection_case_details' collection.id next.id %}">Next question</a>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h2>Case: <a href="{% url 'atlas:case_detail' case_detail.case.pk %}">{{case_detail.case.title}}</a></h2>
|
<h2>Case: <a href="{% url 'atlas:case_detail' case_detail.case.pk %}">{{case_detail.case.title}}</a></h2>
|
||||||
|
|
||||||
|
|||||||
@@ -4,26 +4,7 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
{% include 'atlas/partials/_viewing_case_as_part_of_collection.html' with casedetail=case_detail %}
|
||||||
<div>
|
|
||||||
{% if previous %}
|
|
||||||
<a class="btn btn-outline-secondary btn-sm" href="{% url 'atlas:collection_case_priors' collection.id previous.id %}">← Previous</a>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
<div class="text-center">
|
|
||||||
<div class="h6 mb-0">Viewing question in collection</div>
|
|
||||||
<div>
|
|
||||||
<a href="{% url 'atlas:collection_detail' collection.id %}" class="fw-bold">{{collection.name}}</a>
|
|
||||||
<small class="text-muted">[{{case_number|add:1}}/{{collection_length}}]</small>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
{% if next %}
|
|
||||||
<a class="btn btn-outline-secondary btn-sm" href="{% url 'atlas:collection_case_priors' collection.id next.id %}">Next →</a>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<h2 class="mb-3">Case: <a href="{% url 'atlas:case_detail' case_detail.case.pk %}" class="text-decoration-none">{{case_detail.case.title}}</a></h2>
|
<h2 class="mb-3">Case: <a href="{% url 'atlas:case_detail' case_detail.case.pk %}" class="text-decoration-none">{{case_detail.case.title}}</a></h2>
|
||||||
|
|
||||||
@@ -39,6 +20,10 @@
|
|||||||
<div class="row g-3">
|
<div class="row g-3">
|
||||||
{% for case, added, relation, visibility in available_priors %}
|
{% for case, added, relation, visibility in available_priors %}
|
||||||
{% include 'atlas/partials/_prior_card.html' with case=case added=added relation=relation visibility=visibility case_detail=case_detail collection=collection %}
|
{% include 'atlas/partials/_prior_card.html' with case=case added=added relation=relation visibility=visibility case_detail=case_detail collection=collection %}
|
||||||
|
{% empty %}
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="alert alert-info">No available prior cases found for the case.</div>
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -4,17 +4,7 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<div>
|
{% include 'atlas/partials/_viewing_case_as_part_of_collection.html' with casedetail=case_detail %}
|
||||||
|
|
||||||
{% if previous %}
|
|
||||||
<a href="{% url 'atlas:collection_case_questions' collection.id previous.id %}">Previous question</a>
|
|
||||||
{% endif %}
|
|
||||||
Viewing question as part of collection: <a href="{% url 'atlas:collection_detail' collection.id %}">{{collection.name}}</a> [{{case_number|add:1}}/{{collection_length}}]
|
|
||||||
{% if next %}
|
|
||||||
<a href="{% url 'atlas:collection_case_questions' collection.id next.id %}">Next question</a>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<h2>Case: <a href="{% url 'atlas:case_detail' case_detail.case.pk %}">{{case_detail.case.title}}</a></h2>
|
<h2>Case: <a href="{% url 'atlas:case_detail' case_detail.case.pk %}">{{case_detail.case.title}}</a></h2>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
<div id="prior-card-{{case.id}}" class="col-12 col-md-6 col-lg-4" data-case="{{case.id}}">
|
<div id="prior-card-{{case.id}}" class="col-12 col-md-6 col-lg-4" data-case="{{case.id}}">
|
||||||
<div class="card h-100 shadow-sm {% if added %}border-success{% else %}border-secondary{% endif %}">
|
<div class="card h-100 shadow-sm {% if added %}border-success{% else %}border-secondary{% endif %}">
|
||||||
<div class="card-body d-flex flex-column">
|
<div class="card-body d-flex flex-column">
|
||||||
|
{% if error %}
|
||||||
|
<div class="alert alert-danger py-1 mb-2 small">{{ error }}</div>
|
||||||
|
{% endif %}
|
||||||
<div class="d-flex justify-content-between align-items-start mb-2">
|
<div class="d-flex justify-content-between align-items-start mb-2">
|
||||||
<h5 class="card-title mb-0">{{case.title}}</h5>
|
<h5 class="card-title mb-0">{{case.title}}</h5>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||||
|
<div>
|
||||||
|
{% if previous %}
|
||||||
|
<a class="btn btn-outline-secondary btn-sm" href="{% url nav_link_view collection.id previous.id %}">← Previous</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="text-center">
|
||||||
|
<div class="h6 mb-0">Viewing as part of a collection</div>
|
||||||
|
<div>
|
||||||
|
<a href="{% url 'atlas:collection_detail' collection.id %}" class="fw-bold">{{collection.name}}</a>
|
||||||
|
<small class="text-muted">[{{case_number|add:1}}/{{collection_length}}]</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{% if next %}
|
||||||
|
<a class="btn btn-outline-secondary btn-sm" href="{% url nav_link_view collection.id next.id %}">Next →</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-1">
|
||||||
|
{% include "atlas/collection_detail.html#casedetails-management-links" %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<div class="mt-2 small text-muted">
|
<div class="mt-2 small text-muted">
|
||||||
{% if casedetail.case.series.count == 0 %}
|
{% if casedetail.case.series.count == 0 %}
|
||||||
<span class="text-warning">No series attached</span>
|
<span class="text-warning">This case has no series / stacks attached</span>
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ casedetail.case.series.count }} series
|
{{ casedetail.case.series.count }} series
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -18,22 +18,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
{% if collection %}
|
{% if collection %}
|
||||||
<div class="text-end mb-2">
|
{% include 'atlas/partials/_viewing_case_as_part_of_collection.html' with nav_link_view="atlas:collection_case_view" %}
|
||||||
<div class="small text-muted">Collection</div>
|
|
||||||
<div class="mb-1">
|
|
||||||
{% include "atlas/collection_detail.html#casedetails-management-links" %}
|
|
||||||
</div>
|
|
||||||
<div class="small">
|
|
||||||
{% if previous %}
|
|
||||||
<a class="me-2" href="{% url 'atlas:collection_case_view' collection.id case_number|add:-1 %}">Previous</a>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
Viewing question as part of a collection: <a href="{% url 'atlas:collection_detail' collection.id %}">{{ collection.name }}</a>
|
|
||||||
[{{ case_number|add:1 }} / {{ collection_length }}]
|
|
||||||
{% if next %}
|
|
||||||
<a class="ms-2" href="{% url 'atlas:collection_case_view' collection.id case_number|add:1 %}">Next</a>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
|
|||||||
+23
-5
@@ -2763,6 +2763,7 @@ def collection_case_priors(request, exam_id, case_id):
|
|||||||
if request.htmx:
|
if request.htmx:
|
||||||
# Ensure we can render the updated single-card partial and return it so HTMX
|
# Ensure we can render the updated single-card partial and return it so HTMX
|
||||||
# can swap the card on the client side.
|
# can swap the card on the client side.
|
||||||
|
|
||||||
if "remove" in request.POST:
|
if "remove" in request.POST:
|
||||||
prior_pk = request.POST["remove"]
|
prior_pk = request.POST["remove"]
|
||||||
try:
|
try:
|
||||||
@@ -2792,10 +2793,27 @@ def collection_case_priors(request, exam_id, case_id):
|
|||||||
return HttpResponse(html)
|
return HttpResponse(html)
|
||||||
elif "prior_case_id" in request.POST:
|
elif "prior_case_id" in request.POST:
|
||||||
if not request.POST.get("relation"):
|
if not request.POST.get("relation"):
|
||||||
return HttpResponse(
|
# Return the card partial with an inline error so HTMX will replace
|
||||||
"You need to enter text to describe the relationship between the cases",
|
# the card and display the validation message rather than navigating
|
||||||
status=400,
|
# to a new page or showing a plain text response.
|
||||||
|
prior_case = Case.objects.get(pk=request.POST.get("prior_case_id"))
|
||||||
|
added = False
|
||||||
|
relation = request.POST.get("relation", "")
|
||||||
|
visibility = request.POST.get("prior_visibility", "AL")
|
||||||
|
html = render_to_string(
|
||||||
|
"atlas/partials/_prior_card.html",
|
||||||
|
{
|
||||||
|
"case": prior_case,
|
||||||
|
"added": added,
|
||||||
|
"relation": relation,
|
||||||
|
"visibility": visibility,
|
||||||
|
"case_detail": case_detail,
|
||||||
|
"collection": collection,
|
||||||
|
"error": "You need to enter text to describe the relationship between the cases",
|
||||||
|
},
|
||||||
|
request=request,
|
||||||
)
|
)
|
||||||
|
return HttpResponse(html)
|
||||||
prior_case = Case.objects.get(pk=request.POST["prior_case_id"])
|
prior_case = Case.objects.get(pk=request.POST["prior_case_id"])
|
||||||
p, created = CasePrior.objects.get_or_create(
|
p, created = CasePrior.objects.get_or_create(
|
||||||
case_detail=case_detail, prior_case=prior_case
|
case_detail=case_detail, prior_case=prior_case
|
||||||
@@ -3576,8 +3594,8 @@ def collection_case_view(request, pk, case_number):
|
|||||||
|
|
||||||
series_list = case.series.all().prefetch_related("images", "examination", "plane")
|
series_list = case.series.all().prefetch_related("images", "examination", "plane")
|
||||||
|
|
||||||
previous = case_number > 0
|
previous = collection.get_previous_case(casedetail.case)
|
||||||
next = case_number < (case_count - 1)
|
next = collection.get_next_case(casedetail.case)
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
|
|||||||
Reference in New Issue
Block a user