Skip to content

Commit

Permalink
Have triage editing automatically update key parts of the web page
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMadBug committed Sep 20, 2023
1 parent 5b17ecc commit d8eecaf
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 18 deletions.
27 changes: 15 additions & 12 deletions classification/templates/classification/discordance_report.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,22 @@ <h4>Step 2: Multi-Lab Discussion</h4>
{% if data.is_pending_concordance %}<p class="text-info mt-2">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.</p>{% endif %}
{% else %}
{% if data.is_user_editable and data.report.resolution is empty %}
{% if data.row_data.next_step == "D" %}
<div class="card">
<div class="card-header">Discussion</div>
<div class="card-body">
<div class="no-value">This Discordance Report has not yet been discussed.</div>
{% comment %}Warning this is duplicated in discordance_report_triage_detail.html{% endcomment %}
<div id="discordance-report-discussion">
{% if data.row_data.next_step == "D" %}
<div class="card">
<div class="card-header">Discussion</div>
<div class="card-body">
<div class="no-value">This Discordance Report has not yet been discussed.</div>
</div>
<div class="card-footer">
<a class="mt-2 btn btn-primary" href="{% url 'discordance_report_review' discordance_report_id=data.report.pk %}">Start Discordance Discussion</a>
</div>
</div>
<div class="card-footer">
<a class="mt-2 btn btn-primary" href="{% url 'discordance_report_review' discordance_report_id=data.report.pk %}">Start Discordance Discussion</a>
</div>
</div>
{% else %}
<div class="no-value">This discordance isn't marked as ready for discussion - see triages. <a class="hover-link" href="{% url 'discordance_report_review' discordance_report_id=data.report.pk %}">Click here to discuss anyway.</a></div>
{% endif %}
{% else %}
<div class="no-value">This discordance isn't marked as ready for discussion - see triages. <a class="hover-link" href="{% url 'discordance_report_review' discordance_report_id=data.report.pk %}">Click here to discuss anyway.</a></div>
{% endif %}
</div>
{% else %}
<div class="no-value">This Discordance Report was not discussed.</div>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
{% end_if_user_can_edit %}
{% endif %}
{% include "uicore/messages/messages.html" %}
{% if saved %}
<span data-replace="#reload-info">
<a href="#" onclick="location.reload()" class="hover-link"><br/><i class="fa-solid fa-clock-rotate-left"></i> Click here to refresh now</a> or keep editing.
</span>
{% endif %}
{% else %}
<div class="card-header">{{ triage.lab }} {% admin_link triage %}</div>
{% if form %}
Expand Down Expand Up @@ -58,6 +63,24 @@
{% labelled label="Note" %}{{ triage.note }}{% endlabelled %}
{% endif %}
<div class="container">{% include "uicore/messages/messages.html" %}</div>
{% if saved %}
{% comment %}Warning this is duplicated in discordance_report.html{% endcomment %}
<div data-replace="#discordance-report-discussion">
{% if next_step == "D" %}
<div class="card">
<div class="card-header">Discussion</div>
<div class="card-body">
<div class="no-value">This Discordance Report has not yet been discussed.</div>
</div>
<div class="card-footer">
<a class="mt-2 btn btn-primary" href="{% url 'discordance_report_review' report.pk %}">Start Discordance Discussion</a>
</div>
</div>
{% else %}
<div class="no-value">This discordance isn't marked as ready for discussion - see triages. <a class="hover-link" href="{% url 'discordance_report_review' report.pk %}">Click here to discuss anyway.</a></div>
{% endif %}
</div>
{% endif %}
</div>
{% if not read_only %}
{% if_user_can_edit triage %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<a href="{% url 'discordance_reports_download' dlab.lab_picker.selection %}" class="download-link">Download Discordance Reports</a>

<p class="mt-2 text-info">If you edit a triage of a discordance below, the discordance will only change tab after reloading this page.</p>
<p class="mt-2 text-info">If you edit a triage of a discordance below, the discordance will only change tab after reloading this page. <span id="reload-info"></span></p>

<div data-toggle="ajax" href="{% url 'discordance_reports_active_detail' dlab.lab_picker.selection %}" data-id="active-discordances">
<div class="loading-message">Loading Discordances</div>
Expand Down
16 changes: 15 additions & 1 deletion classification/views/discordance_report_triage_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion uicore/views/ajax_form_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions variantgrid/static_files/default_static/js/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}},

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit d8eecaf

Please sign in to comment.