improve asa build status text
authorMoritz Warning <moritzwarning@web.de>
Fri, 27 Mar 2020 02:11:32 +0000 (03:11 +0100)
committerPaul Spooren <mail@aparcar.org>
Fri, 27 Mar 2020 19:09:52 +0000 (09:09 -1000)
index.css
index.html
index.js
loading.gif [deleted file]
spinner.gif [new file with mode: 0644]

index a7662ca9ced88e181f4ffa1fc85e8f376d9137b0..fb4e86c36429d955fe6fe48cc8c0cdfdfdab5305 100644 (file)
--- 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;
+}
index c6cd268240d8140d2acb9651a12289524097d351..e7fe1ea1dae006179e4ef5fe1f0fe9384c15eb2e 100644 (file)
 
                <br />
                <br />
-               <img id="loading" src="loading.gif" style="display:none" alt="Logo">
+
+               <div>
+                       <img id="buildspinner" src="spinner.gif" alt="Logo">
+                       <div id="buildstatus"></div>
+               </div>
 
                <div id="images">
                        <div id="custom">
index 498547dda7c04764cb93ab0bde6dd957a3f4d61f..1bdc30f3146d0fd4cbb4ba405be5a016ff4188dd 100644 (file)
--- 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('<a href="' + url + '">' + message + '</a>');
+        } 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/loading.gif
deleted file mode 100644 (file)
index 7154314..0000000
Binary files a/loading.gif and /dev/null differ
diff --git a/spinner.gif b/spinner.gif
new file mode 100644 (file)
index 0000000..7154314
Binary files /dev/null and b/spinner.gif differ