4 Replies Latest reply: Oct 7, 2015 5:25 AM by Loris Lombardo RSS

    Mashup - open connection

    Loris Lombardo

      Hi all!

       

      which is the best way to know if there is an open connection between the html client and the sense server?

       

      what i want to do is to show a spinner, or something like that, to notify the user that something is going on behind the scene.

      and i want only a spinner for the whole application.

       

      thanks.

      Loris

        • Re: Mashup - open connection
          Erik Wetterberg

          Hi Loris,

          depends on what you mean by open connection. openApp will open a web socket to the engine immediately, and this will be pretty fast (depends on authentication). Then the QIX engine will load the app if its not already loaded.

           

          When you then do getObject (or createCube or something) engine will calculate values for the object and send to the client. You know that this is ready when the promise that getObject (and createCube) resolves. So if you want to hide your spinner when you have got the visualizations you could use this, something like this:

           

          app.getObject( 'QV01', id ).then( function ( model ) {
            //we have the visualization
            hideSpinner();
          });
          

           

          If you want to wait for several (all??) your objects this will be a bit more complicated: you could use some sort of counter or, if you need the models for something, save them and check in hideSpinner() if you have got them all.

           

          Hope this helps

           

          Erik

           

          Please mark the appropriate replies as correct or helpful so our team and other members know that your question has been answered to your satisfaction.

            • Re: Mashup - open connection
              Loris Lombardo

              Hi Erik,

               

              suppose, for simplicity, that i have an application showing only an object and a list for selecting values.

              i will show the spinner when the browser finish to load the page, then i will open the app and get the obj after, when the promise is resolved, the spinner will be hided according to your code.

               

              but then the user select a value on the list, no spinner is shown, i cant get the action (i guess) and increment a counter or what else.

              More over in a real scenario the user can filter data from different objs or by app.field(dim).toggleSelect(value) , i want a single point for checking the request for new calculation.

               

              so my question is: there is a way to get requests for new calculation to the server indipendently from the obj that throw it, in order to increment something (or show magicmaterialsuperspinner.gif )  ?


              Thanks.

                • Re: Mashup - open connection
                  Erik Wetterberg

                  Hi,

                  You would need to use the events for that. The Validated event occurs when there is valid data in the object, Invalidated occurs when a selection has been made.

                   

                  This would be something like this:

                  app.getObject( 'QV01', id ).then( function ( model ) { 
                    //initial display here
                    model.Invalidated.bind(function(){
                     //data is invalid:show spinner
                    });
                    model.Validated.bind(function(){
                     //data is valid:hide spinner
                    });
                  });
                  

                   

                  In many cases this will happen very quickly, and you might want some sort of delay before showing your spinner to avoid showing it for very short calculation times.

                   

                  Hope this helps

                  Erik

                   

                  Please mark the appropriate replies as correct or helpful so our team and other members know that your question has been answered to your satisfaction.