Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 75 additions & 21 deletions src/assets/js/indicatorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function dataLayerPush(payload) {
class IndicatorHandler {
constructor() {
this.indicators = {};
this.nonCovidcastIndicatorSets = [];
}

fluviewIndicatorsMapping = {
Expand Down Expand Up @@ -42,7 +43,7 @@ class IndicatorHandler {
{ value: "UT", label: "UT" },
];

fluviewRegions = [
fluviewLocations = [
{ id: "nat", text: "U.S. National" },
{ id: "hhs1", text: "HHS Region 1" },
{ id: "hhs2", text: "HHS Region 2" },
Expand Down Expand Up @@ -125,6 +126,16 @@ class IndicatorHandler {
{ id: "jfk", text: "New York City" },
];

nidssFluLocations = [
{ id: 'nationwide', text: 'Taiwan National' },
{ id: 'central', text: 'Central' },
{ id: 'eastern', text: 'Eastern' },
{ id: 'kaoping', text: 'Kaoping' },
{ id: 'northern', text: 'Northern' },
{ id: 'southern', text: 'Southern' },
{ id: 'taipei', text: 'Taipei' },
];

checkForCovidcastIndicators() {
return this.indicators.some((indicator) => {
return indicator["_endpoint"] === "covidcast";
Expand All @@ -151,6 +162,16 @@ class IndicatorHandler {
return fluviewIndicators;
}

getNIDSSFluIndicators() {
var nidssFluIndicators = [];
this.indicators.forEach((indicator) => {
if (indicator["_endpoint"] === "nidss_flu") {
nidssFluIndicators.push(indicator);
}
});
return nidssFluIndicators;
}

getFromToDate(startDate, endDate, timeType) {
if (timeType === "week") {
$.ajax({
Expand Down Expand Up @@ -180,21 +201,42 @@ class IndicatorHandler {
return request;
}

showFluviewRegions() {
var fluviewRegionSelect = `
<div class="row margin-top-1rem">
showfluviewLocations() {
var fluviewLocationselect = `
<div class="row margin-top-1rem" id="fluviewDiv">
<div class="col-2">
<label for="fluviewRegions" class="col-form-label">ILINet Location(s):</label>
<label for="fluviewLocations" class="col-form-label">ILINet Location(s):</label>
</div>
<div class="col-10">
<select id="fluviewRegions" name="fluviewRegions" class="form-select" multiple="multiple"></select>
<select id="fluviewLocations" name="fluviewLocations" class="form-select" multiple="multiple"></select>
</div>
</div>`;
if ($("#otherEndpointLocations").length) {
$("#otherEndpointLocations").append(fluviewRegionSelect);
$("#fluviewRegions").select2({
$("#otherEndpointLocations").append(fluviewLocationselect);
$("#fluviewLocations").select2({
placeholder: "Select ILINet Location(s)",
data: this.fluviewRegions,
data: this.fluviewLocations,
allowClear: true,
width: "100%",
});
}
}

showNIDSSFluLocations() {
var nidssFluLocationselect = `
<div class="row margin-top-1rem" id="nidssFluDiv">
<div class="col-2">
<label for="nidssFluLocations" class="col-form-label">Taiwanese ILI Location(s):</label>
</div>
<div class="col-10">
<select id="nidssFluLocations" name="nidssFluLocations" class="form-select" multiple="multiple"></select>
</div>
</div>`;
if ($("#otherEndpointLocations").length) {
$("#otherEndpointLocations").append(nidssFluLocationselect);
$("#nidssFluLocations").select2({
placeholder: "Select Taiwanese ILI Location(s)",
data: this.nidssFluLocations,
allowClear: true,
width: "100%",
});
Expand All @@ -204,11 +246,13 @@ class IndicatorHandler {
plotData() {
const covidCastGeographicValues =
$("#geographic_value").select2("data");
const fluviewRegions = $("#fluviewRegions").select2("data");
const fluviewLocations = $("#fluviewLocations").select2("data");
const nidssFluLocations = $("#nidssFluLocations").select2("data");
const submitData = {
indicators: this.indicators,
covidCastGeographicValues: covidCastGeographicValues,
fluviewRegions: fluviewRegions,
fluviewLocations: fluviewLocations,
nidssFluLocations: nidssFluLocations,
apiKey: document.getElementById("apiKey").value,
};
const csrftoken = Cookies.get("csrftoken");
Expand All @@ -226,7 +270,8 @@ class IndicatorHandler {
formMode: "epivis",
indicators: JSON.stringify(submitData["indicators"]),
covidcastGeoValues: JSON.stringify(submitData["covidCastGeographicValues"]),
fluviewGeoValues: JSON.stringify(submitData["fluviewRegions"]),
fluviewGeoValues: JSON.stringify(submitData["fluviewLocations"]),
nidssFluLocations: JSON.stringify(submitData["nidssFluLocations"]),
epivisUrl: data["epivis_url"],
apiKey: submitData["apiKey"] ? submitData["apiKey"] : "Not provided",
}
Expand All @@ -236,7 +281,8 @@ class IndicatorHandler {
}

exportData() {
var fluviewRegions = $("#fluviewRegions").select2("data");
var fluviewLocations = $("#fluviewLocations").select2("data");
var nidssFluLocations = $("#nidssFluLocations").select2("data");

var covidCastGeographicValues = Object.groupBy(
$("#geographic_value").select2("data"),
Expand All @@ -247,7 +293,8 @@ class IndicatorHandler {
end_date: document.getElementById("end_date").value,
indicators: this.indicators,
covidCastGeographicValues: covidCastGeographicValues,
fluviewRegions: fluviewRegions,
fluviewLocations: fluviewLocations,
nidssFluLocations: nidssFluLocations,
apiKey: document.getElementById("apiKey").value,
}
const csrftoken = Cookies.get("csrftoken");
Expand All @@ -267,7 +314,8 @@ class IndicatorHandler {
formEndDate: submitData["end_date"],
indicators: JSON.stringify(submitData["indicators"]),
covidcastGeoValues: JSON.stringify(submitData["covidCastGeographicValues"]),
fluviewGeoValues: JSON.stringify(submitData["fluviewRegions"]),
fluviewGeoValues: JSON.stringify(submitData["fluviewLocations"]),
nidssFluLocations: JSON.stringify(submitData["nidssFluLocations"]),
apiKey: submitData["apiKey"] ? submitData["apiKey"] : "Not provided",
}
dataLayerPush(payload);
Expand All @@ -277,7 +325,8 @@ class IndicatorHandler {

previewData() {
$('#loader').show();
var fluviewRegions = $("#fluviewRegions").select2("data");
var fluviewLocations = $("#fluviewLocations").select2("data");
var nidssFluLocations = $("#nidssFluLocations").select2("data");

var covidCastGeographicValues = Object.groupBy(
$("#geographic_value").select2("data"),
Expand All @@ -288,7 +337,8 @@ class IndicatorHandler {
end_date: document.getElementById("end_date").value,
indicators: this.indicators,
covidCastGeographicValues: covidCastGeographicValues,
fluviewRegions: fluviewRegions,
fluviewLocations: fluviewLocations,
nidssFluLocations: nidssFluLocations,
apiKey: document.getElementById("apiKey").value,
}
const csrftoken = Cookies.get("csrftoken");
Expand All @@ -307,7 +357,8 @@ class IndicatorHandler {
formEndDate: submitData["end_date"],
indicators: JSON.stringify(submitData["indicators"]),
covidcastGeoValues: JSON.stringify(submitData["covidCastGeographicValues"]),
fluviewGeoValues: JSON.stringify(submitData["fluviewRegions"]),
fluviewGeoValues: JSON.stringify(submitData["fluviewLocations"]),
nidssFluLocations: JSON.stringify(submitData["nidssFluLocations"]),
apiKey: submitData["apiKey"] ? submitData["apiKey"] : "Not provided",
}
dataLayerPush(payload);
Expand All @@ -318,7 +369,8 @@ class IndicatorHandler {

createQueryCode() {

var fluviewRegions = $("#fluviewRegions").select2("data");
var fluviewLocations = $("#fluviewLocations").select2("data");
var nidssFluLocations = $("#nidssFluLocations").select2("data");

var covidCastGeographicValues = Object.groupBy(
$("#geographic_value").select2("data"),
Expand All @@ -330,7 +382,8 @@ class IndicatorHandler {
end_date: document.getElementById("end_date").value,
indicators: this.indicators,
covidCastGeographicValues: covidCastGeographicValues,
fluviewRegions: fluviewRegions,
fluviewLocations: fluviewLocations,
nidssFluLocations: nidssFluLocations,
apiKey: document.getElementById("apiKey").value,
}
const csrftoken = Cookies.get("csrftoken");
Expand All @@ -357,7 +410,8 @@ class IndicatorHandler {
formEndDate: submitData["end_date"],
indicators: JSON.stringify(submitData["indicators"]),
covidcastGeoValues: JSON.stringify(submitData["covidCastGeographicValues"]),
fluviewGeoValues: JSON.stringify(submitData["fluviewRegions"]),
fluviewGeoValues: JSON.stringify(submitData["fluviewLocations"]),
nidssFluLocations: JSON.stringify(submitData["nidssFluLocations"]),
apiKey: submitData["apiKey"] ? submitData["apiKey"] : "Not provided",
}
dataLayerPush(payload);
Expand Down
2 changes: 1 addition & 1 deletion src/assets/js/indicatorSetsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function format(indicatorSetId, relatedIndicators, indicatorSetDescription) {
).length;
var checkboxTitle = "";
checked = checked ? "checked" : "";
disabled = indicator.endpoint !== "covidcast" && indicator.endpoint !== "fluview" ? "disabled" : "";
disabled = indicator.endpoint !== "covidcast" && indicator.endpoint !== "fluview" && indicator.endpoint !== "nidss_flu" ? "disabled" : "";
sourceType = indicator.source_type;
var restricted = indicator.restricted != "No";
if (disabled === "disabled") {
Expand Down
74 changes: 60 additions & 14 deletions src/assets/js/selectedIndicatorsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ function addSelectedIndicator(element) {
element.dataset.indicatorSet,
element.dataset.indicator
);
if (element.dataset.endpoint !== "covidcast" && !indicatorHandler.nonCovidcastIndicatorSets.includes(element.dataset.indicatorSet)) {
indicatorHandler.nonCovidcastIndicatorSets.push(
element.dataset.indicatorSet
);
}
} else {
checkedIndicatorMembers = checkedIndicatorMembers.filter(
(indicator) => indicator.indicator !== element.dataset.indicator
Expand All @@ -49,6 +54,15 @@ function addSelectedIndicator(element) {
`${element.dataset.datasource}_${element.dataset.indicator}`
)
.remove();
const indicatorSet = element.dataset.indicatorSet;
const stillExist = checkedIndicatorMembers.some(
(indicator) => indicator.indicator_set === indicatorSet
);
if (!stillExist && indicatorHandler.nonCovidcastIndicatorSets.includes(indicatorSet)) {
indicatorHandler.nonCovidcastIndicatorSets = indicatorHandler.nonCovidcastIndicatorSets.filter(
(set) => set !== indicatorSet
);
}
}

indicatorHandler.indicators = checkedIndicatorMembers;
Expand Down Expand Up @@ -210,8 +224,54 @@ $("#geographic_value").on("select2:select", function (e) {
});
});

function showFluviewLocationSelect() {
if (indicatorHandler.getFluviewIndicators().length > 0) {
if (document.getElementsByName("fluviewLocations").length === 0) {
indicatorHandler.showfluviewLocations();
} else {
// IF code goes here, we assume that otherEndpointLocationWarning & fluviewRegion selector is already on the page, but is just hidden, so we should just show it.
$("#fluviewDiv").show();
}
} else {
// If there are no non-covidcast indicators selected then hide otherEndpointLocationWarning & fluviewLocations selector.
$("#fluviewLocations").val(null).trigger("change");
$("#fluviewDiv").hide();
}
}

function showNIDSSFluLocationSelect() {
if (indicatorHandler.getNIDSSFluIndicators().length > 0) {
if (document.getElementsByName("nidssFluLocations").length === 0) {
indicatorHandler.showNIDSSFluLocations();
} else {
// IF code goes here, we assume that otherEndpointLocationWarning & nidssRegion selector is already on the page, but is just hidden, so we should just show it.
$("#nidssFluDiv").show();
}
} else {
// If there are no non-covidcast indicators selected then hide otherEndpointLocationWarning & nidssFluLocations selector.
$("#nidssFluLocations").val(null).trigger("change");
$("#nidssFluDiv").hide();
}
}

function showNonDelphiIndicatorSetsLocations() {
if (indicatorHandler.nonCovidcastIndicatorSets.length > 0) {

var otherEndpointIndicatorSetsLocationMessage = `<div class="alert alert-info" data-mdb-alert-init role="alert">For indicator set(s) ${indicatorHandler.nonCovidcastIndicatorSets.join(", ")}, please use the Location menu(s) below:</div>`
$("#differentLocationNote").html(otherEndpointIndicatorSetsLocationMessage);
showFluviewLocationSelect();
showNIDSSFluLocationSelect();
$("#otherEndpointLocationsWrapper").show();
} else {
$("#differentLocationNote").html("");
$("#otherEndpointLocationsWrapper").hide();
}
}



$("#showSelectedIndicatorsButton").click(async function () {
showNonDelphiIndicatorSetsLocations();
alertPlaceholder.innerHTML = "";

const prevSelectedIds = $('#geographic_value').val() || [];
Expand Down Expand Up @@ -256,20 +316,6 @@ $("#showSelectedIndicatorsButton").click(async function () {
}
})
});
if (indicatorHandler.getFluviewIndicators().length > 0) {
var ilinetEndpointLocationsWarning = '<div class="alert alert-info" data-mdb-alert-init role="alert">For indicator set ILINet, please use the Location menu below:</div>';
$("#differentLocationNote").html(ilinetEndpointLocationsWarning)
if (document.getElementsByName("fluviewRegions").length === 0) {
indicatorHandler.showFluviewRegions();
} else {
// IF code goes here, we assume that otherEndpointLocationWarning & fluviewRegion selector is already on the page, but is just hidden, so we should just show it.
$("#otherEndpointLocationsWrapper").show();
}
} else {
// If there are no non-covidcast indicators selected (only fluview is supported for now) then hide otherEndpointLocationWarning & fliviewRegions selector.
$("#fluviewRegions").val(null).trigger("change");
$("#otherEndpointLocationsWrapper").hide();
}
});


Expand Down
Loading