From eae2698dde36bdc6f33ebefc5f88b77762fc3c87 Mon Sep 17 00:00:00 2001
From: Vermaas <vermaas@astron.nl>
Date: Mon, 1 May 2023 17:14:41 +0200
Subject: [PATCH] add separate multi plots button in validation screen

---
 atdb/logs/atdb.log                            | 20 +++++++++++++++++++
 atdb/taskdatabase/services/algorithms.py      | 10 +++++-----
 .../taskdatabase/validation/tasks.html        |  9 +++++++--
 atdb/taskdatabase/urls.py                     |  2 +-
 atdb/taskdatabase/views.py                    |  6 +++---
 5 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/atdb/logs/atdb.log b/atdb/logs/atdb.log
index 0622ae99..cc8e195e 100644
--- a/atdb/logs/atdb.log
+++ b/atdb/logs/atdb.log
@@ -2,3 +2,23 @@ logging[14/Apr/2023 14:17:24,827] unsupported operand type(s) for +=: 'NoneType'
 [14/Apr/2023 14:17:24,828] task 25485 - (regular) - 146233 has no plots, skipped.
 [14/Apr/2023 14:17:26,041] unsupported operand type(s) for +=: 'NoneType' and 'str'
 [14/Apr/2023 14:17:26,042] task 25485 - (regular) - 146233 has no plots, skipped.
+[01/May/2023 17:07:12,510] unsupported operand type(s) for &: 'bool' and 'str'
+[01/May/2023 17:07:12,512] task 25485 - (regular) - 146233 has no plots, skipped.
+[01/May/2023 17:07:17,635] unsupported operand type(s) for &: 'bool' and 'str'
+[01/May/2023 17:07:17,635] task 25485 - (regular) - 146233 has no plots, skipped.
+[01/May/2023 17:07:28,708] unsupported operand type(s) for &: 'bool' and 'str'
+[01/May/2023 17:07:28,709] unsupported operand type(s) for &: 'bool' and 'str'
+[01/May/2023 17:07:28,709] unsupported operand type(s) for &: 'bool' and 'str'
+[01/May/2023 17:07:28,718] task 25485 - (regular) - 146233 has no plots, skipped.
+[01/May/2023 17:07:28,718] task 25485 - (regular) - 146233 has no plots, skipped.
+[01/May/2023 17:07:28,718] task 25484 - (regular) - 146232 has no plots, skipped.
+[01/May/2023 17:07:29,725] unsupported operand type(s) for &: 'bool' and 'str'
+[01/May/2023 17:07:29,725] task 25484 - (regular) - 146232 has no plots, skipped.
+[01/May/2023 17:07:30,279] unsupported operand type(s) for &: 'bool' and 'str'
+[01/May/2023 17:07:30,279] task 25484 - (regular) - 146232 has no plots, skipped.
+[01/May/2023 17:07:30,718] unsupported operand type(s) for &: 'bool' and 'str'
+[01/May/2023 17:07:30,718] task 25484 - (regular) - 146232 has no plots, skipped.
+[01/May/2023 17:07:47,382] unsupported operand type(s) for &: 'bool' and 'str'
+[01/May/2023 17:07:47,382] task 25485 - (regular) - 146233 has no plots, skipped.
+[01/May/2023 17:07:48,568] unsupported operand type(s) for &: 'bool' and 'str'
+[01/May/2023 17:07:48,569] task 25485 - (regular) - 146233 has no plots, skipped.
diff --git a/atdb/taskdatabase/services/algorithms.py b/atdb/taskdatabase/services/algorithms.py
index d55848d5..61c31d77 100644
--- a/atdb/taskdatabase/services/algorithms.py
+++ b/atdb/taskdatabase/services/algorithms.py
@@ -680,7 +680,7 @@ def unique_values_for_aggregation_key(queryset, aggregation_key):
     return list(map(lambda x: x[aggregation_key], queryset.values(aggregation_key).distinct()))
 
 
-def add_plots(task, token, translation, results):
+def add_plots(task, token, translation, results, expand_image="False"):
     # keep a temporary list of filenames to check uniqueness
     plot_files = []
 
@@ -699,7 +699,7 @@ def add_plots(task, token, translation, results):
 
             url = surl.replace(translation[0], translation[1])
 
-            if basename.endswith('png'):
+            if basename.endswith('png') and expand_image=="True":
 
                 # retrieve the url and add the binary data to the html
                 response = requests.get(url)
@@ -735,7 +735,7 @@ def add_plots(task, token, translation, results):
     return results
 
 
-def construct_inspectionplots(task,source='task_id'):
+def construct_inspectionplots(task, expand_image="False", source='task_id'):
 
     # translate the path to a url
     try:
@@ -750,7 +750,7 @@ def construct_inspectionplots(task,source='task_id'):
     if source == 'task_id':
         results = "<h4>Inspection Plots and Summary Logs</h4>"
         results += "<p>Clicking a link will redirect to SURF SARA in a new browser window. </p>"
-        results = add_plots(task, token, translation, results)
+        results = add_plots(task, token, translation, results, expand_image)
 
     elif source == 'sas_id':
         sas_id = task.sas_id
@@ -767,7 +767,7 @@ def construct_inspectionplots(task,source='task_id'):
 
             try:
                 results += '<tr style="background-color:#7EB1C4"><td colspan="3"><b>Task ' + str(task.id) + '</b></td></tr>'
-                results = add_plots(task,token,translation,results)
+                results = add_plots(task, token, translation, results, expand_image)
 
             except Exception as error:
                 logger.error(error)
diff --git a/atdb/taskdatabase/templates/taskdatabase/validation/tasks.html b/atdb/taskdatabase/templates/taskdatabase/validation/tasks.html
index cb47196b..d89f7fa7 100644
--- a/atdb/taskdatabase/templates/taskdatabase/validation/tasks.html
+++ b/atdb/taskdatabase/templates/taskdatabase/validation/tasks.html
@@ -18,10 +18,15 @@
                     {% if task.has_plots %}
                     <td>
                         <a class="open-modal btn btn-primary btn-sm"
-                         href="{% url 'inspection-plots-sasid' task.id my_tasks.number %}"
-                         data-popup-url="{% url 'inspection-plots-sasid' task.id my_tasks.number %}">
+                         data-popup-url="{% url 'inspection-plots-sasid' task.id False %}">
                           <img src="{% static 'taskdatabase/surfsara.jpg' %}" height="20" alt="inspection plots">
                         </a>&nbsp;
+
+                        <a class="open-modal btn btn-warning btn-sm"
+                         data-popup-url="{% url 'inspection-plots-sasid' task.id True %}">
+                            <i class="fas fa-images"></i>
+                        </a>&nbsp;
+
                     </td>
                     {% else %}
                         <td>-</td>
diff --git a/atdb/taskdatabase/urls.py b/atdb/taskdatabase/urls.py
index 16c5316e..221d39ac 100644
--- a/atdb/taskdatabase/urls.py
+++ b/atdb/taskdatabase/urls.py
@@ -30,7 +30,7 @@ urlpatterns = [
     path('annotate_quality_sasid/<int:id>', views.AnnotateQualitySasId, name='annotate-quality-sasid'),
     path('annotate_quality_sasid/<int:id>/<page>', views.AnnotateQualitySasId, name='annotate-quality-sasid'),
     path('show_inspectionplots/<int:id>/<page>', views.ShowInspectionPlots, name='inspection-plots'),
-    path('show_inspectionplots_sasid/<int:id>/<page>', views.ShowInspectionPlotsSasId, name='inspection-plots-sasid'),
+    path('show_inspectionplots_sasid/<int:id>/<expand_image>', views.ShowInspectionPlotsSasId, name='inspection-plots-sasid'),
 
     path('show_summary/<int:id>/<page>', views.ShowSummarySasId, name='summary'),
 
diff --git a/atdb/taskdatabase/views.py b/atdb/taskdatabase/views.py
index fc8ce497..a64eea07 100644
--- a/atdb/taskdatabase/views.py
+++ b/atdb/taskdatabase/views.py
@@ -643,17 +643,17 @@ def ShowInspectionPlots(request, id=0, page=0):
     task = Task.objects.get(id=id)
 
     # convert the path to a url
-    plots_html = algorithms.construct_inspectionplots(task, source='task_id')
+    plots_html = algorithms.construct_inspectionplots(task, source='task_id', expand_image=True)
 
     return render(request, "taskdatabase/validation/inspection_plots.html", {'task': task, 'my_plots': plots_html})
 
 
-def ShowInspectionPlotsSasId(request, id=0, page=0):
+def ShowInspectionPlotsSasId(request, id=0, expand_image="False"):
     # a GET means that the form should be presented to be filled in
     task = Task.objects.get(id=id)
 
     # convert the path to a url
-    plots_html = algorithms.construct_inspectionplots(task, source='sas_id')
+    plots_html = algorithms.construct_inspectionplots(task, expand_image, source='sas_id')
 
     return render(request, "taskdatabase/validation/inspection_plots.html", {'task': task, 'my_plots': plots_html})
 
-- 
GitLab