From 5e0068d49047a854540bad4cfaa1f9e0f492c29d Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 16 Nov 2025 22:55:59 +0000 Subject: [PATCH] Implement case search functionality and enhance case addition UI in collection view --- .../atlas/add_case_to_collection.html | 23 +++++++----------- .../atlas/partials/case_search_results.html | 20 ++++++++++++++++ .../atlas/partials/case_search_widget.html | 11 +++++++++ atlas/urls.py | 1 + atlas/views.py | 24 +++++++++++++++++++ 5 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 atlas/templates/atlas/partials/case_search_results.html create mode 100644 atlas/templates/atlas/partials/case_search_widget.html diff --git a/atlas/templates/atlas/add_case_to_collection.html b/atlas/templates/atlas/add_case_to_collection.html index db5cba63..6d6524f2 100644 --- a/atlas/templates/atlas/add_case_to_collection.html +++ b/atlas/templates/atlas/add_case_to_collection.html @@ -1,14 +1,9 @@ - - This form allows you to add an existing case to the collection. You may find it easier to do this from the individual case pages or the case overview view which allows you to add multiple cases at once. -
- {% csrf_token %} - - - - -
-
\ No newline at end of file +
+

Add an existing case to this collection. You can also use the case overview view to add multiple cases at once: case overview.

+ + {% include 'atlas/partials/case_search_widget.html' %} + +
+ +
+
\ No newline at end of file diff --git a/atlas/templates/atlas/partials/case_search_results.html b/atlas/templates/atlas/partials/case_search_results.html new file mode 100644 index 00000000..92eac272 --- /dev/null +++ b/atlas/templates/atlas/partials/case_search_results.html @@ -0,0 +1,20 @@ +{% if cases and cases.exists %} +
+ {% for case in cases %} +
+
+
{{ case.title }}
+
{% if case.description %}{{ case.description|truncatechars:100 }}{% endif %}
+
+ +
+ {% csrf_token %} + + +
+
+ {% endfor %} +
+{% else %} +
No cases found.
+{% endif %} diff --git a/atlas/templates/atlas/partials/case_search_widget.html b/atlas/templates/atlas/partials/case_search_widget.html new file mode 100644 index 00000000..b334c1a5 --- /dev/null +++ b/atlas/templates/atlas/partials/case_search_widget.html @@ -0,0 +1,11 @@ +
+ + + +
+
diff --git a/atlas/urls.py b/atlas/urls.py index 97be9f60..4eace63f 100755 --- a/atlas/urls.py +++ b/atlas/urls.py @@ -34,6 +34,7 @@ urlpatterns = [ path("author/", views.author_list, name="author_list"), path("case/", views.CaseView.as_view(), name="case_view"), path("collection//add_case", views.add_case_to_collection, name="add_case_to_collection"), + path("collection/case_search", views.case_search, name="case_search"), path("collection/", views.CollectionView.as_view(), name="collection_view"), path("collection/user", views.user_collections, name="user_collections"), path("uploads", views.user_uploads, name="user_uploads"), diff --git a/atlas/views.py b/atlas/views.py index 578acef1..1a737218 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -1182,6 +1182,30 @@ def add_case_to_collection(request, collection_id): ) +@login_required +def case_search(request): + # HTMX endpoint for searching cases available to the user + if not request.htmx: + return Http404 + + q = request.GET.get("q", "").strip() + collection_id = request.GET.get("collection") + collection = None + if collection_id: + try: + collection = CaseCollection.objects.get(pk=collection_id) + except CaseCollection.DoesNotExist: + collection = None + + qs = get_cases_available_to_user(request.user, collection=collection) + if q: + qs = qs.filter(title__icontains=q) + + cases = qs.order_by("title")[:30] + + return render(request, "atlas/partials/case_search_results.html", {"cases": cases, "collection": collection}) + + @login_required def user_uploads_series(request, series_instance_uid: str): # We don't restrict to teh uploading user here. Should we?