Foundset change doesn't reflect at Client Side

Forum to discuss the new web client version of Servoy.

Foundset change doesn't reflect at Client Side

Postby jay.rao » Tue May 09, 2017 8:14 am

Hello,

I have tried implementing several features like filtering and grouping in a grid component,I have implemented component-serverSide.js for filtering data at server side.I am attaching a screencast here https://www.screencast.com/t/r4hFFZBqwJ for you reference where you can see I am filtering a data and on the first call to server it returns the filtered data i.e 15 records in fs.viewPort.rows although I am using the same foundset at component clientside to resolve but it doesn't reflects the same but if I set time out for 500-1500 ms it reflects in my foundset. Also you can see in the video that after second call to server my foundset is now same the original filtered foundset.
Please take a look at screen cast for better clarity.
jay.rao
 
Posts: 59
Joined: Mon Apr 10, 2017 1:32 pm

Re: Foundset change doesn't reflect at Client Side

Postby Andrei Costescu » Tue May 09, 2017 8:45 am

Ok, from what I can tell:
  • once you filter, you get a full new value for the foundset property (so I think it gets replaced by reference)
  • in your code you are using a "fs" not directly the $scope.model.foundset (if that is the prop. name). I suspect that that "fs" is the one lagging behind. So after the first time it passes through foundset .js the $scope.model will already have the new value but your "fs" has the old one. I don't know how you update the "fs". One solution would be to always use model.foundset and don't cache it to "fs", another option is - in case you are using an angular watch to update "fs" (watches will be executed later in the digest cycle) you can try to switch to listening for changes in model properties using "modelChangeNotifier" as shown here (there you should get the foundset update right away I think)
  • I personally don't like setTimeout workarounds :) - generally that is trouble for later. When calling "callServerSideApi" you get a back a $q promise. You should be able to use that one instead of a timeout. So
    Code: Select all
    childFoundsetPromise = ...; // callServerSideApi
    childFoundsetPromise.then(function success() { /* do your thing */ }, function error() { /* do your thing */ })
    Those should be called exactly after your callServerSideApi did what it was supposed to do.
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: Foundset change doesn't reflect at Client Side

Postby jay.rao » Tue May 09, 2017 9:01 am

Hello Saviour Andrei,


Thank you for the instant reply.You are absolutely correct,"in your code you are using a "fs" not directly the $scope.model.foundset (if that is the prop. name). I suspect that that "fs" is the one lagging behind. So after the first time it passes through foundset .js the $scope.model will already have the new value but your "fs" has the old one. I don't know how you update the "fs". One solution would be to always use model.foundset and don't cache it to "fs", another option is - in case you are using an angular watch to update "fs" (watches will be executed later in the digest cycle) you can try to switch to listening for changes in model properties using "modelChangeNotifier" as shown here (there you should get the foundset update right away I think)" its silly of me to do such mistakes :oops: . I should rather use $scope.model.foundset everywhere I resolve instead of var fs and thats the reason it did not work,although I am not sure why did it resolve on timeout but I believe I would not need timeout anymore.
jay.rao
 
Posts: 59
Joined: Mon Apr 10, 2017 1:32 pm

Re: Foundset change doesn't reflect at Client Side

Postby Andrei Costescu » Tue May 09, 2017 9:10 am

:) Yw.

Yes try to get rid of the timeout as well and use the promise.then instead of it.
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: Foundset change doesn't reflect at Client Side

Postby jay.rao » Tue May 09, 2017 10:45 am

Hello Andrei,

Yes I am trying to get rid of setTimeout function but I want you to take a look at screencast again https://www.screencast.com/t/cLfmUtVc7JV0
As you can see in the video I have removed timeout but now in this case as my serversideapi return $q promise it should only go into the then function when my call is finished although you can see it already went into the then function and due to that I do no get latest foundset as my server side operation is yet pending(as server side operation ends it doesnt go into the .then function again).Also at serverside api i am not returning the foundset as foundset already updates itself in foundset.js file(although doing the same thing with setTimeout does the job but its not the feasible method).
jay.rao
 
Posts: 59
Joined: Mon Apr 10, 2017 1:32 pm

Re: Foundset change doesn't reflect at Client Side

Postby Andrei Costescu » Tue May 09, 2017 11:57 am

That is unexpected. I did try this with a quick example just now and it worked as expected for me.
So I created a server side method that does a $scope.model.foundset find - search that finds only one record (previously there were 200+) and the "then" from callServerSideApi executes on client when $scope.mode.foundset.serverSize is already 1.

What exactly do you do on server in that onFilterApi? You do change the foundset right away right?
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: Foundset change doesn't reflect at Client Side

Postby jay.rao » Tue May 09, 2017 12:31 pm

Hello,

Below is the code which executes on serverside

Code: Select all

$scope.onFilterApi=function(columnsName,operation,searchString){
   var columnsActualName =[]
   var parentFoundset = $scope.model.foundset.foundset;
        parentFoundset.find();
     //CREATE CONDITIONAL QUERY FOR FILTERING
     for(var i=0;i<columnsActualName.length;i++)
     {
      var columnDef = columnsActualName[i]
      if(operation[i]==='contains')
      {
       parentFoundset[columnDef]= "%" + searchString[i]+ "%"
      }
   
      else if(operation[i]==='<=')
      {      
         if(typeof searchString[i]==="string"){
            var date=dateConverter(searchString[i]);
            parentFoundset[columnDef]= "<="+date +"|MM/dd/yyyy";
         }
         else{
            parentFoundset[columnDef]= "<="+searchString[i].toString();
         }
      
      }
      else if(operation[i]==='<')
      {
         if(typeof searchString[i]==="string"){
            var date=dateConverter(searchString[i]);
            parentFoundset[columnDef]= "<"+date +"|MM/dd/yyyy";
         }
         else{
            parentFoundset[columnDef]= "<"+searchString[i].toString();
         }
      
      }
      else if(operation[i]==='>')
      {
         if(typeof searchString[i]==="string"){
            var date=dateConverter(searchString[i]);
            parentFoundset[columnDef]= ">"+date +"|MM/dd/yyyy";
         }
         else{
            parentFoundset[columnDef]= ">"+searchString[i].toString();
         }
      
      }
   
      else if(operation[i]==='between')
      {
         var data = searchString[i].split('...');
         if(typeof data[0]==="string"){
            var startDate=dateConverter(data[0]);
            var endDate=dateConverter(data[1]);
            parentFoundset[columnDef]=startDate + "..." + endDate +"|MM/dd/yyyy";
         }
          else
          {
            parentFoundset[columnDef]= searchString[i].toString();
          }
      
      }
     }
    
     parentFoundset.search();
}


This is the code which executes on filtering,I do not return anything here as it find-search would automatically change my foundset and that foundset is resolved at client side as shown in the video.Yes it is strange,I am not sure if I am missing something here again.
Code: Select all
childFoundsetPromise=$scope.handlers.svy_servoyApi.callServerSideApi("onFilterApi",[columnsName,operation,searchString]);
//                     childFoundsetPromise.then(function(){   
//                     });
                     setTimeout(function(){
                        var result = {
                              data:$scope.model.foundset.viewPort.rows,
                              totalCount: $scope.model.foundset.viewPort.rows.length
                            }
                     deferred.resolve(result);
                      }, 500);
                     }


I tried with then and setTimeout both.
jay.rao
 
Posts: 59
Joined: Mon Apr 10, 2017 1:32 pm

Re: Foundset change doesn't reflect at Client Side

Postby Andrei Costescu » Tue May 09, 2017 12:55 pm

I think I figured it out.

You are not on 8.1.3 right?
There was a fix for this in that build - and without that fix indeed it doesn't work as expected in my test either.

Can you try it with 8.1.3?
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: Foundset change doesn't reflect at Client Side

Postby jay.rao » Tue May 09, 2017 1:54 pm

Hello Andrei,


I updated to 8.1.3 as you said,I did not modify single piece of code but now grid doesn't get any data. I tried debugging foundset.js but it keeps on returning 0 records on grid initialisation.I am not sure why does this behave like this,do I have to change anything after update ?
jay.rao
 
Posts: 59
Joined: Mon Apr 10, 2017 1:32 pm

Re: Foundset change doesn't reflect at Client Side

Postby jay.rao » Tue May 09, 2017 2:03 pm

I have been switching server since starting (also when using 8.1.2) and due to that my query at servoy admin page was perfect but now after updating my initial query at servoy admin page has changed and thus due to that I beleive I am unable to fetch data(i guess its due to switch server)
jay.rao
 
Posts: 59
Joined: Mon Apr 10, 2017 1:32 pm

Re: Foundset change doesn't reflect at Client Side

Postby Andrei Costescu » Tue May 09, 2017 2:22 pm

Yes, I thought it has to be something like that. Others have reported the same and I know ppl. were looking into that. See 8.1.3 release thread.
If it wasn't for that it should have worked.

If you want/have to stay on 8.1.2 for the moment you can always update your data on client not based on promise or timeout, but generally (not only when you request a change) based on incomming changes in the foundset property type. You have to watch many of those anyway - I suspect just in case something changes on server for that foundset due to another form/component or another client that operates with the same data.
So for example:
Code: Select all
$scope.$watch("model.foundset", function (newValue, oldValue) { ... }); // will let you know when foundset property value changed by reference
$scope.$watch("model.foundset.serverSize", function (newValue, oldValue) { ... }); // will let you know when foundset property value's serverSize changed
$scope.$watch("model.foundset.viewPort", function (newValue, oldValue) { ... }); // will let you know when foundset property value's viewPort has completely changed
$scope.$watch("model.foundset.viewPort.rows", function (newValue, oldValue) { ... }); // will let you know when foundset property value viewPort's rows has completely changed
$scope.$watchCollection("model.foundset.viewPort.rows", function (newValue, oldValue) { ... }); // will let you know when foundset property value's rows have changed (any item in the rows array was changed by reference/added/removed or the rows itself changed by reference)
$scope.$watch("model.foundset.viewPort.rows", function (newValue, oldValue) { ... }, true); // will let you know when foundset property value's rows have changed in depth (so any change at any level after rows will be reported)
$scope.$watchCollection("model.foundset.model.foundset.selectedRowIndexes", function (newValue, oldValue) { ... }); // will let you know when foundset property value's selection has changed

All these watches can be replaced with a listener on the foundset property in 8.2 (wiki page describes that), as the more data you watch for the slower the page will get + the listener details nicely the changes that happened.
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: Foundset change doesn't reflect at Client Side

Postby jay.rao » Tue May 09, 2017 3:07 pm

Hello,Andrei
I will have to revert back to 8.1.2 but as I try to revert it throws error 'An error occurred while collecting items to be installed
session context was:(profile=Servoy, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=).
No repository found containing: org.eclipse.update.feature,com.servoy.eclipse.feature,8.1.2.3031'
I am worried if I may have to reinstall everything from the skretch.Is there any other way to revert back to old version.
jay.rao
 
Posts: 59
Joined: Mon Apr 10, 2017 1:32 pm

Re: Foundset change doesn't reflect at Client Side

Postby Andrei Costescu » Tue May 09, 2017 3:59 pm

I usually keep separate installs for each version. Don't know how other ppl. do it.

Did you say "yes" when after updating developer it asked to update app. server as well?
If yes, even if you downgrade developer, your app. server would not downgrade, so a full install of 8.1.2 would be better.

If you didn't update application server (chose "No" there) you can revert to old version by adding this update site to "Available update sites": http://download.servoy.com/developer/8xx_updates/3031
That one has the specific version you had before updating.
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: Foundset change doesn't reflect at Client Side

Postby Andrei Costescu » Wed May 10, 2017 9:35 am

Btw. What kind of database do you use? Just to be sure that it's checked as well when the 8.1.3 bug gets fixed.
Is it Progress/Microsoft SQLServer or something else?
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: Foundset change doesn't reflect at Client Side

Postby jay.rao » Wed May 10, 2017 11:03 am

Hello Andrei,


Actually we use MS SQL and also I have successfully rollback to original version,i updated application server too but just uninstalled Servoy and re-installed again did my job.
Thanks for the support
jay.rao
 
Posts: 59
Joined: Mon Apr 10, 2017 1:32 pm


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 13 guests