Commit b949fd8f authored by Michał Woźniak's avatar Michał Woźniak
Browse files

bugfix: load-6-sites buttons now set the correct settings again

parent 63e7028b
Pipeline #210 passed with stage
in 2 seconds
......@@ -663,6 +663,7 @@ let getCovidData = () => {
siteData[site].source_title = "pomber / covid19"
})
sites = Object.keys(siteData).sort()
// we want Global separated by the dashes from other sites
sites.splice(sites.indexOf('Global'), 1);
sites.unshift('Global', '- - - - - - - - - - - - - - - - - - - - - - - -')
......@@ -1656,22 +1657,6 @@ let testAllSites = () => {
}
/*
* helper: get all the chart settings as an object
*/
let getChartSettings = () => {
return {
}
}
/*
* helper: set all the chart settings from an object
*/
let setChartSettings = (settingsObj) => {
}
/*
* get an array of sites from a string
* used mainly in the context of the URL hash
......@@ -1732,17 +1717,11 @@ let processUrlHash = (hash) => {
}
}
/*
* assemble and set the url hash
* without firing a hashchange event
* return array of settings that are set to something different then default
*/
let updateUrlHash = () => {
// get selected sites
var selected_sites = []
for (let sselect of sitesSelects) {
selected_sites.push(sselect.value.toLowerCase().replace(/[^a-z0-9]/g, '-'))
}
let getSelectedSettings = () => {
// get radio boxes settings
var selected_settings = []
document
......@@ -1761,9 +1740,34 @@ let updateUrlHash = () => {
selected_settings.push(r.id.split('-').slice(-1)[0] + ":" + r.value)
}
})
// return the array
return selected_settings;
}
/*
* assemble and set the url hash
* without firing a hashchange event
*/
let updateUrlHash = () => {
// get selected sites
var selected_sites = []
var valid_sites = Object.keys(siteData)
for (let sselect of sitesSelects) {
// this is to avoid 'select-one' showing up in the URL hash
if (valid_sites.includes(sselect.value)) {
selected_sites.push(sselect.value.toLowerCase().replace(/[^a-z0-9]/g, '-'))
}
}
// get the settings with non-default values
var selected_settings = getSelectedSettings()
// using History.pushState() because we don't want the onhashchange event to fire
history.pushState({}, '', '#' + selected_settings.join(',') + ';' + selected_sites.join(','))
if (selected_settings.length > 0) {
history.pushState({}, '', '#' + selected_settings.join(',') + ';' + selected_sites.join(','))
} else {
history.pushState({}, '', '#' + selected_sites.join(','))
}
}
......@@ -2021,7 +2025,7 @@ document.addEventListener('DOMContentLoaded', (e)=>{
menu_chart_settings[e.target.id]()
}
// TODO: we need to find a better way to do this
window.location.hash = '#' + sites
window.location.hash = '#' + getSelectedSettings().join(',') + ';' + sites
})
})
......@@ -2094,8 +2098,9 @@ document.addEventListener('DOMContentLoaded', (e)=>{
clearAllSites.addEventListener('click', (e)=>{
e.preventDefault()
// we need to do this in a better way
window.location.hash = ''
// just set the settings, with empty sites part
// TODO: we need to do this in a better way
window.location.hash = '#' + getSelectedSettings().join(',') + ';'
})
// handling manual hash change
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment