0

I am working with an angular project and I have a GET and POST $http request in my application. I used before angular loading bar on the top of the screen. But as per the new requirement I need to change the current loading bar with big circular loading bar with percentage inside and blur background.

I found Angular SVG round progress bar perfect for my problem. I have checked their website and Gitlab, but I did not found that how can I integrate with my submit form action? (Basically I submit a form to the server and I get response, but It takes too long time that's why I want this circular progress bar in between)

Any help would be appreciated...:)

UPDATE

My HTML looks something like this,

<form ng-submit="ctrl.submitSearch()">
   <input type="text">
   <input type="text">
   <input type="checkbox">

   <button> Start </button>
</form>

/* Result Table */

<table>
</table>

Example circular loading bar (This is how I want) http://crisbeto.github.io/angular-svg-round-progressbar/

EDIT

currently I have that progress bar element like this,

<!--Background element when loading is in progress -->
<div class="overlay" ng-show="loading"></div>

    <!--Angular SVG circular loading bar -->
    <div class="popup"
        ng-show="loading"
        round-progress
        max="100"
        current="current"
        color="#64b8e3"
        bgcolor="#008acf"
        radius="100"
        stroke="20"
        semi="false"
        rounded="true"
        clockwise="true"
        responsive="false"
        duration="800"
        animation="easeInOutQuart">
    </div> 

And here is my current CSS,

/* CSS for adding blury black background while loading is in progress */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  padding-left: 0;
  padding-top: 0;
  z-index: 998;
  background-color: Black;
  opacity: .5;
} 

/* CSS for loading bar */
.popup {
  position: fixed;
  z-index: 999;
  padding-left: 45%;
}

Everything is working perfect except the position of circular loading bar, which I want on the center of the page and fixed while scrolling.

Harsh Soni
  • 41
  • 1
  • 4
  • 12
  • Please include what you have tried so far. – Paul LeBeau Nov 03 '15 at 14:13
  • @Paul LeBeau : Hey Paul, I haven't write any code yet to do so. Because I don't know where to start. To be more specific, let me add some code. – Harsh Soni Nov 03 '15 at 14:17
  • am I correct in saying you want to show a percentage completion for a POST request, but don't have a mechanism for checking how far your request has progressed? – TygerKrash Nov 03 '15 at 14:39
  • @TygerKrash: I think there is a mechanism available for this problem. And what I want is when I submit my form then first POST request is processed and after that immediately the GET request is also processed to show the table. I want in-between this time a circular progress bar. – Harsh Soni Nov 03 '15 at 14:46
  • Can you include an example of the kind of progress bar you want to display ( a link to the one you mention would do) – TygerKrash Nov 03 '15 at 14:55
  • @TygerKrash : yes sure. here is the link. http://crisbeto.github.io/angular-svg-round-progressbar/ – Harsh Soni Nov 03 '15 at 14:56
  • you should include any updates/clarifications as an edit to your question rather than a comment reply. Another question for you, ctrl.submitSearch performs your Post request? is it an async call? Also to be clear when I asked about the mechanism.. unless you know how long the call will take or can find out how far the post request has been processed you can't display an absolute percentage only and indicator that work is in progress. (e.g if your file processes 100 files and you can query to find out 50 are processed you can say 50%, but without that you can't usefully use a %) – TygerKrash Nov 03 '15 at 15:05
  • @TygerKrash: Yes I have now updated my question. And yes ctrl.submitSearch() performs a POST request. To be more specific it performs 2 POST request and based on POST request it also receives 2 responses and these responses are my two tables in HTML. Yes percentage hat not to be perfect, As you can see in the example link that the numbers are increasing till 50 and when the whole process is done then it shows directly 50. It does not has to be match with the process. – Harsh Soni Nov 03 '15 at 15:15
  • based on this
    I assume you have a $scope.loading that you are setting to true when you start your post? (if you remove that ' ng-show="loading"' does it appear?)
    – TygerKrash Nov 04 '15 at 16:49
  • No, it doesn't. I think this is because of overlay class. Because All the functions are working except center progress bar when I remove overlay class. When I add overlay class then progress bar is disappears. And I have also updated my submit function in question. Please check. – Harsh Soni Nov 04 '15 at 16:54
  • I'd have a look with the chrome developer tools to inspect the runtime CSS of the elements.. it might be you are inheriting something from a parent or another selector, that's affecting visibility of the element. failing that. strip down the content of the overlay class one at a time until you can identify which element is affecting your view. – TygerKrash Nov 04 '15 at 17:08

1 Answers1

1

Assuming your posts are async this fiddle shows how you might do it.

you set up angular bindings as follows:

1) use ng-class on a div or other element you can bind the blur css class, depending on the structure of your code, you might want to unset the 'blur' css class on the progress meter.

2) on the progress meter bind the 'current' property to a ticks counter variable in your $scope.

3) when you submit your post, also kick off an $interval with a tick increment function which recurs until you get your post callback(s) which will stop the increment, reset the blur class on your div and populate the results table.

You mention you've got two posts, you might want to explicitly set the value of currentTicks when you get the first response ( for example if that represented 50% of the work you'd set it to 50).

you'll likely need to work some css absolute position magic to get your progress meter to appear in the exact right place (and mine is displayed from the outset, but you can use a bound css class to make it display:none until its ready to show)

edit: I didn't mention the blur css, I've just lifted it from BenSlight's answer here Blur effect on a div element

edit refined blur ...

form.blur {
  -webkit-filter: blur(2px);
  -moz-filter: blur(2px);
  -o-filter: blur(2px);
  -ms-filter: blur(2px);
  filter: blur(2px);
}

some additional info based on comments. - on completion of your POST you'll need to remove the blur class from the element if you've bound the class to an angular element (say bgClass) $scope.bgClass =""; will clear it.

  • re: timings, the problem with using this particular visualisation as a percentage is that you have to somehow know when it's going to reach 100%. i.e. the calls always finished after 40 seconds or you are polling or getting callbacks every few seconds with an indicator of progress. The best you can do with the current set up I've outlined here and keeping it percentage based is to adjust your interval amount or the max value on the chart so that it definitely doesn't finish before your POST processing completes.

-re: positioning your overlay there's some static css applied to the progress div that makes it a bit tricky, but you can put a separate div around it and apply the following style to that (again, you'll want to add this class to the element on when you start the process, and remove it once the POST completes) - you'll probably need to tweak those padding values for best results. If you have a look around SO you'll probably find simpler cleaner css for overlays tbh. (I've updated the fiddle with an example)

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    max-width: 100px;
    height: 100%;
    margin: 0 auto;
    padding-left: 40%;
    padding-top: 30%;
    z-index: 5;
}
Community
  • 1
  • 1
TygerKrash
  • 1,362
  • 2
  • 20
  • 38
  • first of all thank you for your answer. I applied the same solution but I did not get the perfect result how I want. When I apply blur effect to form then all another form CSS are destroyed and it looks ugly. Also the progress counter is working as predefined. It is not matching with the response time. (I mean the progress of circle finishes earlier then my resulted table appear on the screen). The question of positioning the circular loading bar is still open and after having resulted table the blur effect is still active.??? – Harsh Soni Nov 04 '15 at 13:43
  • I've updated the answer with some more info - a version of that blur that you might find easier to work with. But really I think without having an interactive process where you know what progress actually is at a given point in time or at regular intervals then I think you're better off just presenting the blurred form with an endless animated GIF progress loop overlayed . The percentage based view is misleading in that case and is code you don't need. – TygerKrash Nov 04 '15 at 15:14
  • Hey thank you for your update. Many things I solved. Just two thing remaining. How can I show my circular progress bar on the center of the screen. (It has to overlap my form)??? And I will try your updated blur effect. – Harsh Soni Nov 04 '15 at 15:20
  • No, this overlay is not working for me. It makes my form unactive. – Harsh Soni Nov 04 '15 at 16:22
  • That's because when that class is applied to an element that element is 'on top' of everything else on the page (and therefore gets all the 'click' events. But you'll only enable that overlay while the progress meter is going, and that's only happening you're waiting on the page to update - I've assumed during that time the user shouldn't be able to interact with the form? – TygerKrash Nov 04 '15 at 16:31
  • Yes you are right. When I removed the padding then I can interact with the form. And yes it is right that when progress bar is going on at that time user is not allowed to interact. Please check my updated question again to see my HTML. – Harsh Soni Nov 04 '15 at 16:38
  • I've updated my fiddle to similar to your code , seems to work fine. assuming you have a $scope.current? https://fiddle.jshell.net/c1k13uaa/3/ – TygerKrash Nov 04 '15 at 16:54
  • Hey TygerKrash, based on your answer I completed 90% of my work. And now everything is working perfect except the position of my
    element which is the circular loading bar. It appears like a normal div but I want it on the center of the screen and also fixed while scrolling page. I have also updated my code. Please check and give your suggestion. Thank you.
    – Harsh Soni Nov 05 '15 at 18:40
  • glad it helped. as for your div position.. I'm not sure exactly what the issue is... it works fine for me with the absolute position.. I've given it a different approach just to be sure though. have a look at the fiddle now https://fiddle.jshell.net/c1k13uaa/4/ you'll see I've got a diffferent overlay with fixed position. padding-left/padding-top can be used to position the progress meter. or more clumsily you can add a div inside with a width: the same size as the progress div, then give it "margin: 0 auto" to centre. – TygerKrash Nov 05 '15 at 20:51