Page 3 of 3

Appery Platform Bug! When calling services.

Posted: Fri Dec 02, 2016 3:20 pm
by leven.steve

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?


Appery Platform Bug! When calling services.

Posted: Fri Dec 02, 2016 3:23 pm
by leven.steve

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


Appery Platform Bug! When calling services.

Posted: Fri Dec 02, 2016 3:24 pm
by leven.steve

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...


Appery Platform Bug! When calling services.

Posted: Fri Dec 02, 2016 5:48 pm
by Joe7349603

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.


Appery Platform Bug! When calling services.

Posted: Sat Dec 03, 2016 6:35 pm
by leven.steve

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


Appery Platform Bug! When calling services.

Posted: Sat Dec 03, 2016 7:31 pm
by Joe7349603

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


Appery Platform Bug! When calling services.

Posted: Sun Dec 04, 2016 5:16 am
by Joe7349603

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


Appery Platform Bug! When calling services.

Posted: Sun Dec 04, 2016 10:20 am
by leven.steve

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...