mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2024-12-25 13:53:48 +01:00
Add external file support
This commit is contained in:
parent
7186c7695d
commit
595b90f798
@ -34,11 +34,34 @@ draft: false
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
window.dats=await Promise.all(proms)
|
window.dats=await Promise.all(proms)
|
||||||
reloadSelect()
|
reloadFileSelector()
|
||||||
await reloadContent()
|
await reloadSelect()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
function reloadSelect(){
|
function reloadFileSelector(){
|
||||||
|
document.getElementById("customFiles_input").value = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reloadSelect(){
|
||||||
|
radioval=$('#form_dat > input[name=datatype]:checked').val();
|
||||||
|
for(file of Array.from(document.getElementById("customFiles_input").files))
|
||||||
|
{
|
||||||
|
switch (radioval) {
|
||||||
|
case "abs":
|
||||||
|
var dat=await AbsDataFile.loadAsync(file)
|
||||||
|
window.dats.push(dat)
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "fluo":
|
||||||
|
dat=await FluoDataFile.loadAsync(file)
|
||||||
|
window.dats.push(dat)
|
||||||
|
break;
|
||||||
|
case "ZPE":
|
||||||
|
dat=await ZPEDataFile.loadAsync(file)
|
||||||
|
window.dats.push(dat)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
$('#form_dat > select').each(function(){
|
$('#form_dat > select').each(function(){
|
||||||
$(this).find('option[value!=""]').remove()
|
$(this).find('option[value!=""]').remove()
|
||||||
const vals=uniq(window.dats.map((d)=>{return d[$(this).attr("name")]}))
|
const vals=uniq(window.dats.map((d)=>{return d[$(this).attr("name")]}))
|
||||||
@ -49,6 +72,7 @@ draft: false
|
|||||||
$(this).append(op)
|
$(this).append(op)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
await reloadContent()
|
||||||
}
|
}
|
||||||
async function reloadStat(){
|
async function reloadStat(){
|
||||||
var stb=document.getElementById("stat_table_b");
|
var stb=document.getElementById("stat_table_b");
|
||||||
@ -162,7 +186,7 @@ draft: false
|
|||||||
var lnkfile=document.createElement("a")
|
var lnkfile=document.createElement("a")
|
||||||
lnkfile.target="_blank"
|
lnkfile.target="_blank"
|
||||||
lnkfile.innerText="Go to file"
|
lnkfile.innerText="Go to file"
|
||||||
lnkfile.href=d.sourceFile.viewerUrl
|
lnkfile.href=await d.sourceFile.getViewerURL()
|
||||||
row.appendChild(lnkfile)
|
row.appendChild(lnkfile)
|
||||||
dtb.appendChild(row)
|
dtb.appendChild(row)
|
||||||
}
|
}
|
||||||
@ -179,6 +203,9 @@ draft: false
|
|||||||
<input type="radio" id="zpe" value="zpe" name="datatype">
|
<input type="radio" id="zpe" value="zpe" name="datatype">
|
||||||
<label for="zpe">\(\Delta \text{ZPE}\)</label>
|
<label for="zpe">\(\Delta \text{ZPE}\)</label>
|
||||||
<br/>
|
<br/>
|
||||||
|
<label for="customFiles">Add custom data file</label>
|
||||||
|
<input type="file" multiple onchange="reloadSelect()" id="customFiles_input"></input>
|
||||||
|
<br/>
|
||||||
<label for="mol_select">Molecule</label>
|
<label for="mol_select">Molecule</label>
|
||||||
<select multiple id="mol_select" onchange="reloadContent()" name="molecule"></select>
|
<select multiple id="mol_select" onchange="reloadContent()" name="molecule"></select>
|
||||||
<label for="code_select">Code</label>
|
<label for="code_select">Code</label>
|
||||||
|
@ -114,7 +114,7 @@ draft: false
|
|||||||
node=document.createElement("a")
|
node=document.createElement("a")
|
||||||
node.innerText="Go to file"
|
node.innerText="Go to file"
|
||||||
node.target='_blank'
|
node.target='_blank'
|
||||||
node.href=element.viewerUrl
|
node.href= await element.getViewerURL()
|
||||||
break
|
break
|
||||||
case "Array":
|
case "Array":
|
||||||
k=element[0]
|
k=element[0]
|
||||||
|
@ -24,21 +24,30 @@ draft: false
|
|||||||
console.warn(mystr);
|
console.warn(mystr);
|
||||||
}
|
}
|
||||||
queryDic=parseQueryStringToDictionary()
|
queryDic=parseQueryStringToDictionary()
|
||||||
key="dataFile"
|
key=["file","fileBase64"]
|
||||||
if(queryDic[key]!=undefined){
|
if(key[0] in queryDic){
|
||||||
var filename=queryDic[key];
|
var filename=queryDic[key[0]];
|
||||||
var path=getFullDataPath(filename);
|
var textPromise=getTextFromFileUrlAsync(filename)
|
||||||
var textPromise=getTextFromFileAsync(path)
|
|
||||||
btn_download=document.getElementById("btn_download");
|
btn_download=document.getElementById("btn_download");
|
||||||
btn_download.onclick=function(){
|
btn_download.onclick=function(){
|
||||||
window.open(path,"_self");
|
window.open(filename,"_self");
|
||||||
}
|
}
|
||||||
document.getElementById('fileTitle').innerText=filename;
|
document.getElementById('fileTitle').innerText=filename;
|
||||||
document.getElementById('fileContent').innerText=await textPromise;
|
document.getElementById('fileContent').innerText=await textPromise;
|
||||||
document.getElementById('file').hidden=false;
|
document.getElementById('file').hidden=false;
|
||||||
document.getElementById("div_btn").hidden=false;
|
document.getElementById("div_btn").hidden=false;
|
||||||
|
} else if(key[1] in queryDic){
|
||||||
|
var base64=queryDic[key[1]];
|
||||||
|
btn_download=document.getElementById("btn_download");
|
||||||
|
btn_download.onclick=function(){
|
||||||
|
window.open(String.raw`data:application/pdf;base64,${Base64}`,"_self")
|
||||||
|
}
|
||||||
|
document.getElementById('fileTitle').hudden=true
|
||||||
|
document.getElementById('fileContent').innerText=atob(base64)
|
||||||
|
document.getElementById('file').hidden=false;
|
||||||
|
document.getElementById("div_btn").hidden=false;
|
||||||
}
|
}
|
||||||
else {
|
else{
|
||||||
document.getElementById('error_P').hidden=false;
|
document.getElementById('error_P').hidden=false;
|
||||||
errNode;
|
errNode;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,16 @@ class dataFileBase {
|
|||||||
this.sourceFile=null
|
this.sourceFile=null
|
||||||
}
|
}
|
||||||
static async loadAsync(file) {
|
static async loadAsync(file) {
|
||||||
var dat = this.loadString(await getTextFromFileAsync(getFullDataPath(file)));
|
switch (trueTypeOf(file)) {
|
||||||
|
case "string":
|
||||||
|
file=getFullDataPath(file)
|
||||||
|
var str=await getTextFromFileUrlAsync(file)
|
||||||
|
break;
|
||||||
|
case "File":
|
||||||
|
var str=await getTextFromUploadedFileAsync(file)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
var dat = this.loadString(str);
|
||||||
dat.sourceFile=new websiteFile(file)
|
dat.sourceFile=new websiteFile(file)
|
||||||
return dat
|
return dat
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
async function getTextFromFileAsync(file) {
|
async function getTextFromFileUrlAsync(url) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
var req = new XMLHttpRequest();
|
var req = new XMLHttpRequest();
|
||||||
req.open("GET",file, true);
|
req.open("GET",url, true);
|
||||||
req.onreadystatechange = function() {
|
req.onreadystatechange = function() {
|
||||||
if (req.readyState == 4) {
|
if (req.readyState == 4) {
|
||||||
if (req.status == 200) {//when a good response is given do this
|
if (req.status == 200) {//when a good response is given do this
|
||||||
@ -17,4 +17,20 @@ async function getTextFromFileAsync(file) {
|
|||||||
}
|
}
|
||||||
req.send();
|
req.send();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getTextFromUploadedFileAsync(inputFile){
|
||||||
|
const temporaryFileReader = new FileReader();
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
temporaryFileReader.onerror = () => {
|
||||||
|
temporaryFileReader.abort();
|
||||||
|
reject(new DOMException("Problem parsing input file."));
|
||||||
|
};
|
||||||
|
|
||||||
|
temporaryFileReader.onload = () => {
|
||||||
|
resolve(temporaryFileReader.result);
|
||||||
|
};
|
||||||
|
temporaryFileReader.readAsText(inputFile);
|
||||||
|
});
|
||||||
|
};
|
@ -1,8 +1,18 @@
|
|||||||
class websiteFile{
|
class websiteFile{
|
||||||
constructor(path){
|
constructor(file){
|
||||||
this.path=path
|
this.file=file
|
||||||
}
|
}
|
||||||
get viewerUrl(){
|
|
||||||
return String.raw`/view?dataFile=${this.path}`
|
async getViewerURL(){
|
||||||
|
var urlbase="/view"
|
||||||
|
switch (trueTypeOf(this.file)) {
|
||||||
|
case "string":
|
||||||
|
return String.raw`${urlbase}?file=${this.file}`
|
||||||
|
break
|
||||||
|
case "File":
|
||||||
|
var base64=btoa(await getTextFromUploadedFileAsync(this.file))
|
||||||
|
return String.raw`${urlbase}?fileBase64=${base64}`;
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user