Page 1 of 2

Limit entires to a Grid

Posted: Sun Mar 23, 2014 4:45 pm
by Milton Davis

I am using a REST service to get data from Google Places. It returns 20 entries in a JSON file. Is there anyone to map the response to a Grid object, so that only the first 3 entries show up? I have it working so all 20 show, but want to limit the number of results.

Image


Limit entires to a Grid

Posted: Sun Mar 23, 2014 5:10 pm
by Alena Prykhodko

Limit entires to a Grid

Posted: Mon Mar 24, 2014 12:16 am
by Milton Davis

My JSON file is coming fron Google api so there is no linit parameter. It returns a file with 20 records every time. Is there a way to limit these to only the first 5 entries displaying in a grid?


Limit entires to a Grid

Posted: Mon Mar 24, 2014 6:15 am
by Igor

You should change service incoming answer.

For this goals you should use service wrapper "Generic Security context".

Algorithm is:

1 service receive the response.

2 Generic security context get this response and change it(in your case you should to delete unnecessary items)

3 Return modified object.

Please read this document about it: http://docs.appery.io/documentation/g...


Limit entires to a Grid

Posted: Tue Mar 25, 2014 2:17 am
by Milton Davis

Igor,

I think I need to use Generic Security Context, but I am not understanding how to set it up from the document you provided. Can you help me with the JavaScript?

From the document, I don't understand what calls my GooglePlaces service or my GenericSecurityContext service.

My Service is called GooglePlaces, and it returns a JSON like this:
{

Code: Select all

"html_attributions" : [ 

 ], 

"results" : [ 

   { 

      "geometry" : { 

         "location" : { 

            "lat" : 33.885201, 

            "lng" : -118.410797 

             } 

         }, 

   { 

      "geometry" : { 

         "location" : { 

            "lat" : 33.885158, 

            "lng" : -118.410012 

}

}


Limit entires to a Grid

Posted: Tue Mar 25, 2014 5:05 am
by Illya Stepanov

Hi Milton,

Please do the following steps:

  1. Create "Generic security context" and call it "MySecurityGeneric".

  2. Open editor for JS implementation for this security context http://prntscr.com/33wngf/direct

  3. Insert following JS code:
    pre
    Appery.MySecurityGeneric = Appery.createClass(SecurityContext, {

    invoke: function(service, settings) {
    var oldSuccess = settings.success;

    Code: Select all

     var onSuccess = function(value, other){ 
    
         console.log("Original object"); 
         console.log(value); 
    
         //here you should to change your object here. For example "value.length = 1;" 
    
         console.log("Changed object"); 
         console.log(value); 
    
         oldSuccess.call(this, value, other); 
     }; 
    
     settings.success = onSuccess; 
     Appery.MySecurityGeneric.$super.invoke.call(this, service, settings); 

}

});
/pre

  1. Navigate to your service. And set this security context (MySecurityGeneric). http://prntscr.com/33wog4/direct

  2. Test it. By Default you should have the same result as before it. But in console log you should get two object (before changes and after).

    So you should implement your object changing logic (object after changes should be the same as object before changes, but with count of items you need).

    That's all.


Limit entires to a Grid

Posted: Tue Mar 25, 2014 5:44 am
by Milton Davis

Illya, thanks for the help, but I still can not get it to work...

I was able to follow what you suggested, but when I test the service, I get no change even after changing the logic. I don't see the JSON in the console either. It doesn't seem like my service is running the security context. Any thoughts?
Image Image Image


Limit entires to a Grid

Posted: Tue Mar 25, 2014 6:11 am
by Illya Stepanov

Milton.

You have missed this item:
[quote:]

  1. Create "Generic security context" and call it "MySecurityGeneric".
    [/quote]

    See screen shot: http://prntscr.com/33wzvs/direct

    Fix it and try again.


Limit entires to a Grid

Posted: Tue Mar 25, 2014 3:17 pm
by Milton Davis

Illya, I made that change and also changed the service to call out "MySecurityGeneric" context now, but it still does not work. It is not running the Security Context code for some reason.

Any idea why?


Limit entires to a Grid

Posted: Tue Mar 25, 2014 10:13 pm
by Alena Prykhodko

Hi Milton,

Hard to say what is wrong. Please share your application with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a and tell us its name.