Skip to content

Commit 07c690f

Browse files
committed
Added filters submit onChange. Moved info about number of showed indicators to the top of the table. Removed 'Submit Filters' button. Added spinner(loader) to idicate that form is submitting(added this to all the filters in order not to have different filters behavior).
1 parent 74b5a64 commit 07c690f

File tree

7 files changed

+161
-23
lines changed

7 files changed

+161
-23
lines changed

src/assets/css/custom_styles.css

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,112 @@
4949
font-size: 0.875em!important;
5050
color: var(--mdb-code-color)!important;
5151
word-wrap: break-word!important;
52+
}
53+
54+
55+
56+
/* Loader Overlay */
57+
.loader-overlay {
58+
position: fixed;
59+
top: 0;
60+
left: 0;
61+
width: 100%;
62+
height: 100%;
63+
background: rgba(0, 0, 0, 0.5); /* Semi-transparent black overlay */
64+
display: none; /* Hidden by default */
65+
justify-content: center;
66+
align-items: center;
67+
z-index: 1000; /* Ensure it’s on top */
68+
}
69+
70+
/* Table fade effect when loader is active */
71+
.table-container.faded {
72+
opacity: 0.3; /* Fades the table */
73+
transition: opacity 0.3s ease;
74+
}
75+
76+
/* lds-roller CSS from loading.io */
77+
.lds-roller {
78+
display: inline-block;
79+
position: relative;
80+
width: 200px;
81+
height: 200px;
82+
}
83+
.lds-roller div {
84+
animation: lds-roller 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
85+
transform-origin: 40px 40px;
86+
}
87+
.lds-roller div:after {
88+
content: " ";
89+
display: block;
90+
position: absolute;
91+
width: 7px;
92+
height: 7px;
93+
border-radius: 50%;
94+
background: #fff;
95+
margin: -4px 0 0 -4px;
96+
}
97+
.lds-roller div:nth-child(1) {
98+
animation-delay: -0.036s;
99+
}
100+
.lds-roller div:nth-child(1):after {
101+
top: 63px;
102+
left: 63px;
103+
}
104+
.lds-roller div:nth-child(2) {
105+
animation-delay: -0.072s;
106+
}
107+
.lds-roller div:nth-child(2):after {
108+
top: 68px;
109+
left: 56px;
110+
}
111+
.lds-roller div:nth-child(3) {
112+
animation-delay: -0.108s;
113+
}
114+
.lds-roller div:nth-child(3):after {
115+
top: 71px;
116+
left: 48px;
117+
}
118+
.lds-roller div:nth-child(4) {
119+
animation-delay: -0.144s;
120+
}
121+
.lds-roller div:nth-child(4):after {
122+
top: 72px;
123+
left: 40px;
124+
}
125+
.lds-roller div:nth-child(5) {
126+
animation-delay: -0.18s;
127+
}
128+
.lds-roller div:nth-child(5):after {
129+
top: 71px;
130+
left: 32px;
131+
}
132+
.lds-roller div:nth-child(6) {
133+
animation-delay: -0.216s;
134+
}
135+
.lds-roller div:nth-child(6):after {
136+
top: 68px;
137+
left: 24px;
138+
}
139+
.lds-roller div:nth-child(7) {
140+
animation-delay: -0.252s;
141+
}
142+
.lds-roller div:nth-child(7):after {
143+
top: 63px;
144+
left: 17px;
145+
}
146+
.lds-roller div:nth-child(8) {
147+
animation-delay: -0.288s;
148+
}
149+
.lds-roller div:nth-child(8):after {
150+
top: 56px;
151+
left: 12px;
152+
}
153+
@keyframes lds-roller {
154+
0% {
155+
transform: rotate(0deg);
156+
}
157+
100% {
158+
transform: rotate(360deg);
159+
}
52160
}

src/assets/js/indicatorSetsFilters.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Add an event listener to each 'bulk-select' element
22
let bulkSelectDivs = document.querySelectorAll('.bulk-select');
33
bulkSelectDivs.forEach(div => {
4-
div.addEventListener('click', function(event) {
4+
div.addEventListener('click', function (event) {
55
let form = this.nextElementSibling;
66
let showMoreLink = form.querySelector('a');
77
let checkboxes = form.querySelectorAll('input[type="checkbox"]');
@@ -28,4 +28,23 @@ bulkSelectDivs.forEach(div => {
2828
}
2929
}
3030
});
31+
});
32+
33+
function showLoader() {
34+
document.getElementById('loaderOverlay').style.display = 'flex';
35+
document.querySelector('.table-container').classList.add('faded');
36+
}
37+
38+
$("#filterIndicatorSetsForm").find("input[type='checkbox']").on("change", function (e) {
39+
// Show loader and fade table
40+
showLoader();
41+
this.form.submit();
42+
});
43+
44+
$("#location_search").on({
45+
"change": function (e) {
46+
// Show loader and fade table
47+
showLoader();
48+
this.form.submit();
49+
}
3150
});

src/assets/js/indicatorSetsTable.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function calculate_table_height() {
1212

1313
var table = new DataTable("#indicatorSetsTable", {
1414
fixedHeader: true,
15+
responsive: true,
1516
searching: false,
1617
paging: false,
1718
scrollCollapse: true,
@@ -25,21 +26,22 @@ var table = new DataTable("#indicatorSetsTable", {
2526
mark: true,
2627

2728
language: {
28-
buttons: {
29-
colvis: "Toggle Columns",
30-
},
29+
emptyTable: "No indicators match your specified filters. Try relaxing some filters, or clear all filters and try again.",
30+
// buttons: {
31+
// colvis: "Toggle Columns",
32+
// },
3133
},
3234
});
3335

34-
new DataTable.Buttons(table, {
35-
buttons: [
36-
{
37-
extend: "colvis",
38-
columns: "th:nth-child(n+3)",
39-
prefixButtons: ["colvisRestore"],
40-
},
41-
],
42-
});
36+
// new DataTable.Buttons(table, {
37+
// buttons: [
38+
// {
39+
// extend: "colvis",
40+
// columns: "th:nth-child(n+3)",
41+
// prefixButtons: ["colvisRestore"],
42+
// },
43+
// ],
44+
// });
4345

4446
table.buttons(0, null).container().appendTo("#colvis");
4547

src/indicatorsets/filters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ class Meta:
9494
def location_search_filter(self, queryset, name, value):
9595
if not value:
9696
return queryset
97-
filtered_signals = get_list_of_indicators_filtered_by_geo(value)
97+
filtered_indicators = get_list_of_indicators_filtered_by_geo(value)
9898
query = Q()
99-
for item in filtered_signals["epidata"]:
99+
for item in filtered_indicators["epidata"]:
100100
query |= Q(source__name=item["source"], name=item["signal"])
101101
self.indicators_qs = self.indicators_qs.filter(query)
102102
indicator_sets = self.indicators_qs.values_list(

src/indicatorsets/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def get_list_of_indicators_filtered_by_geo(geos):
3131
url = f"{settings.EPIDATA_URL}covidcast/geo_coverage"
3232
params = {"geo": dict_to_geo_string(geos), "api_key": settings.EPIDATA_API_KEY}
3333
response = requests.get(url, params=params)
34-
print(f"Response from Epidata: {response}")
3534
return response.json()
3635

3736

src/templates/indicatorsets/indicatorSetsFilters.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
{% load static %}
44
{% load dict_get %}
55
<div class="col-2">
6-
<form method="get" id="filterIndicatorSetsForm">
6+
<form method="GET" id="filterIndicatorSetsForm">
77
<div class="card">
88
<div class="card-body no-padding-top-bottom">
99
<span id="totalRowsNumber"></span>
10-
<div class="colvis" id="colvis"></div>
1110
<h2 class="card-title font-size-25">Filters</h2>
1211
<div class="accordion accordion-flush" id="accordionIndicatorSetFilters">
1312
<div class="accordion-item">
@@ -48,7 +47,7 @@ <h2 class="card-title font-size-25">Filters</h2>
4847
data-mdb-target="#flush-collapse_{{ form.pathogens.auto_id }}"
4948
aria-expanded="false"
5049
aria-controls="flush-collapse_{{ form.pathogens.auto_id }}">
51-
Pathogens/Syndromes
50+
Pathogens<br>/Syndromes
5251
<a tabindex="0"
5352
type="button"
5453
class="info-button filter-description-popover"
@@ -234,10 +233,11 @@ <h2 class="card-title font-size-25">Filters</h2>
234233
</div>
235234
<div class="card-body no-padding-top">
236235
<div class="d-grid gap-2 mt-3">
237-
<button id="filter-submit" type="submit" class="btn btn-primary">{% trans "Apply Filters" %}</button>
236+
{% comment %} <button id="filter-submit" type="submit" class="btn btn-primary">{% trans "Apply Filters" %}</button> {% endcomment %}
238237
<div class="margin-left-right-auto">
239238
<a href="{% url 'indicatorsets' %}">Clear filters</a>
240239
</div>
240+
{% comment %} <div class="colvis margin-left-right-auto" id="colvis"></div> {% endcomment %}
241241
</div>
242242
<hr />
243243
<div class="d-grid gap-2 mt-3 smaller-font-size">
@@ -271,7 +271,7 @@ <h2 class="card-title font-size-25">Filters</h2>
271271
initSelect2('location_search', locationSearchValues);
272272
if (urlParams.location_search != "") {
273273
var locationSearch = urlParams.location_search;
274-
$("#location_search").val(locationSearch).trigger("change");
274+
$("#location_search").val(locationSearch).trigger("change.select2");
275275
}
276276
})
277277
</script>

src/templates/indicatorsets/indicatorSetsTable.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<link rel="stylesheet"
99
href="https://cdn.datatables.net/plug-ins/1.10.13/features/mark.js/datatables.mark.min.css">
1010
<div class="col-10">
11-
<div class="row table-responsive">
11+
<div class="row table-responsive table-container">
1212
<table id="indicatorSetsTable" class="display cell-border" width="100%">
1313
<thead>
1414
<tr>
@@ -316,6 +316,10 @@
316316
</tbody>
317317
</table>
318318
</div>
319+
<!-- Loader Overlay -->
320+
<div class="loader-overlay" id="loaderOverlay">
321+
<div class="lds-roller"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>
322+
</div>
319323
<div class="float" id="showSelectedIndicatorsButton" style="display:none;">
320324
<a type="button"
321325
class="btn btn-primary"
@@ -334,7 +338,10 @@
334338

335339
$(document).ready(function() {
336340
table.columns.adjust();
337-
$("#totalRowsNumber").text(`Showing ${table.page.info().recordsTotal} indicator ${pluralize(table.page.info().recordsTotal, 'set')} containing ${relatedIndicators.length} individual ${pluralize(relatedIndicators.length, 'indicator')}`);
341+
const totalRowsSpan = document.createElement("span");
342+
totalRowsSpan.textContent = `Showing ${table.page.info().recordsTotal} indicator ${pluralize(table.page.info().recordsTotal, 'set')} containing ${relatedIndicators.length} individual ${pluralize(relatedIndicators.length, 'indicator')}`;
343+
const refElement = document.getElementById("indicatorSetsTable_wrapper");
344+
refElement.before(totalRowsSpan);
338345
});
339346

340347
// Add event listener for openizng and closing details
@@ -352,4 +359,7 @@
352359
}
353360

354361
});
362+
363+
364+
355365
</script>

0 commit comments

Comments
 (0)