Search code examples
google-apps-scriptweb-applicationsprogress-bar

Google App Scripting Progress Bar


I'm trying to create a progress bar in Google app scripting , which when some one click a button (Go) it will be automatically, slowly go to start to end . Something you see in Firefox download window. this is my code.

function doGet(e) {
  var app = UiApp.createApplication();
  var progressPanel = app.loadComponent("progressbar_auto");
  var gobutton =app.getElementById("go_btn");

  var go_btn_handler =app.createServerHandler("updateProgressbar");
  go_btn_handler.addCallbackElement(gobutton);
  gobutton.addClickHandler(go_btn_handler)


  app.add(progressPanel);
  return app;
}
//function time(i){
//    Utilities.sleep(5);
//  }
function updateProgressbar(){
  var app = UiApp.getActiveApplication()

  for(var i =1 ; i < 250 ; i++ ){

    app.getElementById("progress").setWidth(i + 'px');
    time();
  }
 Logger.log(i);
  return app;

}

But according to this code for loop will execute very speedy & ,progress bar completed very quick . Is there any way to slow this.

You can find the my application here.

https://sites.google.com/a/macros/dewdynamics.net/exec?service=AKfycbztKB_ljMBGi_55RrK_DH3x_pRZQ993bDoAHSsxDA

Is there any way to add a slide bar , to control the progress bar. Something we can do in php or HTML 5.

Thanks


Solution

  • No, there isn't a real way to do a progress bar on Apps Script.

    There's some workarounds though. You can add multiple handlers to the same button, and in each one, with a different sleep time, you can update the GUI many times. Or, as most do, show an endless progress gif animation in a client handler (for instant feedback) and after your second handler finishes, a ServerHandler where you actually do the work, you hide the image and return the results.