leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

Appery Platform Bug! When calling services.

No, not seen that. My app is Angular and not Ionic or jQuery Mobile.
I just tested var $q = Apperyio.get("$q"); in one of those other app types and it gives the error you're seeing.
So either queues aren't available or there is a different syntax?

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

Appery Platform Bug! When calling services.

OK, for jQuery apps (ie not Angular) you need to work with promises as per the jqueyr documentation her:
https://api.jquery.com/promise/

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

Appery Platform Bug! When calling services.

See here for jQuery promises:
https://api.jquery.com/promise/
If I get time I'll try and make it work because no doubt I'll need it in the future!

Good examples here http://joseoncode.com/2011/09/26/a-wa...

Joe7349603
Posts: 0
Joined: Tue Jan 27, 2015 11:08 pm

Appery Platform Bug! When calling services.

Steve, thanks for the links. Yes my app is Jquery and it is possible the syntax are different. I will poke around more to see if I can make it work.

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

Appery Platform Bug! When calling services.

jQuery version below. Maybe Appery or some else can do a better version with a parameter for the upload function and the return value but I'm sure you can make this work and extend it in some way.

You could also try using the "Q" library, see here:https://github.com/kriskowal/q

code
debugger;
console.clear();
console.log("image takes 5 secs and raw takes 1 sec");
doUpload1();
return;

function doUpload1(){
console.log("Uploading image then raw");
var d = $.Deferred();
p=d.promise();
p.then(uploadImg1).then(uploadRaw1).then(function(){
console.log("All done");
});
d.resolve();
}

function uploadImg1(){
var deferred = $.Deferred();
setTimeout(function(){
console.log("uploadImg1 done");
deferred.resolve("img retval");
},5000);
console.log("Uploading uploadImg1");
return deferred.promise();
};
function uploadRaw1(){
var deferred = $.Deferred();
setTimeout(function(){
console.log("uploadRaw1 done");
deferred.resolve("raw retval");
},1000);
console.log("Uploading uploadRaw1");
return deferred.promise();
}

/code

Joe7349603
Posts: 0
Joined: Tue Jan 27, 2015 11:08 pm

Appery Platform Bug! When calling services.

Thanks Steve, I have been tinkering with this on my end. The code below does upload images but not in sequence :( I am just putting it here maybe you can notice something I am doing wrong.

I will work with your code and see what results I get.

code
//This is the function inside the button submit.

function uploadImage_Data() {
var deferred = $.Deferred();

//First upload all images by calling the image upload functions
$.when(UploadImage1(),UploadImage2(),UploadImage3()).promise().done
console.log("uploading images Done. Upload Data");

//when done uploading images, upload raw data.
APIExpress_submit_Report.execute();
}

//I have a total of 5 functions, for now I am just showing 2 but they all look similar

function UploadImage1() {
var deferred = $.Deferred();
console.log("uploading image #1");
uploadBinaryHelper(image01_UploadService, Apperyio.storage.Image1_base64.get()); //this is service upload for image 1
deferred.resolve();
return deferred.promise;

}

function UploadImage2() {
var deferred = $.Deferred();
console.log("uploading image #2");
uploadBinaryHelper(image02_UploadService, Apperyio.storage.Image2_base64.get()); //this is service upload for image 2
deferred.resolve();
//return deferred.promise;
return deferredObject.promise;
}

/code

Joe7349603
Posts: 0
Joined: Tue Jan 27, 2015 11:08 pm

Appery Platform Bug! When calling services.

So I have tried to implement your version and results are the same- no sequencing.

The only change I made to the function is call the service as shown below:
Just above console.log(12q

code
function uploadImg1(){
var deferred = $.Deferred();
setTimeout(function(){
uploadBinaryHelper(image01_UploadService, Apperyio.storage.Image1_base64.get());
console.log("uploadImg1 done");
deferred.resolve("img retval");
},1000);
console.log("Uploading uploadImg1");
return deferred.promise();
}

function uploadRaw1(){
var deferred = $.Deferred();
setTimeout(function(){
APIExpress_submit_Report.execute();
console.log("uploadRaw1 done");
deferred.resolve("raw retval");
},1000);
console.log("Uploading uploadRaw1");
return deferred.promise();
}

/code

leven.steve
Posts: 0
Joined: Sun Mar 04, 2012 4:01 pm

Appery Platform Bug! When calling services.

I'm not expert enough to understand all of the inner workings on this but I had similar non-sequencing issues when I played around with it.

In particular if I used ".when" it didnt work as expected. There's possibly better ways to do this (Appery?)

The important things are this:

  1. the starting point needs to be a promise (as far as I know) so it starts by assigning "p"

  2. Use p to string the sequence together like this:
    p.then(uploadImg1).then(uploadRaw1).then(function(){
    // whatever you want to do after the img and then the raw is uploaded
    }

    If you're uploading all 5 images in one hit then I would do #2 in the "// whatever you want..." bit and so on for 3,4 and 5

    This might help give more info:
    http://blog.mediumequalsmessage.com/p...

Return to “Issues”