AngularJS $http.post() Data

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

AngularJS $http.post() Data

Justin Dennis-3
Hi All -

I'm trying to get on the AngularJS bandwagon, and I'm facing an issue with
the default post data format being JSON. I love the idea of getting JSON
posted to Lasso, but how do I get to it?

I'm struggling to find the right Lasso web_request method to get to the
post data and json_deserialize() it.

Thanks for any pointers you can offer.

- Justin

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: AngularJS $http.post() Data

Jolle Carlestam-2
It's in fact very easy. Give me about 20 minutes to get back to my desk and I'll post it.

HDB
Jolle

Sent from a thin, flat, touchy device from an undetermined place in space.

> 23 nov 2015 kl. 21:57 skrev Justin Dennis <[hidden email]>:
>
> Hi All -
>
> I'm trying to get on the AngularJS bandwagon, and I'm facing an issue with
> the default post data format being JSON. I love the idea of getting JSON
> posted to Lasso, but how do I get to it?
>
> I'm struggling to find the right Lasso web_request method to get to the
> post data and json_deserialize() it.
>
> Thanks for any pointers you can offer.
>
> - Justin
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>  the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: AngularJS $http.post() Data

decorior
In reply to this post by Justin Dennis-3
Since Jolle has been doing this longer, I will let him post, and then chime in on some of the things we do. You will love the way it works!

Deco

> On Nov 23, 2015, at 1:57 PM, Justin Dennis <[hidden email]> wrote:
>
> Hi All -
>
> I'm trying to get on the AngularJS bandwagon, and I'm facing an issue with
> the default post data format being JSON. I love the idea of getting JSON
> posted to Lasso, but how do I get to it?
>
> I'm struggling to find the right Lasso web_request method to get to the
> post data and json_deserialize() it.
>
> Thanks for any pointers you can offer.
>
> - Justin
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>  the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: AngularJS $http.post() Data

Jolle Carlestam-2
In reply to this post by Justin Dennis-3
23 nov 2015 kl. 21:57 skrev Justin Dennis <[hidden email]>:
>
> Thanks for any pointers you can offer.

Back. So. In the javascript a typical save action can look like this.

factory('ServerComs', ['$resource', function($resource){
        return $resource({
// stuff
                save: {method:'POST', url: '/prapi/venue/?-action=save'},
// stuff

        });
}]) // ServerComs


Called from the controller like this:

section.update = function (venuedata) {

        var promois = ServerComs.savesection(venuedata, function(result) {
                if(result.success) {
                        if(result.message) {
                                displayTempMsg(result.message, 3000);
                        }
                } else {
                        alert('Ooops ' + result.message)
                }
        });
}


In the Lasso file I extract the params like so:

local(
        posted = json_decode(web_request -> poststring) or map,
        id = #posted -> find('id') -> asstring,
        lockvalue = #posted -> find('lock') -> asstring,

// and so forth for all params that I want as locals

)

// stuff

// params that is only to be sent directly to the DB call I don't bother creating locals for

#row -> update(map(

        'chairs_available' = integer(#posted -> find('chairsavailable')) or null,
        'incoming_electricity' = #posted -> find('incomingelectricity') or null,
        'venue_room_depth' = decimal(#posted -> find('venueroomdepth')) or null,
        'venue_room_width' = decimal(#posted -> find('venueroomwidth')) or null,

// stuff

))

// #row is a DS object.



The key is this
json_decode(web_request -> poststring)

web_request -> poststring will be the JSON sent from Angular. When you json_decode it will turn into a map.

Piece of cake as promised.

HDB
Jolle

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: AngularJS $http.post() Data

decorior
Hi, Justin:

We take a slightly simpler approach.

This is what we do (simplified to start with)

In your controller function we usually do the following
       
        // create a new object
        var self = this
        var myObj = {}

        // populate the object with some of the value from the controller $scope (i.e. self)

        myObj.id = self.id
        myObj.first_name = self.first_name
        // submit these to a lasso file
            $http.post('get_court.lasso', myObj).success(
                function(data, status, headers) {
                    self.results = data.results
                ...
                })

in lasso we do;

local(parammap) = json_desrialize(web_request->poststring)
…. lots of lasso stuff
…. put the results I want back into a result map

json_header
json_serialize(`results` = #resultmap)


Here are a few things we do:

1. We like to show that the server is busy using http://ngmodules.org/modules/angular-busy <http://ngmodules.org/modules/angular-busy>
This basically display a spiinign daisy while the ajax cal is going on. very simple
2. We typically pass into the $http.post the function data if it is a repeating row
3. We almost never pass html in the results





> On Nov 23, 2015, at 2:35 PM, Jolle Carlestam <[hidden email]> wrote:
>
> 23 nov 2015 kl. 21:57 skrev Justin Dennis <[hidden email]>:
>>
>> Thanks for any pointers you can offer.
>
> Back. So. In the javascript a typical save action can look like this.
>
> factory('ServerComs', ['$resource', function($resource){
> return $resource({
> // stuff
> save: {method:'POST', url: '/prapi/venue/?-action=save'},
> // stuff
>
> });
> }]) // ServerComs
>
>
> Called from the controller like this:
>
> section.update = function (venuedata) {
>
> var promois = ServerComs.savesection(venuedata, function(result) {
> if(result.success) {
> if(result.message) {
> displayTempMsg(result.message, 3000);
> }
> } else {
> alert('Ooops ' + result.message)
> }
> });
> }
>
>
> In the Lasso file I extract the params like so:
>
> local(
> posted = json_decode(web_request -> poststring) or map,
> id = #posted -> find('id') -> asstring,
> lockvalue = #posted -> find('lock') -> asstring,
>
> // and so forth for all params that I want as locals
>
> )
>
> // stuff
>
> // params that is only to be sent directly to the DB call I don't bother creating locals for
>
> #row -> update(map(
>
> 'chairs_available' = integer(#posted -> find('chairsavailable')) or null,
> 'incoming_electricity' = #posted -> find('incomingelectricity') or null,
> 'venue_room_depth' = decimal(#posted -> find('venueroomdepth')) or null,
> 'venue_room_width' = decimal(#posted -> find('venueroomwidth')) or null,
>
> // stuff
>
> ))
>
> // #row is a DS object.
>
>
>
> The key is this
> json_decode(web_request -> poststring)
>
> web_request -> poststring will be the JSON sent from Angular. When you json_decode it will turn into a map.
>
> Piece of cake as promised.
>
> HDB
> Jolle
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>  the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: AngularJS $http.post() Data

Justin Dennis-3
Both responses are right on point and a tremendous help. As always, thank
you for taking the time!

- Justin

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: AngularJS $http.post() Data

decorior
One thing to consider as you go forward is that there is a probability that the session has ended when lasso is called.

So the lasso file should contain a response for this.

In the $http.post response we typically include something like this:

if(data.login_status == false)$state.go('index.lockscreen',{user_id:memberService.user_id});

This will basically send the user to a logged out screen.

Deco

> On Nov 23, 2015, at 3:03 PM, Justin Dennis <[hidden email]> wrote:
>
> Both responses are right on point and a tremendous help. As always, thank
> you for taking the time!
>
> - Justin
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>  the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: AngularJS $http.post() Data

decorior
In reply to this post by Justin Dennis-3
HI, Justin:

This is what we do (simplified to start with)

In your controller function we usually do the following
       


        // create a new object
        var myObj = {}

        // populate the object with some of the value form the controller $scope
        myObj.id = self.id
        myObj.first_name = self.first_name

        // submit these to a lasso file
            $http.post('get_court.lasso', myObj).success(
                function(data, status, headers) {
                    self.results = data.results

                })



> On Nov 23, 2015, at 1:57 PM, Justin Dennis <[hidden email]> wrote:
>
> Hi All -
>
> I'm trying to get on the AngularJS bandwagon, and I'm facing an issue with
> the default post data format being JSON. I love the idea of getting JSON
> posted to Lasso, but how do I get to it?
>
> I'm struggling to find the right Lasso web_request method to get to the
> post data and json_deserialize() it.
>
> Thanks for any pointers you can offer.
>
> - Justin
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>  the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: AngularJS $http.post() Data

decorior
In reply to this post by Justin Dennis-3
Dear Justin:

I also found a number of seemingly frustrating things to figure out with angular. E.g. why it wants to insert blank option in a dropdown, when we started.

Do not hesitate to post. I prefixed my posts on here with [ANG] to make it easier.

Now they alll seem obvious, but I learn new things each day.

We are using a large number of modules/directives to make things easier (go to ngmodules.org <http://ngmodules.org/>). I think Jolle and I posted some of our favorites.

Th amazing thing is how much is available for reuse (buyer beware of course)

Deco




> On Nov 23, 2015, at 3:03 PM, Justin Dennis <[hidden email]> wrote:
>
> Both responses are right on point and a tremendous help. As always, thank
> you for taking the time!
>
> - Justin
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>  the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: AngularJS $http.post() Data

Justin Dennis-3
This is going very well.

With AngularJS, web_request->requestMethod, web_request->postString,
json_deserialize, and of course DS-based custom types, we have some heavy
stuff working with less than 20 lines of Lasso code.

I'm a fan!

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: AngularJS $http.post() Data

decorior
We use Jolles session stuff as well.

The 9.3 upgrade is supposed to improve the JSON tags as well, so even better performance.

The only negative is Angular 2 is around the corner.

Are using Bootstrap as well?

Deco

> On Nov 24, 2015, at 7:52 AM, Justin Dennis <[hidden email]> wrote:
>
> This is going very well.
>
> With AngularJS, web_request->requestMethod, web_request->postString,
> json_deserialize, and of course DS-based custom types, we have some heavy
> stuff working with less than 20 lines of Lasso code.
>
> I'm a fan!
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>  the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>