diff --git a/web/index.css b/web/index.css index b338b27..a4ad5bb 100644 --- a/web/index.css +++ b/web/index.css @@ -316,4 +316,22 @@ body { #adminPassInput { margin-bottom: 1em; } - \ No newline at end of file + input#uploadFile { + margin-top: 0.5em; + margin-bottom: 0.5em; + } + div#uploadProgress { + width: 100%; + max-width: 20em; + height: 1em; + margin-left: 1em; + /* margin-right: auto; */ + border: 1px solid grey; + margin-top: 0.5em; + margin-bottom: 0.5em; +} +#uploadDone{ + background-color: blue; + width: 0px; + height: 100%; +} \ No newline at end of file diff --git a/web/index.html b/web/index.html index 64917e3..a9bad2c 100644 --- a/web/index.html +++ b/web/index.html @@ -76,10 +76,20 @@
diff --git a/web/index.js b/web/index.js index 1b5b7cc..dc1757f 100644 --- a/web/index.js +++ b/web/index.js @@ -85,6 +85,9 @@ function update() { else { let el = document.getElementById(k); if (el) el.textContent = jsonData[k]; + forEl('.status-'+k,function(el){ + el.textContent=jsonData[k]; + }); } } lastUpdate = (new Date()).getTime(); @@ -1447,13 +1450,50 @@ function updateDashboard(data) { } function uploadBin(){ let el=document.getElementById("uploadFile"); + let progressEl=document.getElementById("uploadDone"); if (! el) return; if ( el.files.length < 1) return; ensurePass() .then (function(hash){ + let file=el.files[0]; + let len=file.size; let req = new XMLHttpRequest(); req.onloadend=function(){ - alert("upload complete"); + let result="unknown error"; + try{ + let jresult=JSON.parse(req.responseText); + if (jresult.status == 'OK'){ + result=''; + } + else{ + if (jresult.status) { + result=jresult.status; + } + } + }catch (e){ + result="Error "+req.status; + } + if (progressEl){ + progressEl.style.width=0; + } + if (! result){ + alertRestart(); + } + else{ + alert("update error: "+result); + } + } + req.onerror=function(e){ + alert("unable to upload: "+e); + } + if (progressEl){ + progressEl.style.width=0; + req.upload.onprogress=function(ev){ + if (ev.lengthComputable){ + let percent=100*ev.loaded/ev.total; + progressEl.style.width=percent+"%"; + } + } } let formData = new FormData(); formData.append("file1", el.files[0]);