Skip to contentSkip to conversation

toaster: show loading spinner after creating custom image

PATCH In review Elliot Smith 2 participants 2 messages Jul 25, 2016 – Jul 27, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 toaster: show loading spinner after creating custom image

Creating a custom image through the "New custom image" dialog can sometimes result in a long pause between pressing the button to create the image, and being transferred to the page showing details of its content. This can make it appear as though pressing the button had no effect.

To prevent this from happening, disable the button and text box in the new custom image dialog after the "Create image" button is pressed. Also show a loading spinner and "loading..." text on the button to make it clear that the application is still responding.

[YOCTO #9475]

---
 .../lib/toaster/toastergui/static/css/default.css  | 12 ++++++++
 .../lib/toaster/toastergui/static/js/libtoaster.js | 20 +++++++++++--
 .../toastergui/static/js/newcustomimage_modal.js   | 33 ++++++++++++++++++++--
 .../toastergui/templates/newcustomimage_modal.html |  7 ++++-
 4 files changed, 66 insertions(+), 6 deletions(-)
bitbake/lib/toaster/toastergui/static/css/default.css +12 -0
index 0d3570a..96eedfc 100644
@@ -249,6 +249,18 @@ code { color: #333; background-color: transparent; }
 /* Style the special no results message in the custom image details page */
 [id^="no-results-special-"] > .alert-warning > ol { margin-top: 10px; }
 
+/* style the loading spinner in the new custom image dialog */
+#create-new-custom-image-btn [data-role="loading-state"] {
+  padding-left: 16px;
+}
+
+/* icon has to be absolutely positioned, otherwise the spin animation doesn't work */
+#create-new-custom-image-btn [data-role="loading-state"] .icon-spinner {
+  position: absolute;
+  left: 26px;
+  bottom: 26px;
+}
+
 /* Style the content of modal dialogs */
 .modal-footer { text-align: left; }
 .date-filter-controls { margin-top: 10px; }
bitbake/lib/toaster/toastergui/static/js/libtoaster.js +18 -2
index eafe70d..b8bf1a2 100644
@@ -421,8 +421,23 @@ var libtoaster = (function () {
      });
   }
 
+  // if true, the loading spinner for Ajax requests will be displayed
+  // if requests take more than 1200ms
+  var ajaxLoadingTimerEnabled = true;
+
+  // turn on the page-level loading spinner for Ajax requests
+  function _enableAjaxLoadingTimer() {
+    ajaxLoadingTimerEnabled = true;
+  }
+
+  // turn off the page-level loading spinner for Ajax requests
+  function _disableAjaxLoadingTimer() {
+    ajaxLoadingTimerEnabled = false;
+  }
 
   return {
+    enableAjaxLoadingTimer: _enableAjaxLoadingTimer,
+    disableAjaxLoadingTimer: _disableAjaxLoadingTimer,
     reload_params : reload_params,
     startABuild : _startABuild,
     cancelABuild : _cancelABuild,
@@ -469,7 +484,6 @@ function reload_params(params) {
     window.location.href = url+"?"+callparams.join('&');
 }
 
-
 /* Things that happen for all pages */
 $(document).ready(function() {
 
@@ -628,7 +642,9 @@ $(document).ready(function() {
         window.clearTimeout(ajaxLoadingTimer);
 
       ajaxLoadingTimer = window.setTimeout(function() {
-        $("#loading-notification").fadeIn();
+        if (libtoaster.ajaxLoadingTimerEnabled) {
+          $("#loading-notification").fadeIn();
+        }
       }, 1200);
     });
 
bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js +30 -3
index 8356c02..dace8e3 100644
@@ -25,7 +25,11 @@ function newCustomImageModalInit(){
   var duplicateNameMsg = "An image with this name already exists. Image names must be unique.";
   var duplicateImageInProjectMsg = "An image with this name already exists in this project."
   var invalidBaseRecipeIdMsg = "Please select an image to customise.";
-	
+
+  // set button to "submit" state and enable text entry so user can
+  // enter the custom recipe name
+  showSubmitState();
+
   /* capture clicks on radio buttons inside the modal; when one is selected,
    * set the recipe on the modal
    */
@@ -40,6 +44,9 @@ function newCustomImageModalInit(){
   });
 
   newCustomImgBtn.click(function(e){
+    // disable the button and text entry
+    showLoadingState();
+
     e.preventDefault();
 
     var baseRecipeId = imgCustomModal.data('recipe');
@@ -69,12 +76,33 @@ function newCustomImageModalInit(){
           }
         } else {
           imgCustomModal.modal('hide');
+          imgCustomModal.one('hidden.bs.modal', showSubmitState);
           window.location.replace(ret.url + '?notify=new');
         }
       });
     }
   });
 
+  // enable text entry, show "Create image" button text
+  function showSubmitState() {
+    libtoaster.enableAjaxLoadingTimer();
+    newCustomImgBtn.find('[data-role="loading-state"]').hide();
+    newCustomImgBtn.find('[data-role="submit-state"]').show();
+    newCustomImgBtn.removeAttr('disabled');
+    nameInput.removeAttr('disabled');
+  }
+
+  // disable text entry, show "Creating image..." button text;
+  // we also disabled the page-level ajax loading spinner while this spinner
+  // is active
+  function showLoadingState() {
+    libtoaster.disableAjaxLoadingTimer();
+    newCustomImgBtn.find('[data-role="submit-state"]').hide();
+    newCustomImgBtn.find('[data-role="loading-state"]').show();
+    newCustomImgBtn.attr('disabled', 'disabled');
+    nameInput.attr('disabled', 'disabled');
+  }
+
   function showNameError(text){
     invalidNameHelp.text(text);
     invalidNameHelp.show();
@@ -167,6 +195,5 @@ function newCustomImageModalSetRecipes(baseRecipes) {
 
     // show the radio button container
     imageSelector.show();
-	 
-  }	
+  }
 }
bitbake/lib/toaster/toastergui/templates/newcustomimage_modal.html +6 -1
index 5caa683..d448d3a 100644
@@ -48,7 +48,12 @@
       </div>
 
       <div class="modal-footer">
-        <button id="create-new-custom-image-btn" class="btn btn-primary btn-lg" data-original-title="" title="" disabled>Create custom image</button>
+        <button id="create-new-custom-image-btn" class="btn btn-primary btn-large" disabled>
+          <span data-role="submit-state">Create custom image</span>
+          <span data-role="loading-state" style="display:none">
+            <i class="fa-pulse icon-spinner"></i>&nbsp;Creating custom image...
+          </span>
+        </button>
       </div>
     </div>
   </div>
Signature · 1 line
2.7.4
#1 lore raw
Quoted 6 lines · On 25/07/2016 08:57, "[email protected] on behalf of Elliot…

Creating a custom image through the "New custom image" dialog can sometimes result in a long pause between pressing the button to create the image, and being transferred to the page showing details of its content. This can make it appear as though pressing the button had no effect.

Quoted 6 lines

To prevent this from happening, disable the button and text box in the new custom image dialog after the "Create image" button is pressed. Also show a loading spinner and "loading..." text on the button to make it clear that the application is still responding.

[YOCTO #9475]

This works for me.

Thanks!

Belén

Quoted 191 lines

---

.../lib/toaster/toastergui/static/css/default.css  | 12 ++++++++
.../lib/toaster/toastergui/static/js/libtoaster.js | 20 +++++++++++--
.../toastergui/static/js/newcustomimage_modal.js   | 33
++++++++++++++++++++--
.../toastergui/templates/newcustomimage_modal.html |  7 ++++-
4 files changed, 66 insertions(+), 6 deletions(-)
bitbake/lib/toaster/toastergui/static/css/default.css +6 -0
index 0d3570a..96eedfc 100644
@@ -249,6 +249,18 @@ code { color: #333; background-color: transparent; }
 /* Style the special no results message in the custom image details page
 */
 [id^="no-results-special-"] > .alert-warning > ol { margin-top: 10px; }
 
+/* style the loading spinner in the new custom image dialog */
+#create-new-custom-image-btn [data-role="loading-state"] {
+  padding-left: 16px;
+}
+
+/* icon has to be absolutely positioned, otherwise the spin animation

doesn't work */

bitbake/lib/toaster/toastergui/static/css/default.css +6 -0
+#create-new-custom-image-btn [data-role="loading-state"] .icon-spinner {
+  position: absolute;
+  left: 26px;
+  bottom: 26px;
+}
+

/* Style the content of modal dialogs */
.modal-footer { text-align: left; }
.date-filter-controls { margin-top: 10px; }

bitbake/lib/toaster/toastergui/static/js/libtoaster.js +18 -2
index eafe70d..b8bf1a2 100644
@@ -421,8 +421,23 @@ var libtoaster = (function () {
     });
  }
 
+  // if true, the loading spinner for Ajax requests will be displayed
+  // if requests take more than 1200ms
+  var ajaxLoadingTimerEnabled = true;
+
+  // turn on the page-level loading spinner for Ajax requests
+  function _enableAjaxLoadingTimer() {
+    ajaxLoadingTimerEnabled = true;
+  }
+
+  // turn off the page-level loading spinner for Ajax requests
+  function _disableAjaxLoadingTimer() {
+    ajaxLoadingTimerEnabled = false;
+  }
 
  return {
+    enableAjaxLoadingTimer: _enableAjaxLoadingTimer,
+    disableAjaxLoadingTimer: _disableAjaxLoadingTimer,
    reload_params : reload_params,
    startABuild : _startABuild,
    cancelABuild : _cancelABuild,
@@ -469,7 +484,6 @@ function reload_params(params) {
    window.location.href = url+"?"+callparams.join('&');
 }
 
-
 /* Things that happen for all pages */
 $(document).ready(function() {
 
@@ -628,7 +642,9 @@ $(document).ready(function() {
        window.clearTimeout(ajaxLoadingTimer);
 
      ajaxLoadingTimer = window.setTimeout(function() {
-        $("#loading-notification").fadeIn();
+        if (libtoaster.ajaxLoadingTimerEnabled) {
+          $("#loading-notification").fadeIn();
+        }
      }, 1200);
    });
 
(quoted diff) +0 -0

a/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js b/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js index 8356c02..dace8e3 100644

bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js +0 -0
@@ -25,7 +25,11 @@ function newCustomImageModalInit(){
  var duplicateNameMsg = "An image with this name already exists. Image
 names must be unique.";
  var duplicateImageInProjectMsg = "An image with this name already

exists in this project."
var invalidBaseRecipeIdMsg = "Please select an image to customise.";

bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js +5 -1
-	
+
+  // set button to "submit" state and enable text entry so user can
+  // enter the custom recipe name
+  showSubmitState();
+
  /* capture clicks on radio buttons inside the modal; when one is

selected,
* set the recipe on the modal
*/

bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js +15 -0
@@ -40,6 +44,9 @@ function newCustomImageModalInit(){
  });
 
  newCustomImgBtn.click(function(e){
+    // disable the button and text entry
+    showLoadingState();
+
    e.preventDefault();
 
    var baseRecipeId = imgCustomModal.data('recipe');
@@ -69,12 +76,33 @@ function newCustomImageModalInit(){
          }
        } else {
          imgCustomModal.modal('hide');
+          imgCustomModal.one('hidden.bs.modal', showSubmitState);
          window.location.replace(ret.url + '?notify=new');
        }
      });
    }
  });
 
+  // enable text entry, show "Create image" button text
+  function showSubmitState() {
+    libtoaster.enableAjaxLoadingTimer();
+    newCustomImgBtn.find('[data-role="loading-state"]').hide();
+    newCustomImgBtn.find('[data-role="submit-state"]').show();
+    newCustomImgBtn.removeAttr('disabled');
+    nameInput.removeAttr('disabled');
+  }
+
+  // disable text entry, show "Creating image..." button text;
+  // we also disabled the page-level ajax loading spinner while this

spinner

bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js +10 -2
+  // is active
+  function showLoadingState() {
+    libtoaster.disableAjaxLoadingTimer();
+    newCustomImgBtn.find('[data-role="submit-state"]').hide();
+    newCustomImgBtn.find('[data-role="loading-state"]').show();
+    newCustomImgBtn.attr('disabled', 'disabled');
+    nameInput.attr('disabled', 'disabled');
+  }
+
  function showNameError(text){
    invalidNameHelp.text(text);
    invalidNameHelp.show();
@@ -167,6 +195,5 @@ function newCustomImageModalSetRecipes(baseRecipes) {
 
    // show the radio button container
    imageSelector.show();
-	 
-  }	
+  }
 }
(quoted diff) +0 -0

a/bitbake/lib/toaster/toastergui/templates/newcustomimage_modal.html b/bitbake/lib/toaster/toastergui/templates/newcustomimage_modal.html index 5caa683..d448d3a 100644

bitbake/lib/toaster/toastergui/templates/newcustomimage_modal.html +0 -1
@@ -48,7 +48,12 @@
      </div>
 
      <div class="modal-footer">
-        <button id="create-new-custom-image-btn" class="btn btn-primary

btn-lg" data-original-title="" title="" disabled>Create custom image</button>
+ <button id="create-new-custom-image-btn" class="btn btn-primary
btn-large" disabled>

bitbake/lib/toaster/toastergui/templates/newcustomimage_modal.html +3 -0
+          <span data-role="submit-state">Create custom image</span>
+          <span data-role="loading-state" style="display:none">
+            <i class="fa-pulse icon-spinner"></i>&nbsp;Creating custom

image...

bitbake/lib/toaster/toastergui/templates/newcustomimage_modal.html +2 -0
+          </span>
+        </button>
      </div>
    </div>
  </div>
Signature · 7 lines
2.7.4

-- 
_______________________________________________
toaster mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/toaster