From 7f8701c0a508bc377b93d64455e1294458cebb25 Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Fri, 27 Mar 2020 03:11:32 +0100 Subject: [PATCH] improve asa build status text --- index.css | 12 +++++++++ index.html | 6 ++++- index.js | 49 +++++++++++++++++++++++-------------- loading.gif => spinner.gif | Bin 4 files changed, 48 insertions(+), 19 deletions(-) rename loading.gif => spinner.gif (100%) diff --git a/index.css b/index.css index a7662ca..fb4e86c 100644 --- a/index.css +++ b/index.css @@ -205,3 +205,15 @@ header > div { .download-help { display: none; } + +#buildspinner { + float: left; + height: 40px; + padding-right: 12px; + display: none; +} + +#buildstatus { + padding: 10px 0; + display: none; +} diff --git a/index.html b/index.html index c6cd268..e7fe1ea 100644 --- a/index.html +++ b/index.html @@ -36,7 +36,11 @@

- + +
+ Logo +
+
diff --git a/index.js b/index.js index 498547d..1bdc30f 100644 --- a/index.js +++ b/index.js @@ -34,10 +34,31 @@ function build_asa_request() { }).join('/'); } + function showStatus(text) { + show('buildstatus'); + $('buildstatus').innerHTML = text; + } + + function handleError(response) { + hide('buildspinner'); + + response.json() + .then(mobj => { + var message = mobj['message'] || 'Build Failed'; + if (mobj.buildlog == true) { + var url = config.asu_url + '/store/' + mobj.bin_dir + '/buildlog.txt'; + showStatus('' + message + ''); + } else { + showStatus(message); + } + }); + } + // hide image view updateImages(); - show('loading'); + show('buildspinner'); + showStatus('Request image...'); var request_data = { 'profile': current_model.id, @@ -45,8 +66,6 @@ function build_asa_request() { 'version': $('versions').value } - console.log('disable request button / show loading spinner') - fetch(config.asu_url + '/api/build', { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -55,13 +74,13 @@ function build_asa_request() { .then(response => { switch (response.status) { case 200: - hide('loading'); + hide('buildspinner'); + showStatus('Build successful'); - console.log('image found'); response.json() .then(mobj => { console.log(mobj) - var download_url = config.asu_url + '/store/' + mobj.bin_dir + var download_url = config.asu_url + '/store/' + mobj.bin_dir; updateImages( mobj.version_number, mobj.version_commit, @@ -72,26 +91,20 @@ function build_asa_request() { }); break; case 202: - // show some spinning animation - console.log('check again in 5 seconds'); + showStatus('Check again in 5 seconds...'); setTimeout(_ => { build_asa_request() }, 5000); break; case 400: // bad request case 422: // bad package case 500: // build failed - hide('loading'); - console.log('error (' + response.status + ')'); - response.json() - .then(mobj => { - if (mobj.buildlog == true) { - $('buildlog').href = config.asu_url + '/store/' + mobj.bin_dir + '/buildlog.txt'; - show('buildlog') - } - alert(mobj.message) - }); + handleError(response); break; } }) + .catch(err => { + hide('buildspinner'); + showStatus(err); + }) } function loadFile(url, callback) { diff --git a/loading.gif b/spinner.gif similarity index 100% rename from loading.gif rename to spinner.gif -- 2.30.2