Page 1 of 1

VLWeb Completed Event for File Downloads

Posted: Fri Apr 24, 2020 3:33 am
by jyoung
When downloading a file from a Server Module that uses the Response(*RESOURCE) parameter, is there any way to get a notification that download is completed?

For example, here is a simple Server Module

Code: Select all

begin_com role(*EXTENDS #PRIM_SRVM)

srvroutine name(DownloadCSV) response(*resource #Response)
define_com class(#XPRIM_OSUtil) name(#util)
define field(#contentstring) type(*CHAR) length(256) decimals(0)

* simulate a lot of work
#util.ThreadSleep( 10000 )

* not a CSV, but it get the the job done. :D
#contentstring := '{"JOBID":"' + *JOBNBR + '","ServerStatus":"OK",' + '"CPUTYPE":"' + *CPUTYPE + '",' + '"LANSAPGMLIB":"' + *LANSAPGMLIB + '"}'

#Response.ContentString := #ContentString
#Response.AttachmentFileName := 'MyCSV.CSV'
endroutine

end_com
Here is a Web Page that downloads the CSV

Code: Select all

begin_com role(*EXTENDS #PRIM_WEB) LayoutManager(#Layout1)

define_com class(#PRIM_TBLO) name(#Layout1)
define_com class(#PRIM_TBLO.Row) name(#Layout1Row1) DisplayPosition(1) Parent(#Layout1)
define_com class(#PRIM_TBLO.Column) name(#Layout1Column1) DisplayPosition(1) Parent(#Layout1)

define_com class(#PRIM_MD.RaisedButton) name(#Button) Caption('PRIMARY') DisplayPosition(1) Left(165) Parent(#COM_OWNER) TabPosition(1) ThemeDrawStyle('MediumTitle') Top(203)
define_com class(#PRIM_IMAG) name(#LoadingImage) DisplayPosition(2) Image(#xImageImage32) ImageSizing(None) Left(428) Parent(#COM_OWNER) TabPosition(2) TabStop(False) Top(172) Visible(False)

define_com class(#JoesTestModule.DownloadCSV) name(#Download)

evtroutine handling(#Com_owner.Initialize)
#LoadingImage.Image <= #SYS_WEB.LoadingImage
endroutine

evtroutine handling(#Button.Click)
#LoadingImage.Visible := True
#Download.Execute
#LoadingImage.Visible := False
endroutine

end_com
As you can see, what I am trying to do is toggle a loading image while the server module is working.

The Execute is supposed to be synchronous but it seems to be acting asynchronously in that it returns right after the execute call.

We have gotten around this in the past by using target(NEW) on download definition, to force the download in a new window.
Wondering if anyone has better way to handle this.

Thanks,
Joe

Re: VLWeb Completed Event for File Downloads

Posted: Fri Apr 24, 2020 9:12 am
by BrendanB
Joe,

2 things here:

1. when you have a routine that does:

routine <<< can be evtroutine or mthroutine
<<showloading image>>
<< do important stuff >>
<<hideloading image>>
endroutine

what happens is the *SCREEN IS NOT RENDERED* until the endroutine.

if you were to do:

Code: Select all

Define_Evt Name(DownloadRequested)

Evtroutine Handling(#Button.Click)
#LoadingImage.Visible := True
Signal Event(DownloadRequested)
Endroutine

Evtroutine Handling(#COM_OWNER.DownloadRequested)
#Download.Execute
#LoadingImage.Visible := False
Endroutine
This might have a better chance of showing your loading image.

I usually use a normal serverRoutine, and return a BLOB. It is possible with a small widget to get the browser to show the download window for the file. This allows me to use ExecuteAsync (which is important if the file is fairly large), which will give you All 4 events (Uploading, Downloading, Completed, Failed) and in fact you can use the 'downloading' even to show a percentage indicator.

Re: VLWeb Completed Event for File Downloads

Posted: Fri Apr 24, 2020 11:19 pm
by jyoung
I tried doing the same with a a timer (instead of an event) where I show the loading image and start the timer on the button click and then on the timer tick, execute and hide the timer.

I never tried it with a blob, however. Will have to give that go.

Thanks,
Joe