Skip to content

Commit eacf67e

Browse files
committed
Sorted Locations by geo level, added group names
1 parent 07c690f commit eacf67e

File tree

5 files changed

+54
-17
lines changed

5 files changed

+54
-17
lines changed

src/assets/js/indicatorSetsTable.js

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

1313
var table = new DataTable("#indicatorSetsTable", {
1414
fixedHeader: true,
15-
responsive: true,
1615
searching: false,
1716
paging: false,
1817
scrollCollapse: true,

src/indicatorsets/urls.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from django.urls import path
22
from django.urls.resolvers import URLPattern
3-
43
from indicatorsets.views import (IndicatorSetListView, epivis,
54
generate_export_data_url, preview_data, create_query_code)
65

src/indicatorsets/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import ast
22
import random
3+
from collections import defaultdict
34
from datetime import datetime as dtime
45

56
import requests
67
from django.conf import settings
78
from epiweeks import Week
9+
810
from indicatorsets.models import IndicatorSet
911

1012

@@ -62,3 +64,20 @@ def get_original_data_provider_choices():
6264
.order_by("original_data_provider")
6365
.distinct()
6466
]
67+
68+
69+
def group_by_property(list_of_dicts, property):
70+
"""Groups a list of dictionaries by a specified property.
71+
72+
Args:
73+
list_of_dicts: A list of dictionaries.
74+
property: The property to group by.
75+
76+
Returns:
77+
A dictionary where keys are the unique values of the property,
78+
and values are lists of dictionaries with that property value.
79+
"""
80+
grouped_dict = defaultdict(list)
81+
for item in list_of_dicts:
82+
grouped_dict[item[property]].append(item)
83+
return dict(grouped_dict)

src/indicatorsets/views.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
generate_epivis_custom_title,
1717
generate_random_color,
1818
get_epiweek,
19+
group_by_property,
1920
)
2021

2122
logger = logging.getLogger(__name__)
@@ -146,6 +147,29 @@ def get_url_params(self):
146147
url_params_str = f"{url_params_str}&{param_name}={param_value}"
147148
return url_params_dict, url_params_str
148149

150+
def get_grouped_geographic_granularities(self):
151+
geographic_granularities = [
152+
{
153+
"id": str(geo_unit.geo_id),
154+
"geoType": geo_unit.geo_level.name,
155+
"text": geo_unit.display_name,
156+
"geoTypeDisplayName": geo_unit.geo_level.display_name,
157+
}
158+
for geo_unit in GeographyUnit.objects.all()
159+
.prefetch_related("geo_level")
160+
.order_by("level")
161+
]
162+
geographic_granularities = group_by_property(
163+
geographic_granularities, "geoTypeDisplayName"
164+
)
165+
grouped_geographic_granularities = []
166+
for key, value in geographic_granularities.items():
167+
grouped_geographic_granularities.append({
168+
"text": key,
169+
"children": value,
170+
})
171+
return grouped_geographic_granularities
172+
149173
def get_context_data(self, **kwargs):
150174
context = super().get_context_data(**kwargs)
151175
queryset = self.get_queryset()
@@ -172,14 +196,7 @@ def get_context_data(self, **kwargs):
172196
context["available_geographies"] = Geography.objects.filter(
173197
used_in="indicators"
174198
)
175-
context["geographic_granularities"] = [
176-
{
177-
"id": str(geo_unit.geo_id),
178-
"geoType": geo_unit.geo_level.name,
179-
"text": geo_unit.display_name,
180-
}
181-
for geo_unit in GeographyUnit.objects.all().prefetch_related("geo_level")
182-
]
199+
context["geographic_granularities"] = self.get_grouped_geographic_granularities()
183200
return context
184201

185202

src/templates/indicatorsets/indicatorSetsFilters.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ <h2 class="card-title font-size-25">Filters</h2>
4747
data-mdb-target="#flush-collapse_{{ form.pathogens.auto_id }}"
4848
aria-expanded="false"
4949
aria-controls="flush-collapse_{{ form.pathogens.auto_id }}">
50-
Pathogens<br>/Syndromes
50+
Pathogens
51+
<br>
52+
/Syndromes
5153
<a tabindex="0"
5254
type="button"
5355
class="info-button filter-description-popover"
@@ -262,12 +264,13 @@ <h2 class="card-title font-size-25">Filters</h2>
262264
$(document).ready(function() {
263265
const geoValues = {{ geographic_granularities|safe }};
264266
var urlParams = JSON.parse(JSON.stringify({{ url_params_dict|safe }}));
265-
const locationSearchValues = geoValues.map(item => {
266-
return {
267-
...item,
268-
"id": `${item.geoType}:${item.id}`
269-
}
270-
});
267+
const locationSearchValues = geoValues.map(group => ({
268+
...group,
269+
children: group.children.map(child => ({
270+
...child,
271+
id: `${child.geoType}:${child.id}`
272+
}))
273+
}));
271274
initSelect2('location_search', locationSearchValues);
272275
if (urlParams.location_search != "") {
273276
var locationSearch = urlParams.location_search;

0 commit comments

Comments
 (0)