Skip to content
Snippets Groups Projects
Commit f1744d80 authored by Nico Vermaas's avatar Nico Vermaas
Browse files

Merge branch 'SDC-438-filters-on-dashboard' into 'master'

apply filter to dashboard

See merge request !199
parents 945d4d8a eb99c30b
No related branches found
No related tags found
2 merge requests!200apply filter to dashboard,!199apply filter to dashboard
Pipeline #24685 passed
Showing with 86 additions and 23 deletions
# Generated by Django 3.1.4 on 2022-02-01 13:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('taskdatabase', '0011_auto_20220131_1103'),
]
operations = [
migrations.AddField(
model_name='task',
name='environment',
field=models.JSONField(blank=True, null=True),
),
]
......@@ -274,13 +274,13 @@ def convert_monitor_to_html(request, monitor_data):
# aggregate information from the tasks table per workflow per status
def aggregate_resources_tasks(selection):
def aggregate_resources_tasks(request, selection, filtered_tasks):
workflow_results = []
my_workflows = []
# get all active tasks
if 'active' in selection:
active_tasks = Task.objects.filter(status__in=settings.ACTIVE_STATUSSES).filter(task_type='regular')
active_tasks = filtered_tasks.filter(status__in=settings.ACTIVE_STATUSSES).filter(task_type='regular')
# retrieve all unique workflows from the active tasks
active_workflows = active_tasks.values('workflow').distinct()
......@@ -303,7 +303,7 @@ def aggregate_resources_tasks(selection):
# get the numbers for this workflow
# all tasks for this workflow for the 'grand total'
tasks_per_workflow = Task.objects.filter(workflow=workflow).filter(task_type='regular')
tasks_per_workflow = filtered_tasks.filter(workflow=workflow).filter(task_type='regular')
nr_of_tasks_per_workflow = tasks_per_workflow.count()
sum_size_to_process = tasks_per_workflow.aggregate(Sum('size_to_process'))
......@@ -471,24 +471,20 @@ def highlight_value(values, value_to_highlight):
def construct_tasks_per_workflow_html(request, workflow_results):
# --- Progress of tasks per active workflow ---
results_tasks = "<p>Progress of tasks per workflow</p>"
# construct the header
###header = ""
header = '<th class="aggregate_failed">failed</th><th class="aggregate">active</th><th class="aggregate">total</th>'
for status in settings.ALL_STATUSSES:
header += "<th>" + status + "</th>"
###header += '<th class="failed">failed</th><th class="active">active</th><th>total</th>'
results_tasks += header
for workflow_result in workflow_results:
link = construct_link_to_workflow_api(request, workflow_result)
# values = "<tr><td colspan='5'><b>" + link + "</b></td></tr><tr>"
values = "<tr class='info'><td colspan='6'><b>" + link + "</b></td>"
# add sizes
......@@ -615,8 +611,16 @@ def construct_logs_per_workflow_html(request, workflow_results):
def construct_dashboard_html(request, selection):
# gather and construct the dashboard based on the requested selection
filtered_tasks = Task.objects.all()
try:
if 'applyfilter' in selection:
filtered_tasks_as_list = request.session['filtered_tasks_as_list']
filtered_tasks = Task.objects.filter(id__in=filtered_tasks_as_list)
except:
pass
# --- Progress of tasks per active workflow ---
workflow_results = aggregate_resources_tasks(selection)
workflow_results = aggregate_resources_tasks(request, selection, filtered_tasks)
results_tasks = construct_tasks_per_workflow_html(request, workflow_results)
# --- logentries ---
......
......@@ -24,6 +24,17 @@
{% if 'resources' in selection %} checked {% endif %}
>&nbsp;
<input type="checkbox"
id = "apply_filter"
name="apply_filter"
data-on="Latest Filter Applied"
data-off="No Filter Applied"
data-toggle="toggle"
data-onstyle="primary"
data-offstyle="secondary"
data-style
{% if 'applyfilter' in selection %} checked {% endif %}
>&nbsp;
<script>
$(function() {
......@@ -58,4 +69,21 @@
})
})
</script>
<script>
$(function() {
$('#apply_filter').change(function() {
let url = location.href
if ($(this).prop('checked')) {
url = url.replace('nofilter','applyfilter');
location.assign(url);
} else {
url = url.replace('applyfilter','nofilter');
location.assign(url);
}
})
})
</script>
</table>
\ No newline at end of file
......@@ -15,8 +15,8 @@
<form action="" method="get" class="form form-inline">
{% bootstrap_form filter.form layout='inline' %}
&nbsp;<button type="submit" class="btn-success btn-sm" title="Filter"><i class="fas fa-filter"></i> Filter</button>
</form>
{% include "taskdatabase/filter/clear_filter_button.html" %}
</form>
</div>
{% endif %}
......
......@@ -52,7 +52,7 @@
<li><a class="nav-link" href="{% url 'quality' %}">Quality</a></li>
{% endif %}
<li><a class="nav-link" href="{% url 'dashboard' 'active_nores' %}">Dashboard</a></li>
<li><a class="nav-link" href="{% url 'dashboard' 'active_nores_nofilter' %}">Dashboard</a></li>
<li><a class="nav-link" href="{% url 'query' %}">Filter</a></li>
......
<a href="{% url 'clear-filter' %}" class="btn btn-warning btn-sm" role="button"><i class="fas fa-window-close"></i> Clear Filter</a>
......@@ -6,7 +6,7 @@
<tr><td>Click to Filter</td></tr>
<tr>
<td>
<a href="{% url 'task-set-filter' 'all' %}" class="btn btn-success btn-sm" role="button"><i class="fas fa-layer-group"></i> All</a>
{% include "taskdatabase/filter/clear_filter_button.html" %}
<a href="{% url 'task-set-active-filter' %}" class="btn btn-success btn-sm" role="button"><i class="fas fa-layer-group"></i> Active</a>
<a href="{% url 'task-set-filter' 'failed' %}" class="btn btn-danger btn-sm" role="button"><i class="fas fa-layer-group"></i> Failed</a>
<a href="{% url 'task-set-onhold-filter' True %}" class="btn btn-warning btn-sm" role="button"><i class="fas fa-layer-group"></i> On Hold</a>
......
......@@ -34,7 +34,7 @@
{% include 'taskdatabase/pagination.html' %}
</div>
</div>
<p class="footer"> Version 1.0.0 (4 feb 2021 - 16:00)
<p class="footer"> Version 1.0.0 (7 feb 2021 - 15:00)
</div>
......
......@@ -83,6 +83,8 @@ urlpatterns = [
path('tasks/set_filter/<filter>', views.TaskSetFilter, name='task-set-filter'),
path('tasks/set_active_filter', views.TaskSetActiveFilter, name='task-set-active-filter'),
path('tasks/task-set-onhold-filter/<onhold>', views.TaskSetOnHoldFilter, name='task-set-onhold-filter'),
path('tasks/clear_filter/', views.TaskClearFilter, name='clear-filter'),
path('tasks/<int:pk>/set_status/<new_status>/<query_params>', views.TaskSetStatusTables2, name = 'task-setstatus'),
path('tasks/set_status_multi/<new_status>/<query_params>', views.TaskMultiStatus, name='task-multi-setstatus'),
path('tasks/set_multi_hold/<onhold>/<query_params>', views.TaskMultiHold, name='task-multi-hold'),
......
......@@ -172,8 +172,12 @@ class QueryView(SingleTableMixin, FilterView):
query_list_of_ids = list(self.object_list.values_list('id'))[:limit]
filtered_tasks_as_list = []
for id in query_list_of_ids:
filtered_tasks_as_list.append(id[0])
# store on the session
self.request.session['query_list_of_ids'] = query_list_of_ids
self.request.session['filtered_tasks_as_list'] = filtered_tasks_as_list
return self.object_list
......@@ -803,6 +807,12 @@ def TaskSetOnHoldFilter(request, onhold):
request.session['task_onhold_filter'] = onhold
return redirect('/atdb/?page=1')
def TaskClearFilter(request):
request.session['task_filter'] = 'all'
request.session['task_onhold_filter'] = None
request.session['filtered_tasks_as_list'] = None
request.session['search_box'] = ''
return redirect('/atdb/?page=1')
@login_required
def ChangePriority(request, pk, priority_change, page=0):
......@@ -869,13 +879,13 @@ def TaskSetStatusTables2(request, pk, new_status, query_params):
@login_required
def TaskMultiStatus(request, new_status, query_params):
# get the list of id's from the session
query_list_of_ids = request.session['query_list_of_ids']
count = len(query_list_of_ids)
filtered_tasks_as_list = request.session['filtered_tasks_as_list']
count = len(filtered_tasks_as_list)
if request.method == "POST":
for id in query_list_of_ids:
task = Task.objects.get(id=id[0])
for id in filtered_tasks_as_list:
task = Task.objects.get(id=id)
task.new_status = new_status
task.save()
......@@ -893,13 +903,13 @@ def TaskMultiStatus(request, new_status, query_params):
@login_required
def TaskMultiHold(request, onhold, query_params):
# get the list of id's from the session
query_list_of_ids = request.session['query_list_of_ids']
count = len(query_list_of_ids)
filtered_tasks_as_list = request.session['filtered_tasks_as_list']
count = len(filtered_tasks_as_list)
if request.method == "POST":
for id in query_list_of_ids:
task = Task.objects.get(id=id[0])
for id in filtered_tasks_as_list:
task = Task.objects.get(id=id)
task.resume = (onhold == 'resume')
task.save()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment