From d8eecaf690242320d13d5d42443a6dc79328ed9f Mon Sep 17 00:00:00 2001 From: TheMadBug Date: Wed, 20 Sep 2023 11:34:30 +1000 Subject: [PATCH] Have triage editing automatically update key parts of the web page --- .../classification/discordance_report.html | 27 ++++++++++--------- .../discordance_report_triage_detail.html | 23 ++++++++++++++++ .../classification/discordance_reports.html | 2 +- .../views/discordance_report_triage_view.py | 16 ++++++++++- uicore/views/ajax_form_view.py | 3 ++- .../static_files/default_static/js/global.js | 12 ++++++--- 6 files changed, 65 insertions(+), 18 deletions(-) diff --git a/classification/templates/classification/discordance_report.html b/classification/templates/classification/discordance_report.html index 9d4995f24..01e678a65 100644 --- a/classification/templates/classification/discordance_report.html +++ b/classification/templates/classification/discordance_report.html @@ -141,19 +141,22 @@

Step 2: Multi-Lab Discussion

{% if data.is_pending_concordance %}

There are outstanding pending changes for this discordance. When labs re-submit with the agreed changes the discordance should be resolved. There is likely no need for further discussion.

{% endif %} {% else %} {% if data.is_user_editable and data.report.resolution is empty %} - {% if data.row_data.next_step == "D" %} -
-
Discussion
-
-
This Discordance Report has not yet been discussed.
+ {% comment %}Warning this is duplicated in discordance_report_triage_detail.html{% endcomment %} +
+ {% if data.row_data.next_step == "D" %} +
+
Discussion
+
+
This Discordance Report has not yet been discussed.
+
+
- -
- {% else %} -
This discordance isn't marked as ready for discussion - see triages. Click here to discuss anyway.
- {% endif %} + {% else %} +
This discordance isn't marked as ready for discussion - see triages. Click here to discuss anyway.
+ {% endif %} +
{% else %}
This Discordance Report was not discussed.
{% endif %} diff --git a/classification/templates/classification/discordance_report_triage_detail.html b/classification/templates/classification/discordance_report_triage_detail.html index ed8b31723..bc10bfb97 100644 --- a/classification/templates/classification/discordance_report_triage_detail.html +++ b/classification/templates/classification/discordance_report_triage_detail.html @@ -19,6 +19,11 @@ {% end_if_user_can_edit %} {% endif %} {% include "uicore/messages/messages.html" %} + {% if saved %} + +
Click here to refresh now
or keep editing. +
+ {% endif %} {% else %}
{{ triage.lab }} {% admin_link triage %}
{% if form %} @@ -58,6 +63,24 @@ {% labelled label="Note" %}{{ triage.note }}{% endlabelled %} {% endif %}
{% include "uicore/messages/messages.html" %}
+ {% if saved %} + {% comment %}Warning this is duplicated in discordance_report.html{% endcomment %} +
+ {% if next_step == "D" %} +
+
Discussion
+
+
This Discordance Report has not yet been discussed.
+
+ +
+ {% else %} +
This discordance isn't marked as ready for discussion - see triages. Click here to discuss anyway.
+ {% endif %} +
+ {% endif %}
{% if not read_only %} {% if_user_can_edit triage %} diff --git a/classification/templates/classification/discordance_reports.html b/classification/templates/classification/discordance_reports.html index 9dfb5d85a..798ed953a 100644 --- a/classification/templates/classification/discordance_reports.html +++ b/classification/templates/classification/discordance_reports.html @@ -41,7 +41,7 @@ Download Discordance Reports -

If you edit a triage of a discordance below, the discordance will only change tab after reloading this page.

+

If you edit a triage of a discordance below, the discordance will only change tab after reloading this page.

Loading Discordances
diff --git a/classification/views/discordance_report_triage_view.py b/classification/views/discordance_report_triage_view.py index e8166fcf1..2bc2f9396 100644 --- a/classification/views/discordance_report_triage_view.py +++ b/classification/views/discordance_report_triage_view.py @@ -6,7 +6,9 @@ from django.shortcuts import get_object_or_404 from classification.models import DiscordanceReportTriage, DiscordanceReportTriageStatus +from classification.models.discordance_models_utils import DiscordanceReportRowData from library.log_utils import log_saved_form +from snpdb.lab_picker import LabPickerData from uicore.views.ajax_form_view import AjaxFormView, LazyRender @@ -42,11 +44,22 @@ class DiscordanceReportTriageView(AjaxFormView[DiscordanceReportTriage]): @classmethod def lazy_render(cls, obj: DiscordanceReportTriage, context: Optional[Dict] = None) -> LazyRender: + def dynamic_context_gen(request): + if context and context.get("saved") == True: + user = request.user + discordance_report = obj.discordance_report + discordance_report_row = DiscordanceReportRowData(discordance_report=discordance_report, perspective=LabPickerData.for_user(user)) + return { + "next_step": discordance_report_row.next_step, + "report": discordance_report + } + return LazyRender( template_name="classification/discordance_report_triage_detail.html", core_object=obj, core_object_name="triage", - static_context=context + static_context=context, + dynamic_context=dynamic_context_gen ) def get(self, request, discordance_report_triage_id: int, *args, **kwargs): @@ -75,6 +88,7 @@ def handle(self, request, discordance_report_triage_id: int): form.save() log_saved_form(form) messages.add_message(request, level=messages.SUCCESS, message="Discordance triage saved successfully") + context["saved"] = True saved = True else: context["form"] = form diff --git a/uicore/views/ajax_form_view.py b/uicore/views/ajax_form_view.py index d1ca370b6..8925e60b3 100644 --- a/uicore/views/ajax_form_view.py +++ b/uicore/views/ajax_form_view.py @@ -63,7 +63,8 @@ def _context(self, request): """ use_context = (self.static_context or {}).copy() if dynamic_context := self.dynamic_context: - use_context.update(dynamic_context(request)) + if dynamic_context_output := dynamic_context(request): + use_context.update(dynamic_context_output) if self.core_object_name not in use_context: use_context[self.core_object_name] = self.core_object return use_context diff --git a/variantgrid/static_files/default_static/js/global.js b/variantgrid/static_files/default_static/js/global.js index 1fba06864..9161b19a0 100644 --- a/variantgrid/static_files/default_static/js/global.js +++ b/variantgrid/static_files/default_static/js/global.js @@ -98,7 +98,10 @@ function enhanceAndMonitor() { }}, {test: '[data-replace]', func: (node) => { - $(node.attr('data-replace')).html(node); + let selector = node.attr('data-replace'); + console.log(`Found replace for ${selector}`) + node.detach(); + $(selector).html(node); node.fadeIn(); }}, @@ -472,6 +475,7 @@ function enhanceAndMonitor() { for (let processor of processors) { if (node.is(processor.test)) { if (processor.func) { + let element = node[0]; processor.func(node); } else { return; // no function means it's some weird element type we should stay away from @@ -517,7 +521,7 @@ function enhanceAndMonitor() { mutationsList.forEach((mutation) => { let mutatedNode = $(mutation.target); // leave 3rd party wigets alone - for (selector of ignoreSelectors) { + for (let selector of ignoreSelectors) { if (mutatedNode.parents(selector).length) { return; } @@ -559,7 +563,9 @@ function cardToModal(content) { console.log("DID NOT FIND modal") } if (content.find('.auto-close-modal').length) { - content.closest('.modal').modal('hide'); + window.setTimeout(() => { + content.closest('.modal').modal('hide'); + }, 1); } }