Page 1 of 1

Execute service not assigned to a specific page?

Posted: Thu Oct 24, 2013 7:03 pm
by Roger6240907

I want to track user interactions by using mixpanel. It provides JSON APIs that I can call successfully if I encode the request in base64. This requires a little bit of JS code I added as JS asset.
What I would like to do is to have a simple function log() that I can call whenever I wants.

At the moment I can do that within one page where I added a service call MX_track and I trigger it with MX_track.execute({});

Unfortunately I can not add the same service with the same name to another page, hence I cannot use the JS function log() over multiple pages.
In theory if a service only needs to access localStorage it should be possible to be triggered anywhere regardless if it is added to a page or not. I tried to create a template, but the service does not propagate to the child pages.
Is there any other way?


Execute service not assigned to a specific page?

Posted: Thu Oct 24, 2013 7:44 pm
by Kateryna Grynko

Hi Roger,

For each page, create its own datasource, based on a service. You can not use the same datasource on different pages, as each has certain mapping for a specific page.

In your example the datasource call is:preMX_track.execute({});/pre


Execute service not assigned to a specific page?

Posted: Fri Mar 07, 2014 11:37 pm
by Jamie5245261

Reference to similar topic: https://getsatisfaction.com/apperyio/...

Hi gang,

This isn't a question or a problem: just a suggestion.

I too have run into the same difficulty that Roger and Janko encountered.

In my case, I have a Javascript function that is available across my entire app (which is comprised of several pages). The function should (ideally) call a singular service, but I can't do that.

I make use of an identical Appery server code service on all pages and I'm using the xyz.execute(); service to call my server code. I find it inconvenient to have to edit mappings on every single page for what is essentially the same identical service.

It would be nice to be able to call on a page's service from another page (without having to do workaround like navigating back and forth to pages and so forth).

Of course, I'm suggesting this with full knowledge that perhaps something does, in fact, meet my needs.


Execute service not assigned to a specific page?

Posted: Thu Apr 10, 2014 10:50 am
by Maryna Brodina

Hello!

I'm sorry for taking too long to reply...
If you need to call service which is on one screen from different screens and at the same time have this service mapping working, it would work only if your pages are rendered in one html file (otherwise pages are replaced and there is nowhere to perform mapping)
1) Check Render all pages in one html file
2) Before service invocation ensure service is loaded. It is loaded after pre screenName_js();/pre is executed
where screenName - screen name which contains service.
For example use the following code:pre if( typeof(restserviceName) === 'undefined') {
screenName_js();
}
restserviceName.execute();/preIf you don't need mapping, but want to perform any actions on server response, there is no need to render all pages in one html file, you can define service manually in global scope. Here is more information https://getsatisfaction.com/apperyio/...


Execute service not assigned to a specific page?

Posted: Thu Apr 10, 2014 11:42 am
by Jamie5245261

Thanks Maryna!

Jamie


Execute service not assigned to a specific page?

Posted: Tue Apr 22, 2014 10:51 am
by Sam6522984

Hi

I solved this problem with defining the services on the startpage, then I just start the service with the execution-method. I think this approach will only work if you don't map the response to the page.

Maybe an official can explain possible problems with this approach.

Sam


Execute service not assigned to a specific page?

Posted: Tue Apr 22, 2014 11:58 pm
by Igor

Hi,

Here is two things in appery:

1 service

2 datasource - derivative of service.

Service - global to all pages.

Datasource available after page has been initialized.

In case when all pages generates in the one page - your all datasource are available from all pages.

In case when you use separate pages your datasources available only within the initialized pages.

But if you want to use separate pages and use services, you cancreate datasource dynamically.

See following code to understand how do it:

pre
//Create dataSource.
//note "ToDoDB_users_list_service" - is service and should be replaced by yours one.
var yourDataSource = new Apperyio.DataSource(ToDoDB_users_list_service, {
'onBeforeSend': function(jqXHR) {

Code: Select all

 }, 

 //onComplete eventHandler 
 'onComplete': function(jqXHR, textStatus) { 
     console.log("complete"); 
 }, 

 //onSuccess eventHandler 
 'onSuccess': function(data) { 
     console.log("success"); 
 }, 

 //Error eventHandler 
 'onError': function(jqXHR, textStatus, errorThrown) {}, 

 'responseMapping': [], 

 'requestMapping': [{ 
     'PATH': ['X-Appery-Database-Id'], 
     'TYPE': 'STRING', 
     'HEADER': true, 
     'ATTR': '{database_id}' 
 }] 

});

yourDataSource.execute();
/pre


Execute service not assigned to a specific page?

Posted: Wed Apr 23, 2014 7:51 am
by Sam6522984

Thank you for the clarification.

So as long as I don't map a service to HTML-components, I can use them on every page? Also the service should be defined in the startpage.

This is currently my approach for services, which I need on multiple pages. I'm a bit concerned that this could stop working.


Execute service not assigned to a specific page?

Posted: Wed Apr 23, 2014 11:35 pm
by Illya Stepanov

Hi Sam,

Yes, you can call datasources in all pages, if it defined in already inited page (for example start page or if you have this option: http://prntscr.com/3ctop9/direct ).

Also you can create datasource dynamically with code described in Igors message.

Don't worry, if you have this option http://prntscr.com/3ctop9/direct your services could not stop to work.

Also, if you can migrate between these two ways, if it would need.

Regards.


Execute service not assigned to a specific page?

Posted: Thu Apr 24, 2014 12:28 pm
by Sam6522984

Thank you for the quick response and the clarification.