10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-07-23 03:07:44 +02:00

Add a webpage to view raw data file copy to clipboard (on supported browser like Firefox or chromium family) or download file

This commit is contained in:
Mickaël Véril 2019-09-09 15:20:30 +02:00
parent 6a4de3f44e
commit 6630ac3b28
2 changed files with 63 additions and 2 deletions

View File

@ -0,0 +1,60 @@
<!DOCTYPE html>
<html>
<head>
<title>view</title>
<meta name="save_as" content="view.html"></meta>
<meta name="date" content="2019-08-29 09:00"></meta>
</head>
<body>
<script src="{static}/scripts/getFullDataPath.js" type="text/javascript"></script>
<script src="{static}/scripts/getTextFromFile.js" type="text/javascript"></script>
<script>
window.onload=async function(){
if(typeof(navigator.clipboard) == 'undefined' || typeof(navigator.clipboard.writeText) === 'undefined'){
btn_clip=document.getElementById("btn_clip");
btn_clip.disabled = true;
btn_clip.title="This feature is not supported in this bowser\n we recomend to use Firefox or a Chromium based browser like Google Chrome"
}
if(location.hash.length>1){
var filename=location.hash.substr(1);
var path=getFullDataPath(filename);
var textPromise=getTextFromFileAsync(path)
btn_download=document.getElementById("btn_download");
btn_download.onclick=function(){
window.open(path,"_self");
}
var preNode= document.getElementById('fileContent');
preNode.hidden=false;
preNode.innerText=await textPromise;
document.getElementById("div_btn").hidden=false;
}
else {
document.getElementById('error_P').hidden=false;
errNode;
}
}
</script>
<script>
function Copy()
{
navigator.clipboard.writeText(document.getElementById('fileContent').innerText);
};
</script>
</script>
</script>
<div>
<p id="error_P" style="color: red; font-weight: bold" hidden=true>
Error
</p>
<pre id="fileContent" hidden=true></pre>
</div>
<div id="div_btn" hidden=true>
<button id="btn_clip" onclick="Copy()">Copy content</button>
<button id='btn_download'>Download</button>
</div>
</body>
</html>

View File

@ -8,6 +8,7 @@
<body>
<script src="{static}/scripts/data.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="https://cdn.rawgit.com/larsgw/citation.js/archive/citation.js/citation-0.4.0-9.js" type="text/javascript"></script>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script type="text/javascript" id="MathJax-script" async
@ -17,7 +18,7 @@
async function update_file(filename) {
var file=filename+'.dat';
var lnk_file=document.getElementById('lnk_file');
lnk_file.setAttribute('href',getFullDataPath(file));
lnk_file.setAttribute('href',String.raw`view#${file}`);
dat= await data.loadAsync(file);
await applyData(dat);
}
@ -84,6 +85,6 @@
</label><br/>
<h1>Data</h1>
<p id=data_par></p>
<a target="_blank" id='lnk_file' type='text/plain'>Go to file</a>
<a target="_blank" id='lnk_file'>Go to file</a>
</body>
</html>