10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-25 13:53:48 +01:00

using async await when is possible

This commit is contained in:
Mickaël Véril 2019-09-05 10:32:46 +02:00
parent 084ea6373c
commit 9b1a445998
2 changed files with 28 additions and 17 deletions

View File

@ -13,16 +13,19 @@
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async> src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async>
</script> </script>
<script> <script>
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',getFullDataPath(file)); lnk_file.setAttribute('href',getFullDataPath(file));
data.load(file,onApplyData); dat= await data.loadAsnyc(file);
await applyData(dat);
} }
function onApplyData(dat) { async function applyData(dat) {
const Cite = require('citation-js'); const Cite = require('citation-js');
const LatexInline=['\\(','\\)']; // Start a async task to get publi
var par=document.getElementById("data_par"); let publitask = Cite.async(dat.doi.string)
const LatexInline=['\\(','\\)']
var par=document.getElementById("data_par")
par.innerHTML=''; par.innerHTML='';
var md=[]; var md=[];
var els=[]; var els=[];
@ -45,8 +48,9 @@
par.appendChild(node); par.appendChild(node);
}); });
var publi = new Cite(dat.doi.string)
var lnkdoi = document.createElement("a"); var lnkdoi = document.createElement("a");
// Wait for the value of publi when required
let publi=await publitask;
let output = publi.format('bibliography', { let output = publi.format('bibliography', {
format: 'html', format: 'html',
template: 'apa', template: 'apa',
@ -67,7 +71,7 @@
</script> </script>
<label>Write a data file name without extension<br/> <label>Write a data file name without extension<br/>
<input type="text" id='inp_filename' onkeydown="onKeyDown(event)"></input> <input type="text" id='inp_filename' onkeydown="onKeyDown(e)"></input>
</label><br/> </label><br/>
<p id=data_par></p> <p id=data_par></p>
<a target="_blank" id='lnk_file' type='text/plain'>Go to file</a> <a target="_blank" id='lnk_file' type='text/plain'>Go to file</a>

View File

@ -70,18 +70,25 @@ class data {
this.doi=null; this.doi=null;
this.excitations=[]; this.excitations=[];
} }
static load(file,fn) { static async loadAsync(file) {
var req = new XMLHttpRequest(); return new Promise(function (resolve, reject) {
req.open("GET",getFullDataPath(file), true); var req = new XMLHttpRequest();
req.onreadystatechange = function() { req.open("GET",getFullDataPath(file), true);
if (req.readyState == 4 && req.status == 200) {//when a good response is given do this req.onreadystatechange = function() {
var text = req.responseText; if (req.readyState == 4 && req.status == 200) {//when a good response is given do this
fn(data.loadstring(text)); var text = req.responseText;
} resolve(data.loadString(text))
} } else {
reject({
status: req.status,
statusText: req.statusText
});
}
};
req.send(); req.send();
});
} }
static loadstring(text) { static loadString(text) {
// for each line with metadata // for each line with metadata
var ismetaArea=true; var ismetaArea=true;
//metadata RegExp (start with #; maybe somme spaces; : ; maybe somme space; datas) //metadata RegExp (start with #; maybe somme spaces; : ; maybe somme space; datas)