Skip to content

OKRS24-198 #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 16, 2024
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
4 changes: 4 additions & 0 deletions src/assets/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
border: none!important;
}

.select2-container--default .select2-selection--multiple {
border: none!important;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
display: none!important;
}
Expand Down
1 change: 1 addition & 0 deletions src/signal_documentation/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from sentry_sdk.integrations.redis import RedisIntegration

EPIVIS_URL = "https://deploy-preview-36--cmu-delphi-epivis.netlify.app/"
DATA_EXPORT_URL = "https://api.covidcast.cmu.edu/epidata/covidcast/csv"

SENTRY_DSN = os.environ.get('SENTRY_DSN')
if SENTRY_DSN:
Expand Down
1 change: 1 addition & 0 deletions src/signals/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def get_context_data(self, **kwargs) -> Dict[str, Any]:

context: Dict[str, Any] = super().get_context_data(**kwargs)
context["epivis_url"] = settings.EPIVIS_URL
context["data_export_url"] = settings.DATA_EXPORT_URL
return context


Expand Down
124 changes: 0 additions & 124 deletions src/templates/signals/epivis_block.html

This file was deleted.

225 changes: 225 additions & 0 deletions src/templates/signals/epivis_export_data_block.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
<h5>Plot / Export data</h5>
<section class="section">
<div class="row">
<div class="card">
<div class="card-body">
<form class="margin-top-1rem" onsubmit="submitMode(event)" id="epivis-form">
<div class="row">
<div class="col-2">
<label class="form-label"
>Select mode:</label
>
</div>
<div class="col-10">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="modes" id="epivis" value="epivis" checked>
<label class="form-check-label" for="epivis">Plot data</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="modes" id="export" value="export">
<label class="form-check-label" for="export">Export data</label>
</div>
</div>
</div>
<div class="row margin-top-1rem">
<div class="col-2">
<label for="source" class="form-label"
>Data Source:</label
>
</div>
<div class="col-10">
<select id="source" name="source" class="form-select" disabled>
<option selected>{{ signal.source.name }}</option>
</select>
</div>
</div>
<div class="row margin-top-1rem">
<div class="col-2">
<label for="signal" class="form-label"
>Data Signal:</label
>
</div>
<div class="col-10">
<select id="signal" name="signal" class="form-select" disabled>
<option selected>{{ signal.name }}</option>
</select>
</div>
</div>
<div class="row margin-top-1rem">
<div class="col-2">
<label for="geographic_type" class="form-label"
>Geographic Type:</label
>
</div>
<div class="col-10">
<select id="geographic_type" name="geographic_type" class="form-select">
<option selected>Choose...</option>
{% for geography in signal.available_geography.all %}
<option>{{ geography }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="row margin-top-1rem">
<div class="col-2">
<label for="geographic_value" class="col-form-label">Geographic Value:</label>
</div>
<div class="col-10">
<select id="geographic_value" name="geographic_value" class="form-select" multiple="multiple"></select>
</div>
</div>
<div class="row margin-top-1rem" name="choose_date" style="display: none;">
<div class="col-2">
<label for="start_date" class="form-label">
Start Date:
</label>
</div>
<div class="col-10">
<input type="date" class="form-control" id="start_date" name="start_date">
</div>
</div>
<div class="row margin-top-1rem" name="choose_date" style="display: none;">
<div class="col-2">
<label for="end_date" class="form-label">
End Date:
</label>
</div>
<div class="col-10">
<input type="date" class="form-control" id="end_date" name="end_date">
</div>
</div>
<div class="row">
<button type="submit" value="Submit" class="btn btn-primary margin-top-1rem">
Submit
</button>
</div>
</form>
</div>
</div>
</div>
</section>
<script>
function initGeographicValueSelect(mode) {
var maxSelectionLength = 1;
if (mode === 'epivis') {
maxSelectionLength = 1;
} else {
maxSelectionLength = 10;
}
$('#geographic_value').select2({
ajax: {
url: '{% url 'geography_units_api' %}',
dataType: 'json',
data: function (params) {
var geographic_type = document.getElementById('geographic_type');
return {
geography__name: geographic_type.value,
term: params.term,
limit: 50
};
},
processResults: function (data) {
return {
results: $.map(data.results, function (item) {
if (typeof item.geo_id === 'string') {
return {
text: item.display_name,
id: item.geo_id.toLowerCase()
}
} else {
return {
text: item.display_name,
id: item.geo_id
}
}
})
};
}
},
minimumInputLength: 0,
maximumSelectionLength: maxSelectionLength,
});
}

$(document).ready(function () {
initGeographicValueSelect('epivis');
});

document.getElementById('geographic_type').addEventListener("change", (event) => {
$('#geographic_value').val(null).trigger('change');
})

document.getElementsByName('modes').forEach((el) => {
el.addEventListener('change', (event) => {
$('#geographic_value').val(null).trigger('change');
//$('#geographic_value').select2('destroy');
if (event.target.value === 'epivis') {
initGeographicValueSelect(event.target.value);
} else {
initGeographicValueSelect('export');
}
handleModeChange(event.target.value);
});
});

var currentMode = 'epivis';

function handleModeChange(mode) {
document.getElementById("epivis-form").reset();

var choose_dates = document.getElementsByName('choose_date');
if (mode === 'epivis') {
currentMode = 'epivis';
choose_dates.forEach((el) => {
el.style.display = 'none';
});
} else {
currentMode = 'export';
choose_dates.forEach((el) => {
el.style.display = 'flex';
});
}
document.getElementsByName("modes").forEach((el) => {
if (currentMode === el.value) {
el.checked = true;
}
});
}


function submitMode(event) {
event.preventDefault();

var dataSource = document.getElementById('source').value;
var dataSignal = document.getElementById('signal').value;
var geographicType = document.getElementById('geographic_type').value;
var geographicValue = $('#geographic_value').select2('data').map((el) => el.id).join(',');

if (geographicType === 'Choose...' || geographicValue === '') {
alert('Please select Geographic Type and Geographic Value!');
return;
}

if (currentMode === 'epivis') {
var epiVisUrl = "{{ epivis_url }}";
var urlParamsEncoded = btoa(`{"datasets":[{"color":"#415742","title":"value","params":{"_endpoint":"covidcast","data_source":"${dataSource}","signal":"${dataSignal}","time_type":"day","geo_type":"${geographicType}","geo_value":"${geographicValue}"}}]}`);

epiVisUrl += `#${urlParamsEncoded}`;
window.open(epiVisUrl, '_blank').focus();

} else {
var startDate = document.getElementById('start_date').value;
var endDate = document.getElementById('end_date').value;

var dataExportUrl = "{{ data_export_url }}";

if (startDate === '' || endDate === '') {
alert('Please select start and end date');
return;
}

dataExportUrl += `?signal=${dataSource}:${dataSignal}&start_day=${startDate}&end_day=${endDate}&geo_type=${geographicType}&geo_values=${geographicValue}`;
window.open(dataExportUrl, '_blank').focus();
}
}
</script>
2 changes: 1 addition & 1 deletion src/templates/signals/signal_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ <h5>Response Example</h5>
</div>
</section>
{% endif %}
{% include "signals/epivis_block.html"%}
{% include "signals/epivis_export_data_block.html"%}
<h5>Related links</h5>
<section class="section">
<div class="row">
Expand Down