diff --git a/atdb/taskdatabase/services/algorithms.py b/atdb/taskdatabase/services/algorithms.py index 3c826d1b1679fa10a15c571e12b7591103e75aa2..92405952b7a7b1cbc212d5dd2c442ec8c79d674d 100644 --- a/atdb/taskdatabase/services/algorithms.py +++ b/atdb/taskdatabase/services/algorithms.py @@ -117,26 +117,32 @@ def convert_config_to_html(querylist): # aggregate information from the tasks table per workflow per status -def aggregate_resources_tasks(): - # NOTE: uncomment (or refactor) the lines with ### to only aggregate the data for active tasks +def aggregate_resources_tasks(selection): workflow_results = [] + my_workflows = [] # get all active tasks - ### active_tasks = Task.objects.filter(status__in=settings.ACTIVE_STATUSSES) + if 'active' in selection: + active_tasks = Task.objects.filter(status__in=settings.ACTIVE_STATUSSES) - # retrieve all unique workflows from the active tasks - ### active_workflows = active_tasks.values('workflow').distinct() + # retrieve all unique workflows from the active tasks + active_workflows = active_tasks.values('workflow').distinct() - all_workflows = Workflow.objects.all() + # construct the list of workflows (cheap) + for w in active_workflows: + try: + workflow = Workflow.objects.get(id = w['workflow']) + my_workflows.append(workflow) + except: + pass - # iterate through the filters and accumulate logentries - ### for w in all_workflows: - for workflow in all_workflows: - workflow_result = {} + else: + my_workflows = Workflow.objects.all() - # extract the workflow object (cheap) - ### workflow = Workflow.objects.get(id = w['workflow']) + # iterate through the workflows + for workflow in my_workflows: + workflow_result = {} # get the numbers for this workflow @@ -181,26 +187,30 @@ def aggregate_resources_tasks(): # aggregate information from the logentries table per workflow per status -def aggregate_resources_logs(): - # NOTE: uncomment (or refactor) the lines with ### to only aggregate the data for active tasks - +def aggregate_resources_logs(selection): workflow_results = [] + my_workflows = [] # get all active tasks - ### active_tasks = Task.objects.filter(status__in=settings.ACTIVE_STATUSSES) + if 'active' in selection: + active_tasks = Task.objects.filter(status__in=settings.ACTIVE_STATUSSES) - # retrieve all unique workflows - ### active_workflows = active_tasks.values('workflow').distinct() + # retrieve all unique workflows from the active tasks + active_workflows = active_tasks.values('workflow').distinct() - all_workflows = Workflow.objects.all() - # iterate through the filters and accumulate logentries + # construct the list of workflows (cheap) + for w in active_workflows: + try: + workflow = Workflow.objects.get(id = w['workflow']) + my_workflows.append(workflow) + except: + pass - ### for w in active_workflows: - for workflow in all_workflows: - workflow_result = {} + else: + my_workflows = Workflow.objects.all() - # extract the workflow object (cheap) - ### workflow = Workflow.objects.get(id = w['workflow']) + for workflow in my_workflows: + workflow_result = {} # aggregate logentries per step for all active statusses record_per_status = {} @@ -442,18 +452,19 @@ def construct_logs_per_workflow_html(request, workflow_results): return results -def construct_dashboard_html(request): +def construct_dashboard_html(request, selection): + + # gather and construct the dashboard based on the requested selection # --- Progress of tasks per active workflow --- - workflow_results = aggregate_resources_tasks() + workflow_results = aggregate_resources_tasks(selection) results_tasks = construct_tasks_per_workflow_html(request, workflow_results) - # --- logentries (first version with list instead of matrix--- - # log_records = aggregate_resources_logs_version1() - #results_logs = construct_logs_per_workflow_html_version1(log_records) - # --- logentries --- - log_records = aggregate_resources_logs() - results_logs = construct_logs_per_workflow_html(request, log_records) + results_logs = "<p>Resources not shown. Click the 'Resources Invisible' toggle to show resources.</p>" + if 'resources' in selection: + log_records = aggregate_resources_logs(selection) + results_logs = construct_logs_per_workflow_html(request, log_records) + return results_tasks,results_logs diff --git a/atdb/taskdatabase/templates/dashboard/dashboard.html b/atdb/taskdatabase/templates/dashboard/dashboard.html index 2a4878be714a664cae8a35f64c13214cc4403ac2..2349368c92f462eec7e66fc2b35ddc3649dcb7b3 100644 --- a/atdb/taskdatabase/templates/dashboard/dashboard.html +++ b/atdb/taskdatabase/templates/dashboard/dashboard.html @@ -7,7 +7,16 @@ <div class="card"> <div class="card-body"> - <h4>Dashboard</h4> + <div class="container-fluid"> + <div class="row"> + <div class="col-8"> + <h4>Dashboard</h4> + </div> + <div class="col-4"> + {% include "dashboard/toggles.html" %} + </div> + </div> + </div> <table class="table table-striped"> diff --git a/atdb/taskdatabase/templates/dashboard/toggles.html b/atdb/taskdatabase/templates/dashboard/toggles.html index 47e0cbbc0cbf1acc8b9ec844b35e810d1c9c678d..5b2a785052b6ad96ff09f2271b27732372433d75 100644 --- a/atdb/taskdatabase/templates/dashboard/toggles.html +++ b/atdb/taskdatabase/templates/dashboard/toggles.html @@ -1,4 +1,61 @@ <table> - <input type="checkbox" data-on="Active Workflows" data-off="All Workflows" checked data-toggle="toggle" data-onstyle="warning" data-offstyle="primary" data-style="slow"> - <input type="checkbox" data-on="Resources Visible" data-off="Resources Invisible" checked data-toggle="toggle" data-onstyle="primary" data-style="slow"> + + <input type="checkbox" + id = "all_active_workflows" + name="all_active_workflows" + data-on="All Workflows" + data-off="Active Workflows" + data-toggle="toggle" + data-onstyle="warning" + data-offstyle="primary" + data-style + {% if not 'active' in selection %} checked {% endif %} + > + + <input type="checkbox" + id = "resources_visible" + name="resources_visible" + data-on="Resources Visible" + data-off="Resources Invisible" + data-toggle="toggle" + data-onstyle="primary" + data-offstyle="secondary" + data-style + {% if 'resources' in selection %} checked {% endif %} + > + + + <script> + $(function() { + $('#all_active_workflows').change(function() { + + let url = location.href + if ($(this).prop('checked')) { + url = url.replace('active','all'); + location.assign(url); + } else { + url = url.replace('all','active'); + location.assign(url); + } + + }) + }) + </script> + + <script> + $(function() { + $('#resources_visible').change(function() { + + let url = location.href + if ($(this).prop('checked')) { + url = url.replace('nores','resources'); + location.assign(url); + } else { + url = url.replace('resources','nores'); + location.assign(url); + } + + }) + }) + </script> </table> \ No newline at end of file diff --git a/atdb/taskdatabase/templates/taskdatabase/base.html b/atdb/taskdatabase/templates/taskdatabase/base.html index 1c2726a8fdbbf41343b3f8ca8941f54fd53736d6..1318e15cbcfc3adb83242709b7d28b327e6debe4 100644 --- a/atdb/taskdatabase/templates/taskdatabase/base.html +++ b/atdb/taskdatabase/templates/taskdatabase/base.html @@ -45,7 +45,7 @@ <li><a class="nav-link" href="{% url 'task-details'%}">Details</a></li> {% endif %} - <li><a class="nav-link" href="{% url 'dashboard' %}">Dashboard</a></li> + <li><a class="nav-link" href="{% url 'dashboard' 'active_nores' %}">Dashboard</a></li> <li><a class="nav-link" href="{% url 'query' %}">Query</a></li> diff --git a/atdb/taskdatabase/urls.py b/atdb/taskdatabase/urls.py index 5192da51b18f8d1d197f7d02823f7504c73378b6..e14448fb7b9470d7e4ca8ac1f5596f8ea3c5c183 100644 --- a/atdb/taskdatabase/urls.py +++ b/atdb/taskdatabase/urls.py @@ -20,7 +20,7 @@ urlpatterns = [ path('show-inputs/<int:id>/', views.ShowInputs, name='show-inputs'), path('show-outputs/<int:id>/', views.ShowOutputs, name='show-outputs'), path('show-metrics/<int:id>/', views.ShowMetrics, name='show-metrics'), - path('dashboard/', views.ShowDashboard, name='dashboard'), + path('dashboard/<selection>', views.ShowDashboard, name='dashboard'), path('workflow_details/<id>/', views.WorkflowDetails, name='workflow-details'), path('query/', views.QueryView.as_view(), name='query'), diff --git a/atdb/taskdatabase/views.py b/atdb/taskdatabase/views.py index 93278874a39844cb29b8d130d4f54791cf5ba6f5..9a40824780a6b8c3b307aae8d4aa658871acdeff 100644 --- a/atdb/taskdatabase/views.py +++ b/atdb/taskdatabase/views.py @@ -275,10 +275,13 @@ def ShowConfig(request): return render(request, "taskdatabase/config.html", {'results': results}) -def ShowDashboard(request): +def ShowDashboard(request, selection): # gather the results - results_tasks,results_logs = algorithms.construct_dashboard_html(request) - return render(request, "dashboard/dashboard.html", {'results_tasks': results_tasks, 'results_logs': results_logs}) + results_tasks,results_logs = algorithms.construct_dashboard_html(request, selection) + return render(request, "dashboard/dashboard.html", + {'results_tasks': results_tasks, + 'results_logs': results_logs, + 'selection': selection}) def WorkflowDetails(request, id):