Skip to content

Commit 3929271

Browse files
committed
1. If Location Search was used on the main page, the Locations used should be copied as default to the "Selected Indicators" page.
1 parent 6fdba6e commit 3929271

File tree

2 files changed

+50
-28
lines changed

2 files changed

+50
-28
lines changed

src/assets/js/signal_sets.js

+44-26
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,32 @@ function showWarningAlert(warningMessage, slideUpTime = 2000) {
1515
});
1616
}
1717

18-
function checkGeoCoverage(geoType, geoValue) {
19-
var notCoveredSignals = [];
20-
$.ajax({
21-
url: "epidata/covidcast/geo_coverage/",
22-
type: 'GET',
23-
async: false,
24-
data: {
25-
'geo': `${geoType}:${geoValue}`
26-
},
27-
success: function (result) {
28-
checkedSignalMembers.forEach(signal => {
29-
var covered = result["epidata"].some(
30-
e => (e.source === signal.data_source && e.signal === signal.signal)
31-
)
32-
if (!covered) {
33-
notCoveredSignals.push(signal);
34-
}
35-
})
36-
}
37-
})
38-
return notCoveredSignals;
18+
async function checkGeoCoverage(geoType, geoValue) {
19+
const notCoveredSignals = [];
20+
21+
try {
22+
const result = await $.ajax({
23+
url: "epidata/covidcast/geo_coverage/",
24+
type: 'GET',
25+
data: {
26+
'geo': `${geoType}:${geoValue}`
27+
}
28+
});
29+
30+
checkedSignalMembers.forEach(signal => {
31+
const covered = result["epidata"].some(
32+
e => (e.source === signal.data_source && e.signal === signal.signal)
33+
);
34+
if (!covered) {
35+
notCoveredSignals.push(signal);
36+
}
37+
});
38+
39+
return notCoveredSignals;
40+
} catch (error) {
41+
console.error('Error fetching geo coverage:', error);
42+
return notCoveredSignals;
43+
}
3944
}
4045

4146

@@ -123,6 +128,18 @@ function addSelectedSignal(element) {
123128
}
124129
}
125130

131+
$("#showSelectedSignalsButton").click(function() {
132+
alertPlaceholder.innerHTML = "";
133+
$('#geographic_value').select2("data").forEach(geo => {
134+
checkGeoCoverage(geo.geoType, geo.id).then((notCoveredSignals) => {
135+
if (notCoveredSignals.length > 0) {
136+
showNotCoveredGeoWarningMessage(notCoveredSignals, geo.text);
137+
}
138+
})
139+
140+
});
141+
});
142+
126143
// Add an event listener to each 'bulk-select' element
127144
let bulkSelectDivs = document.querySelectorAll('.bulk-select');
128145
bulkSelectDivs.forEach(div => {
@@ -439,10 +456,12 @@ function showNotCoveredGeoWarningMessage(notCoveredSignals, geoValue) {
439456

440457
$('#geographic_value').on('select2:select', function (e) {
441458
var geo = e.params.data;
442-
var notCoveredSignals = checkGeoCoverage(geo.geoType, geo.id)
443-
if (notCoveredSignals.length > 0) {
444-
showNotCoveredGeoWarningMessage(notCoveredSignals, geo.text);
459+
checkGeoCoverage(geo.geoType, geo.id).then((notCoveredSignals) => {
460+
if (notCoveredSignals.length > 0) {
461+
showNotCoveredGeoWarningMessage(notCoveredSignals, geo.text);
462+
}
445463
}
464+
);
446465
});
447466

448467

@@ -454,9 +473,8 @@ function submitMode(event) {
454473
appendAlert("Please select at least one geographic location", "warning")
455474
return;
456475
}
457-
476+
458477
if (currentMode === 'epivis') {
459-
// appendAlert(warningMessage, "warning")
460478
plotData();
461479
} else if (currentMode === 'export') {
462480
exportData();

src/templates/signal_sets/signal_sets.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,14 @@ <h5 class="modal-title" id="selectedSignalsModalLabel">Selected indicators</h5>
758758
}
759759
})
760760
initSelect2('location_search', locationSearchValues);
761+
initSelect2('geographic_value', geoValues);
761762
if (urlParams.location_search != "") {
762-
$("#location_search").val(urlParams.location_search).trigger("change");
763+
var locationSearch = urlParams.location_search;
764+
$("#location_search").val(locationSearch).trigger("change");
765+
var locationIds = locationSearch.map((item) => item.split(":")[1]);
766+
$('#geographic_value').val(locationIds).trigger('change');
763767
}
764-
initSelect2('geographic_value', geoValues);
768+
765769
table.columns.adjust()
766770

767771
$("#totalRowsNumber").text(`Showing ${table.page.info().recordsTotal} indicator ${pluralize(table.page.info().recordsTotal, 'set')} containing ${relatedSignals.length} individual ${pluralize(relatedSignals.length, 'indicator')}`)

0 commit comments

Comments
 (0)