From 51593f982e40861d2a27760832c8d1c8b2a1bb43 Mon Sep 17 00:00:00 2001
From: Nico Vermaas <vermaas@astron.nl>
Date: Fri, 12 Mar 2021 16:48:24 +0100
Subject: [PATCH] bonus link in dashboard

---
 atdb/atdb/static/taskdatabase/style.css       |  4 +++
 atdb/taskdatabase/services/algorithms.py      | 36 +++++++++++++------
 .../static/taskdatabase/style.css             |  4 +++
 .../templates/dashboard/dashboard.html        |  2 ++
 atdb/taskdatabase/views.py                    |  2 +-
 5 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/atdb/atdb/static/taskdatabase/style.css b/atdb/atdb/static/taskdatabase/style.css
index e293d1a7..d63af60c 100644
--- a/atdb/atdb/static/taskdatabase/style.css
+++ b/atdb/atdb/static/taskdatabase/style.css
@@ -13,6 +13,10 @@ TD {
   color: blue;
 }
 
+.active {
+  background-color: lemonchiffon;
+}
+
 .error,.failed,.staging_failed,.processed_failed {
   color: red;
   font-weight: bold;
diff --git a/atdb/taskdatabase/services/algorithms.py b/atdb/taskdatabase/services/algorithms.py
index 109ccd81..4b2e0f65 100644
--- a/atdb/taskdatabase/services/algorithms.py
+++ b/atdb/taskdatabase/services/algorithms.py
@@ -198,20 +198,15 @@ def aggregate_resources_tasks():
     return workflow_results
 
 
-def convert_aggregation_to_html():
-
-    # gather the data
-    workflow_results = aggregate_resources_tasks()
-    records = aggregate_resources_logs()
-
-    # layout the data
+def convert_aggregation_to_html(request):
 
     # --- Progress of tasks per active workflow ---
+    workflow_results = aggregate_resources_tasks()
     results_tasks = "<p>Progress of tasks per (active) workflow</p>"
     header = "<th>Workflow</th>"
     for status in settings.ALL_STATUSSES:
         header += "<th>" + status + "</th>"
-    results_tasks += header + "<th>active</th><th>total</th>"
+    results_tasks += header + '<th class="active">active</th><th>total</th>'
 
     for workflow_result in workflow_results:
 
@@ -219,18 +214,37 @@ def convert_aggregation_to_html():
         values = "<td><b>" + str(workflow_result['id'])+" - "+workflow_result['name'] + "</b></td>"
         for key in d:
              percentage = round(int(d[key]) / int(workflow_result['nr_of_tasks']) * 100)
-             values += "<td>" + str(percentage) + "% ("+str(d[key])+")</td>"
+
+             # distinguish active statusses
+             style = ""
+             if key in settings.ACTIVE_STATUSSES or key=='active':
+                style = "active"
+
+             # bonus: add a query link
+             query = "?status="+key+ "&workflow="+str(workflow_result['id'])
+             url = request.build_absolute_uri('/atdb/tasks')+query
+             link = '<a href="' + url + '" target="_blank">' + str(d[key]) + "</a>"
+             values += "<td class=" + style + ">" + str(percentage) + "% (" + link + ")</td>"
+             #values += "<td class="+style+">" + str(percentage) + "% ("+str(d[key])+")</td>"
              #values += "<td>" + str(d[key]) + "</td>"
 
         results_tasks += "<tr>" + values + "</tr>"
 
     results_tasks = "<tbody>" + results_tasks + "</tbody>"
 
+
     # --- logentries ---
+    log_records = aggregate_resources_logs()
     results_logs = ""
-    for record in records:
+
+    for record in log_records:
+        # distinguish active statusses
+        style = ""
+        if record['status'] in settings.ACTIVE_STATUSSES:
+            style = "active"
+
         line = "<tr><td><b>" + record['name'] + "</b></td>"\
-               '<td class="' + record['status'] + '" >' + record['status'] + \
+               '<td class="' + style + '" >' + record['status'] + \
                "</td><td>" + str(record['cpu_cycles']) + \
                "</td><td>" + str(record['wall_clock_time']) + "</td><tr>"
         results_logs += line
diff --git a/atdb/taskdatabase/static/taskdatabase/style.css b/atdb/taskdatabase/static/taskdatabase/style.css
index 6a61c007..9919c705 100644
--- a/atdb/taskdatabase/static/taskdatabase/style.css
+++ b/atdb/taskdatabase/static/taskdatabase/style.css
@@ -13,6 +13,10 @@ TD {
   color: blue;
 }
 
+.active {
+  background-color: lemonchiffon;
+}
+
 .error,.failed,.staging_failed,.processed_failed {
   color: red;
   font-weight: bold;
diff --git a/atdb/taskdatabase/templates/dashboard/dashboard.html b/atdb/taskdatabase/templates/dashboard/dashboard.html
index 2d36ed2a..0282275d 100644
--- a/atdb/taskdatabase/templates/dashboard/dashboard.html
+++ b/atdb/taskdatabase/templates/dashboard/dashboard.html
@@ -8,10 +8,12 @@
   <div class="card">
        <div class="card-body">
            <h4>Dashboard</h4>
+           &nbsp;
            <table class="table table-striped">
                {{ results_tasks | safe }}
            </table>
 
+            &nbsp;
            <table class="table table-striped">
                <p>Resources used per step per active workflow</p>
               <th>Workflow</th><th>Status</th><th>CPU cycles</th><th>wall clock time</th>
diff --git a/atdb/taskdatabase/views.py b/atdb/taskdatabase/views.py
index 187daffe..568e2364 100644
--- a/atdb/taskdatabase/views.py
+++ b/atdb/taskdatabase/views.py
@@ -253,7 +253,7 @@ def ShowConfig(request):
 
 def ShowDashboard(request):
     # gather the results
-    results_tasks,results_logs = algorithms.convert_aggregation_to_html()
+    results_tasks,results_logs = algorithms.convert_aggregation_to_html(request)
     return render(request, "dashboard/dashboard.html", {'results_tasks': results_tasks, 'results_logs': results_logs})
 
 
-- 
GitLab