10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-25 22:03:49 +01:00

Use search query string instead of hash for file wiewer

This commit is contained in:
Mickaël Véril 2019-09-10 14:37:44 +02:00
parent 0e324735c5
commit 61038a8750
3 changed files with 37 additions and 3 deletions

View File

@ -8,6 +8,7 @@
<body> <body>
<script src="{static}/scripts/getFullDataPath.js" type="text/javascript"></script> <script src="{static}/scripts/getFullDataPath.js" type="text/javascript"></script>
<script src="{static}/scripts/getTextFromFile.js" type="text/javascript"></script> <script src="{static}/scripts/getTextFromFile.js" type="text/javascript"></script>
<script src="{static}/scripts/parseQueryStringToDictionary.js" type="text/javascript"></script>
<script> <script>
window.onload=async function(){ window.onload=async function(){
@ -25,8 +26,10 @@
} }
console.warn(mystr); console.warn(mystr);
} }
if(location.hash.length>1){ queryDic=parseQueryStringToDictionary()
var filename=location.hash.substr(1); key="dataFile"
if(queryDic[key]!=undefined){
var filename=queryDic[key];
var path=getFullDataPath(filename); var path=getFullDataPath(filename);
var textPromise=getTextFromFileAsync(path) var textPromise=getTextFromFileAsync(path)
btn_download=document.getElementById("btn_download"); btn_download=document.getElementById("btn_download");

View File

@ -18,7 +18,7 @@
async function update_file(filename) { async function update_file(filename) {
var file=filename+'.dat'; var file=filename+'.dat';
var lnk_file=document.getElementById('lnk_file'); var lnk_file=document.getElementById('lnk_file');
lnk_file.setAttribute('href',String.raw`view#${file}`); lnk_file.setAttribute('href',String.raw`view?dataFile=${file}`);
dat= await data.loadAsync(file); dat= await data.loadAsync(file);
await applyData(dat); await applyData(dat);
} }

View File

@ -0,0 +1,31 @@
function parseQueryStringToDictionary(queryString=window.location.search) {
var dictionary = {};
// remove the '?' from the beginning of the
// if it exists
if (queryString.indexOf('?') === 0) {
queryString = queryString.substr(1);
}
// Step 1: separate out each key/value pair
var parts = queryString.split('&amp;');
for (var i = 0; i < parts.length; i++) {
var p = parts[i];
// Step 2: Split Key/Value pair
var keyValuePair = p.split('=');
// Step 3: Add Key/Value pair to Dictionary object
var key = keyValuePair[0];
var value = keyValuePair[1];
// decode URI encoded string
value = decodeURIComponent(value);
value = value.replace(/\+/g, ' ');
dictionary[key] = value;
}
// Step 4: Return Dictionary Object
return dictionary;
}