immediate display alert to user while Ajax request

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

immediate display alert to user while Ajax request

Sabine Manaa
Hi,

while generating reports, I want to show the user some kind of information about the status of the report generation. After each step, I want to alert him about the status. Alert is only an example for reducing the problem here.  will use the mdlSnackbar for it.

When he clicks on "create reports", an alert should show before the first step and then after each next step. In my reduced example below, the alerts are all shown at the end, AFTER the script.

How can I do this, I don't get it and could need some help...
Sabine

reducedExample>>html mdlButton
onClick: (html jQuery ajax
script: [ :script | 
self session reportModel: RKAReportHead new.
script alert: 'Reisekosten' inspect.
RKAPDFWriter new createCostReports: self session.
script alert: 'Belege' inspect.
RKAPDFWriter new createReceiptReports:  self session.
script alert: 'Fahrten' inspect.
RKAPDFWriter new createVehicleReports:  self session.
script alert: 'Buchungen' inspect.
RKAPDFWriter new createBookingReports:  self session ]);
with: 'test'

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: immediate display alert to user while Ajax request

jtuchel
Sabine,

fur such things, I set up an instance  variable in the component with the text to display, for off a process that does the actual processing and updates the variable with the text reperesenting the progress.

On the client side, I setup a timeout that will issue an ajax callback back to the server every x smsecs and. The server will answer the current string. The Javascript code can then update the "please wait" dialog, or, in your case, open an alert if the text has changed from last time.

I am not near an image right now, so I cannot provide sample code...

Joachim



Am 21.07.17 um 15:39 schrieb Sabine Manaa:
Hi,

while generating reports, I want to show the user some kind of information about the status of the report generation. After each step, I want to alert him about the status. Alert is only an example for reducing the problem here.  will use the mdlSnackbar for it.

When he clicks on "create reports", an alert should show before the first step and then after each next step. In my reduced example below, the alerts are all shown at the end, AFTER the script.

How can I do this, I don't get it and could need some help...
Sabine

reducedExample>>html mdlButton
onClick: (html jQuery ajax
script: [ :script | 
self session reportModel: RKAReportHead new.
script alert: 'Reisekosten' inspect.
RKAPDFWriter new createCostReports: self session.
script alert: 'Belege' inspect.
RKAPDFWriter new createReceiptReports:  self session.
script alert: 'Fahrten' inspect.
RKAPDFWriter new createVehicleReports:  self session.
script alert: 'Buchungen' inspect.
RKAPDFWriter new createBookingReports:  self session ]);
with: 'test'


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: immediate display alert to user while Ajax request

Sabine Manaa
Hi Joachim, all,

thanks a lot! I think I am very near to the solution but there is one problem remaining: within the Ajax block, the JQLoad   seems to be "blocked". I explain:

* I have an attribute @directUserMessage: in my session initialized with an empty string.

*In my main view I have >>renderLoadIntervalMessageOn: html
html paragraph
id: 'spf-direct-message';
script:
(html jQuery this load
onComplete:
(' javascript which shows the snackbar if spa-direct-message is set'));
html: [ :r | self renderMessageOn: r ];
interval: 1 seconds);
with: [ self renderMessageOn: html ]

 >>renderMessageOn: html
self session directUserMessage isEmpty
ifFalse: [ html render: self session directUserMessage ]


I have my button invoking the report generation: 

onClick:
(html jQuery ajax
script: [ :script | 
self session generateReportFiles: script.
 ...]);
with: 'PDF'.

in >>generateReportFiles:
"i set the directUserMessages:"
self session directUserMessage: 'Erstelle Reisekostenabrechnungen, bitte warten...'.
RKAPDFWriter new createCostReports: self.
self session directUserMessage: 'Erstelle Belege, bitte warten...'.
RKAPDFWriter new createReceiptReports: self.
self session directUserMessage: 'Erstelle Fahrten, bitte warten...'.
RKAPDFWriter new createVehicleReports: self.
self session directUserMessage: 'Erstelle Buchungen, bitte warten...'.
RKAPDFWriter new createBookingReports: self.
self session directUserMessage: ''

I tried I with a test button:
html mdlButton
onClick:
 (html jQuery ajax script: [ :script | self session directUserMessage: 'test' ]);
with: 'set message'

this works perfect - after clicking on the test button, the snackbar is showing every second again.
So, I can say that the principle was clear and I have a possibility to show individual messages by setting the string in the session.

BUT: while I am in the Ajax block, it does not work.
I put a console.log() into the javascript code and AFTER finishing the Ajax, all the messages are put there.
It seems to wait till the Ajax call is finished.

I have put an output  into the transcript: 

renderMessageOn: html
Transcript crShow: Time now printString , '-' , self session directUserMessage.

and there I see, that while I am in the Ajax block, there is no output.
While I am not in the Ajax block, it renders the time into it each second.

What is wrong here, can anyone explain?
Joachim, do you also set the instance variable with the text from an Ajax block? 

Regards
Sabine



Reply | Threaded
Open this post in threaded view
|

Re: immediate display alert to user while Ajax request

Paul DeBruicker
Hi Sabine,

You might want fork the report processing using a ThreadPool e.g. http://onsmalltalk.com/2010-07-28-a-simple-thread-pool-for-smalltalk  Code is here: http://smalltalkhub.com/#!/~pdebruic/ThreadPool

And then in your 'update the message to the customer polling' code also poll for the reports to be complete and have that code update the page once they are.

The ThreadPool, when running, does use some CPU, maybe more than it should, and I haven't looked into why yet.

Hope this helps.  

Paul




Sabine Manaa wrote
Hi Joachim, all,

thanks a lot! I think I am very near to the solution but there is one
problem remaining: within the Ajax block, the JQLoad   seems to be
"blocked". I explain:

* I have an attribute @directUserMessage: in my session initialized with an
empty string.

*In my main view I have >>renderLoadIntervalMessageOn: html
html paragraph
id: 'spf-direct-message';
script:
(html jQuery this load
onComplete:
(' javascript which shows the snackbar if spa-direct-message is set'));
html: [ :r | self renderMessageOn: r ];
interval: 1 seconds);
with: [ self renderMessageOn: html ]

 >>renderMessageOn: html
self session directUserMessage isEmpty
ifFalse: [ html render: self session directUserMessage ]


I have my button invoking the report generation:

onClick:
(html jQuery ajax
script: [ :script |
self session generateReportFiles: script.
 ...]);
with: 'PDF'.

in >>generateReportFiles:
"i set the directUserMessages:"
self session directUserMessage: 'Erstelle Reisekostenabrechnungen, bitte
warten...'.
RKAPDFWriter new createCostReports: self.
self session directUserMessage: 'Erstelle Belege, bitte warten...'.
RKAPDFWriter new createReceiptReports: self.
self session directUserMessage: 'Erstelle Fahrten, bitte warten...'.
RKAPDFWriter new createVehicleReports: self.
self session directUserMessage: 'Erstelle Buchungen, bitte warten...'.
RKAPDFWriter new createBookingReports: self.
self session directUserMessage: ''

I tried I with a test button:
html mdlButton
onClick:
 (html jQuery ajax script: [ :script | self session directUserMessage:
'test' ]);
with: 'set message'

this works perfect - after clicking on the test button, the snackbar is
showing every second again.
So, I can say that the principle was clear and I have a possibility to show
individual messages by setting the string in the session.

BUT: while I am in the Ajax block, it does not work.
I put a console.log() into the javascript code and AFTER finishing the
Ajax, all the messages are put there.
It seems to wait till the Ajax call is finished.

I have put an output  into the transcript:

renderMessageOn: html
Transcript crShow: Time now printString , '-' , self session
directUserMessage.

and there I see, that while I am in the Ajax block, there is no output.
While I am not in the Ajax block, it renders the time into it each second.

What is wrong here, can anyone explain?
Joachim, do you also set the instance variable with the text from an Ajax
block?

Regards
Sabine
Reply | Threaded
Open this post in threaded view
|

Re: immediate display alert to user while Ajax request

Ramon Leon-5
On 07/21/2017 08:50 AM, Paul DeBruicker wrote:
> The ThreadPool, when running, does use some CPU, maybe more than it should,
> and I haven't looked into why yet.

That's the pool manager checking if it needs to scale the pool size up
or down.  That could certainly be easily reduced by only doing this when
the work queue has jobs, you can see that in the startUp method line...

PoolManager := [ [ self adjustPoolSize ] repeat ] newProcess.

It does this even when the queue is empty, so that's a good idea you
have there to reduce the CPU usage.  I don't maintain the public version
of my code there, but I'll certainly be enhancing my own to check this.

--
Ramon Leon

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: immediate display alert to user while Ajax request

jtuchel
In reply to this post by Sabine Manaa
Sabine,

I think you need to fork  a new (background) process in order to have it run independently of the Ajax callbacks. The Ajax callbacks will be executed one after the other, there will never be any progress reporting.

So I THINK what you absolutely have to do is to start the long running Ajax callback as another process.

So start by putting your sequence of process steps in a

[
 ] fork.

block and see if it improves things.


I am using an inst var of the component instead of the session, but I guess that doesn't really matter. Using the session is probably a much better idea because you could then use this facility for a general solution that works for all ajax callbacks that run longer...


HTH

Joachim



Am 21.07.17 um 17:31 schrieb Sabine Manaa:
Hi Joachim, all,

thanks a lot! I think I am very near to the solution but there is one problem remaining: within the Ajax block, the JQLoad   seems to be "blocked". I explain:

* I have an attribute @directUserMessage: in my session initialized with an empty string.

*In my main view I have >>renderLoadIntervalMessageOn: html
html paragraph
id: 'spf-direct-message';
script:
(html jQuery this load
onComplete:
(' javascript which shows the snackbar if spa-direct-message is set'));
html: [ :r | self renderMessageOn: r ];
interval: 1 seconds);
with: [ self renderMessageOn: html ]

 >>renderMessageOn: html
self session directUserMessage isEmpty
ifFalse: [ html render: self session directUserMessage ]


I have my button invoking the report generation: 

onClick:
(html jQuery ajax
script: [ :script | 
self session generateReportFiles: script.
 ...]);
with: 'PDF'.

in >>generateReportFiles:
"i set the directUserMessages:"
self session directUserMessage: 'Erstelle Reisekostenabrechnungen, bitte warten...'.
RKAPDFWriter new createCostReports: self.
self session directUserMessage: 'Erstelle Belege, bitte warten...'.
RKAPDFWriter new createReceiptReports: self.
self session directUserMessage: 'Erstelle Fahrten, bitte warten...'.
RKAPDFWriter new createVehicleReports: self.
self session directUserMessage: 'Erstelle Buchungen, bitte warten...'.
RKAPDFWriter new createBookingReports: self.
self session directUserMessage: ''

I tried I with a test button:
html mdlButton
onClick:
 (html jQuery ajax script: [ :script | self session directUserMessage: 'test' ]);
with: 'set message'

this works perfect - after clicking on the test button, the snackbar is showing every second again.
So, I can say that the principle was clear and I have a possibility to show individual messages by setting the string in the session.

BUT: while I am in the Ajax block, it does not work.
I put a console.log() into the javascript code and AFTER finishing the Ajax, all the messages are put there.
It seems to wait till the Ajax call is finished.

I have put an output  into the transcript: 

renderMessageOn: html
Transcript crShow: Time now printString , '-' , self session directUserMessage.

and there I see, that while I am in the Ajax block, there is no output.
While I am not in the Ajax block, it renders the time into it each second.

What is wrong here, can anyone explain?
Joachim, do you also set the instance variable with the text from an Ajax block? 

Regards
Sabine





View this message in context: Re: immediate display alert to user while Ajax request
Sent from the Seaside General mailing list archive at Nabble.com.


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: immediate display alert to user while Ajax request

Sabine Manaa
Hi Joachim,

you are right. This was the point.

I had another problem with getting the session in the forked process. I asked in Discord and Max Leske helped.
To geht the session, I have to do the following in the Ajax request:

| requestContext |
 requestContext := WACurrentRequestContext value. 
[ WACurrentRequestContext use: requestContext during: [ self session dosomething ] ] fork.

Thank you for your help!
Sabine

2017-07-23 10:55 GMT+02:00 jtuchel [via Smalltalk] <[hidden email]>:
Sabine,

I think you need to fork  a new (background) process in order to have it run independently of the Ajax callbacks. The Ajax callbacks will be executed one after the other, there will never be any progress reporting.

So I THINK what you absolutely have to do is to start the long running Ajax callback as another process.

So start by putting your sequence of process steps in a

[
 ] fork.

block and see if it improves things.


I am using an inst var of the component instead of the session, but I guess that doesn't really matter. Using the session is probably a much better idea because you could then use this facility for a general solution that works for all ajax callbacks that run longer...


HTH

Joachim



Am 21.07.17 um 17:31 schrieb Sabine Manaa:
Hi Joachim, all,

thanks a lot! I think I am very near to the solution but there is one problem remaining: within the Ajax block, the JQLoad   seems to be "blocked". I explain:

* I have an attribute @directUserMessage: in my session initialized with an empty string.

*In my main view I have >>renderLoadIntervalMessageOn: html
html paragraph
id: 'spf-direct-message';
script:
(html jQuery this load
onComplete:
(' javascript which shows the snackbar if spa-direct-message is set'));
html: [ :r | self renderMessageOn: r ];
interval: 1 seconds);
with: [ self renderMessageOn: html ]

 >>renderMessageOn: html
self session directUserMessage isEmpty
ifFalse: [ html render: self session directUserMessage ]


I have my button invoking the report generation: 

onClick:
(html jQuery ajax
script: [ :script | 
self session generateReportFiles: script.
 ...]);
with: 'PDF'.

in >>generateReportFiles:
"i set the directUserMessages:"
self session directUserMessage: 'Erstelle Reisekostenabrechnungen, bitte warten...'.
RKAPDFWriter new createCostReports: self.
self session directUserMessage: 'Erstelle Belege, bitte warten...'.
RKAPDFWriter new createReceiptReports: self.
self session directUserMessage: 'Erstelle Fahrten, bitte warten...'.
RKAPDFWriter new createVehicleReports: self.
self session directUserMessage: 'Erstelle Buchungen, bitte warten...'.
RKAPDFWriter new createBookingReports: self.
self session directUserMessage: ''

I tried I with a test button:
html mdlButton
onClick:
 (html jQuery ajax script: [ :script | self session directUserMessage: 'test' ]);
with: 'set message'

this works perfect - after clicking on the test button, the snackbar is showing every second again.
So, I can say that the principle was clear and I have a possibility to show individual messages by setting the string in the session.

BUT: while I am in the Ajax block, it does not work.
I put a console.log() into the javascript code and AFTER finishing the Ajax, all the messages are put there.
It seems to wait till the Ajax call is finished.

I have put an output  into the transcript: 

renderMessageOn: html
Transcript crShow: Time now printString , '-' , self session directUserMessage.

and there I see, that while I am in the Ajax block, there is no output.
While I am not in the Ajax block, it renders the time into it each second.

What is wrong here, can anyone explain?
Joachim, do you also set the instance variable with the text from an Ajax block? 

Regards
Sabine





View this message in context: Re: immediate display alert to user while Ajax request
Sent from the Seaside General mailing list archive at Nabble.com.


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/immediate-display-alert-to-user-while-Ajax-request-tp4956083p4956392.html
To start a new topic under Seaside General, email [hidden email]
To unsubscribe from Seaside, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: immediate display alert to user while Ajax request

Sabine Manaa
and also thank you for the hint with the ThreadPool, Paul and Ramon.
I have to implement this, too!




2017-07-24 12:18 GMT+02:00 Sabine Manaa <[hidden email]>:
Hi Joachim,

you are right. This was the point.

I had another problem with getting the session in the forked process. I asked in Discord and Max Leske helped.
To geht the session, I have to do the following in the Ajax request:

| requestContext |
 requestContext := WACurrentRequestContext value. 
[ WACurrentRequestContext use: requestContext during: [ self session dosomething ] ] fork.

Thank you for your help!
Sabine

2017-07-23 10:55 GMT+02:00 jtuchel [via Smalltalk] <[hidden email]>:
Sabine,

I think you need to fork  a new (background) process in order to have it run independently of the Ajax callbacks. The Ajax callbacks will be executed one after the other, there will never be any progress reporting.

So I THINK what you absolutely have to do is to start the long running Ajax callback as another process.

So start by putting your sequence of process steps in a

[
 ] fork.

block and see if it improves things.


I am using an inst var of the component instead of the session, but I guess that doesn't really matter. Using the session is probably a much better idea because you could then use this facility for a general solution that works for all ajax callbacks that run longer...


HTH

Joachim



Am 21.07.17 um 17:31 schrieb Sabine Manaa:
Hi Joachim, all,

thanks a lot! I think I am very near to the solution but there is one problem remaining: within the Ajax block, the JQLoad   seems to be "blocked". I explain:

* I have an attribute @directUserMessage: in my session initialized with an empty string.

*In my main view I have >>renderLoadIntervalMessageOn: html
html paragraph
id: 'spf-direct-message';
script:
(html jQuery this load
onComplete:
(' javascript which shows the snackbar if spa-direct-message is set'));
html: [ :r | self renderMessageOn: r ];
interval: 1 seconds);
with: [ self renderMessageOn: html ]

 >>renderMessageOn: html
self session directUserMessage isEmpty
ifFalse: [ html render: self session directUserMessage ]


I have my button invoking the report generation: 

onClick:
(html jQuery ajax
script: [ :script | 
self session generateReportFiles: script.
 ...]);
with: 'PDF'.

in >>generateReportFiles:
"i set the directUserMessages:"
self session directUserMessage: 'Erstelle Reisekostenabrechnungen, bitte warten...'.
RKAPDFWriter new createCostReports: self.
self session directUserMessage: 'Erstelle Belege, bitte warten...'.
RKAPDFWriter new createReceiptReports: self.
self session directUserMessage: 'Erstelle Fahrten, bitte warten...'.
RKAPDFWriter new createVehicleReports: self.
self session directUserMessage: 'Erstelle Buchungen, bitte warten...'.
RKAPDFWriter new createBookingReports: self.
self session directUserMessage: ''

I tried I with a test button:
html mdlButton
onClick:
 (html jQuery ajax script: [ :script | self session directUserMessage: 'test' ]);
with: 'set message'

this works perfect - after clicking on the test button, the snackbar is showing every second again.
So, I can say that the principle was clear and I have a possibility to show individual messages by setting the string in the session.

BUT: while I am in the Ajax block, it does not work.
I put a console.log() into the javascript code and AFTER finishing the Ajax, all the messages are put there.
It seems to wait till the Ajax call is finished.

I have put an output  into the transcript: 

renderMessageOn: html
Transcript crShow: Time now printString , '-' , self session directUserMessage.

and there I see, that while I am in the Ajax block, there is no output.
While I am not in the Ajax block, it renders the time into it each second.

What is wrong here, can anyone explain?
Joachim, do you also set the instance variable with the text from an Ajax block? 

Regards
Sabine





View this message in context: Re: immediate display alert to user while Ajax request
Sent from the Seaside General mailing list archive at Nabble.com.


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


-- 
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          [hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/immediate-display-alert-to-user-while-Ajax-request-tp4956083p4956392.html
To start a new topic under Seaside General, email [hidden email]
To unsubscribe from Seaside, click here.
NAML



View this message in context: Re: immediate display alert to user while Ajax request
Sent from the Seaside General mailing list archive at Nabble.com.

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside