-
Notifications
You must be signed in to change notification settings - Fork 2
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
Set COVIDcast export values based on URL parameters #1244
Changes from 4 commits
a621fc5
0d5d149
cd448c3
d9f12de
f978fa7
b94ad01
333a79c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -27,18 +27,55 @@ | |||||
} | ||||||
} | ||||||
|
||||||
// Pre-fill the form from URL parameters. | ||||||
// Supported parameters: source, sensor, start, end, geo_type, geo_id | ||||||
const urlParams = new URLSearchParams(window.location.search); | ||||||
|
||||||
// Overwrite default source & sensor if these are present in the URL | ||||||
if (urlParams.has('data_source')) { | ||||||
sourceValue = urlParams.get('data_source'); | ||||||
|
||||||
if (urlParams.has('signal')) { | ||||||
sensorValue = urlParams.get('signal'); | ||||||
} | ||||||
} | ||||||
|
||||||
$: isWeekly = sensor ? sensor.isWeeklySignal : false; | ||||||
$: formatDate = isWeekly ? (d) => formatWeek(d).replace('W', '') : formatDateISO; | ||||||
|
||||||
let geoType = 'county'; | ||||||
let geoType = urlParams.has('geo_type') ? urlParams.get('geo_type') : 'county'; | ||||||
|
||||||
let startDate = new Date(); | ||||||
let endDate = new Date(); | ||||||
|
||||||
function initDate(date) { | ||||||
const param = new DateParam(date); | ||||||
endDate = param.sparkLineTimeFrame.max; | ||||||
startDate = param.sparkLineTimeFrame.min; | ||||||
|
||||||
// Populate date based on URL params or, if absent, the current date | ||||||
if (sensor && !sensor.active) { | ||||||
// If the sensor is inactive, set the start and end dates to its historical range rather than current date | ||||||
if ( | ||||||
urlParams.has('start_day') && | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Im not sure we want to clamp these values to the active range if theyve been specified in the URL... The principle of least surprise suggests showing the user what they asked for. |
||||||
new Date(urlParams.get('start_day')) >= sensor.meta.minTime && | ||||||
new Date(urlParams.get('start_day')) <= sensor.meta.maxTime | ||||||
) { | ||||||
startDate = new Date(urlParams.get('start_day')); | ||||||
} else { | ||||||
startDate = sensor.meta.minTime; | ||||||
} | ||||||
if ( | ||||||
urlParams.has('end_day') && | ||||||
new Date(urlParams.get('end_day')) <= sensor.meta.minTime && | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
new Date(urlParams.get('end_day')) <= sensor.meta.maxTime | ||||||
) { | ||||||
endDate = new Date(urlParams.get('end_day')); | ||||||
} else { | ||||||
endDate = sensor.meta.maxTime; | ||||||
} | ||||||
} else { | ||||||
startDate = urlParams.has('start_day') ? new Date(urlParams.get('start_day')) : param.sparkLineTimeFrame.min; | ||||||
endDate = urlParams.has('end_day') ? new Date(urlParams.get('end_day')) : param.sparkLineTimeFrame.max; | ||||||
} | ||||||
} | ||||||
$: initDate($currentDateObject); | ||||||
|
||||||
|
@@ -59,12 +96,20 @@ | |||||
|
||||||
let geoValuesMode = 'all'; | ||||||
let geoValues = []; | ||||||
let geoURLSet = false; | ||||||
$: geoItems = [...(infosByLevel[geoType] || []), ...(geoType === 'county' ? infosByLevel.state : [])]; | ||||||
$: { | ||||||
if (geoItems != null) { | ||||||
geoValues = []; | ||||||
geoValuesMode = guessMode(geoItems.length); | ||||||
} | ||||||
|
||||||
// Populate region based on URL params... but let the user override this later | ||||||
if (urlParams.has('geo_value') && !geoURLSet) { | ||||||
Comment on lines
+89
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it remove the need for |
||||||
let infos = infosByLevel[geoType].filter((d) => d.propertyId == urlParams.get('geo_value')); | ||||||
addRegion(infos[0]); | ||||||
geoURLSet = true; | ||||||
} | ||||||
} | ||||||
|
||||||
function flatIds(geoValues) { | ||||||
|
@@ -90,6 +135,11 @@ | |||||
} | ||||||
} | ||||||
$: usesAsOf = asOfMode !== 'latest' && asOfDate instanceof Date; | ||||||
// set as_of based on URL params, if it's a valid date | ||||||
if (urlParams.has('as_of') && !isNaN(new Date(urlParams.get('as_of')))) { | ||||||
asOfMode = 'single'; | ||||||
asOfDate = new Date(urlParams.get('as_of')); | ||||||
} | ||||||
|
||||||
let form = null; | ||||||
|
||||||
|
@@ -104,6 +154,14 @@ | |||||
); | ||||||
}); | ||||||
} | ||||||
// Fix up the UI if we got an inactive sensor from the URL parameters. | ||||||
if (sensor && !sensor.active) { | ||||||
showInActive = true; | ||||||
// Force an update to sourceValue to set related reactive statements correctly. | ||||||
let temp = sourceValue; | ||||||
sourceValue = ''; | ||||||
sourceValue = temp; | ||||||
} | ||||||
}); | ||||||
|
||||||
function addRegion(detail) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change these to match new parameter names