diff --git a/apis_ontology/static/scripts/show_popup.js b/apis_ontology/static/scripts/show_popup.js new file mode 100644 index 0000000..ff63d4e --- /dev/null +++ b/apis_ontology/static/scripts/show_popup.js @@ -0,0 +1,17 @@ +function showPopup(recordId, renderStyle) { + renderStyle = "tei"; + fetch(`/apis/excerpts/${recordId}/${renderStyle}`) + .then(response => response.text()) + .then(data => { + // Display the data in the popup + document.getElementById('popupContent').innerHTML = data; + document.getElementById('popupModal').style.display = 'block'; + }) + .catch(error => { + console.error('Error fetching dynamic content:', error); + }); +} + +function closePopup() { + document.getElementById('popupModal').style.display = 'none'; +} diff --git a/apis_ontology/tables.py b/apis_ontology/tables.py index 1f76c5a..f2da236 100644 --- a/apis_ontology/tables.py +++ b/apis_ontology/tables.py @@ -153,22 +153,8 @@ def render_tei_refs(self, value): links = [] for xml_id in xml_ids: true_id = xml_id.replace('"', "").replace("xml:id=", "").strip() - excerpt_xml = "" # Fallback blank excerpt - try: - excerpt_xml = Excerpts.objects.get(xml_id=true_id).xml_content - - except Excerpts.DoesNotExist: - logger.error( - "Could not find excerpt with id %s in the database.", true_id - ) - except Exception as e: - logger.error(repr(e)) - encoded_excerpt_xml = escape( - excerpt_xml.replace("'", "\\'").replace("\n", "") - ) - # Append the link with the onclick event links.append( - f'{true_id}' + f"""{true_id}""" ) return mark_safe("
".join(links)) diff --git a/apis_ontology/templates/apis_core/apis_entities/abstractentity_detail.html b/apis_ontology/templates/apis_core/apis_entities/abstractentity_detail.html index 891171a..eb9a585 100644 --- a/apis_ontology/templates/apis_core/apis_entities/abstractentity_detail.html +++ b/apis_ontology/templates/apis_core/apis_entities/abstractentity_detail.html @@ -11,6 +11,8 @@ {% endblock col-zero %} {% block col-one %} +{% include "excerpts/popup.html" %} +

Relations

{% related_entity_types as related_entity_types %}
diff --git a/apis_ontology/templates/apis_entities/partials/entity_relations_multiple_cards.html b/apis_ontology/templates/apis_entities/partials/entity_relations_multiple_cards.html index d21cc30..678b705 100644 --- a/apis_ontology/templates/apis_entities/partials/entity_relations_multiple_cards.html +++ b/apis_ontology/templates/apis_entities/partials/entity_relations_multiple_cards.html @@ -3,6 +3,7 @@ {% load apiscore %} {% load relationsng %} {% load relations %} +{% include "excerpts/popup.html" %}

Relations

{% related_entity_types as related_entity_types %} diff --git a/apis_ontology/templates/excerpts/popup.html b/apis_ontology/templates/excerpts/popup.html new file mode 100644 index 0000000..a732f37 --- /dev/null +++ b/apis_ontology/templates/excerpts/popup.html @@ -0,0 +1,19 @@ + + + diff --git a/apis_ontology/urls.py b/apis_ontology/urls.py index 432ba9a..5864d5e 100644 --- a/apis_ontology/urls.py +++ b/apis_ontology/urls.py @@ -1,3 +1,4 @@ +from apis_ontology.views import ExcerptsView from django.contrib import admin from django.urls import include, path from django.views.generic import TemplateView @@ -13,6 +14,11 @@ path("accounts/", include("django.contrib.auth.urls")), path("entity//", GetEntityGeneric.as_view(), name="GetEntityGenericRoot"), path("", TemplateView.as_view(template_name="base.html")), + path( + "apis/excerpts///", + ExcerptsView.as_view(), + name="excerpts_view", + ), ] urlpatterns += staticfiles_urlpatterns() diff --git a/apis_ontology/views.py b/apis_ontology/views.py new file mode 100644 index 0000000..191ef2b --- /dev/null +++ b/apis_ontology/views.py @@ -0,0 +1,19 @@ +from django.http import HttpResponse +from django.views import View +from django.shortcuts import get_object_or_404 +from .models import Excerpts + + +class ExcerptsView(View): + def get(self, request, xml_id, render_style, *args, **kwargs): + print("You are here!") + record = get_object_or_404(Excerpts, xml_id=xml_id) + + # Generate dynamic content based on link_type + if render_style == "tei": + # TODO: render correctly with xslt + content = f"{record.xml_content}" + else: + content = f"{record.xml_content}" + + return HttpResponse(content)