CGI "please wait" message.

M

Milo Thurston

Apologies for the many CGI posts.

Anyway, I am attempting to set up a script that runs blast jobs,
these take some time, so a "pease wait" message whilst they are running
followed displaying the results would be good.
There are suggestiong here:
http://www.daimi.au.dk/~mailund/css/cgi-ui-ex.html
http://tech.irt.org/articles/js172/#io_buffering
....but these are for Perl.

At present, I have something like:

def results(genome)
if genome.empty?
# display the "please select a genome to search" message
else
# show a please wait message
results = run_job(genome)
if results.empty?
# print "nothing found" message
else
# print results
end
end
end

cgi.out do
cgi.html do
cgi.body {
header +
submit_buttons +
results(genome) +
footer
}
end
end

This runs but does not (of course) display the "please wait" part.
Are there any sites similar to the above giving Ruby examples?
Thanks.
 
D

Dan Tapp

Milo said:
Apologies for the many CGI posts.

Anyway, I am attempting to set up a script that runs blast jobs,
these take some time, so a "pease wait" message whilst they are running
followed displaying the results would be good.

{ Snip... }
This runs but does not (of course) display the "please wait" part.
Are there any sites similar to the above giving Ruby examples?
Thanks.

Hi Milo,

I don't have the answer to your question, since I don't know nearly
enough about the various Ruby CGI packages.

So I'd like to build upon your question to the group with one of my own.
Maybe we'll both get what we're looking for.

Back when I worked with WebObjects (which has been a couple of years),
the kit included a special toplevel component called a WOLongResponse,
which was designed for just this type of thing.

IIRC, when instantiating a WOLongResponse, the developer passed in a
Runnable which was responsible for doing the time-consuming work.

He could also optionally pass in the name of a WOComponent which would
return a custom "please wait" page, if he wanted something prettier than
the default.

This is where my memory gets cloudy (I didn't use the page that much),
but I _think_ the developer also passed in the name of the results page
to be called when the background task was complete. That is, I don't
believe the background task was responsible for generating its own page,
since the WOLongResponse would not be able to check the status on the
Runnable that way.

The WOLongResponse would start the background task, and then return the
designated "please wait" page with an embedded meta-refresh. (The
frequency of the refresh was also settable, and defaulted to something
like five seconds.

When the background task had finished, the WOLongResponse would detect
the Runnable status and swap in the final output page on the next
refresh cycle.

Soooo, that (or something like it) seems to be what Milo's looking for.
The question is, does it exist?

- dan
 
M

Milo Thurston

Dan Tapp said:
Soooo, that (or something like it) seems to be what Milo's looking for.
The question is, does it exist?

That's definitely the sort of thing I need.
An equivalent to Perl's CGI::Carp would be good, too. I now find myself
trying to debug this on a server where the administrator won't let me
read the apache error logs...
Anyway, hopefully something will turn up.
Thanks,
Milo.
 
C

Carlos

2004-06-03 12.10 CEST] said:
This runs but does not (of course) display the "please wait" part.
Are there any sites similar to the above giving Ruby examples?
Thanks.

I don't know about any sites. Here is an approach to display the "please
wait" message.

The problem is that cgi.<methods> create strings. When you do

cgi.out { cgi.html { cgi.body { cgi.h1 { ... } } } }

all these methods create strings and only when you have a string with the
whole homepage, it is sent to the client. So, if you want to flush the
output in the middle, you can't use these methods, but have to write the
tags manually.

#!/usr/local/bin/ruby
require "cgi"
require "thread"

cgi = CGI.new "html4"

header = "<h1>HEADER</h1>"
submit_buttons = "<p><i>here the submit buttons</i></p>"

# flush output after each print or puts:
$stdout.sync=true

# manually generate the page until the point where we want to display the
# "please wait" message:
puts cgi.header
puts
puts cgi.doctype
puts "<html><head><title>Your results</title></head><body>"
puts header
puts submit_buttons

# we will put the results of our long calculation in this variable:
results = nil

# this thread will do the calculation, and in the end, will put the results
# in the variable results:
Thread.new do
# our long calculation is only sleep :)
begin
sleep 5
results = "<table border=1><tr><td>result 1</td>" +
"<td>result 2</td></tr></table>"
rescue
results = "<b>BIG ERROR</b>"
end
end

# show the message...
print '<b id="PLEASEWAIT">Please wait ...'

# and wait until there is any result. Meanwhile we show nice progression
# dots...
while !results
print " ."
sleep 0.5
end
# now we have the results
puts "</b>"

# this javascript is to remove the "please wait" message.
# works in mozilla :)
puts '<script>n=document.getElementById("PLEASEWAIT");' +
'n.parentNode.removeChild(n)</script>'

puts results

puts "</body></html>"
 
G

Georgy

There can be two options with the "please wait" trick:
1) You show a page with the "Please wait" message, then you redirect to the final page
2) You make one page with DHTML.
I did the second trick in PHP, but the language doesn't matter here. The idea is the following:
First you output the beginning of your page and finish thi spart with e.g.

<script language="vbscript">
document.body.style.cursor="wait"
document.write "<div id=dvStatus style='color:red;font-weight:700'>Loading...<br>Please wait!<br></div>"
</script>
<script language='JavaScript'>

It may be useful to *flush* the output at this point, but all seems to work w/o flush. I don't
know if Ruby's CGI buffers its output. If so, you need to switch it off or to flush the output
explicitly. Then you do your looooooong stuff: calculate 1_000_000 digits of Pi, generate
fractal pictures, print long tables to your page, whatever. When done, you output this:

<script language="VBScript">
document.body.style.cursor="default"
dvStatus.style.display="none"
</script>

and then you can print some your final stuff and finish with </body></html> :)
It all requires vbscript and IE at the client's site only if you want to show a hour-glass
cursor. If you don't care about the cursor, you can remove the lines relating to it and
switch to JavaScript. Then it could work for Netscape/Opera/etc too, although you
should probably change line [dvStatus.style.display="none"] too.

HTH,
Georgy

| Apologies for the many CGI posts.
|
| Anyway, I am attempting to set up a script that runs blast jobs,
| these take some time, so a "pease wait" message whilst they are running
| followed displaying the results would be good.
| There are suggestiong here:
| http://www.daimi.au.dk/~mailund/css/cgi-ui-ex.html
| http://tech.irt.org/articles/js172/#io_buffering
| ...but these are for Perl.
|
| At present, I have something like:
|
| def results(genome)
| if genome.empty?
| # display the "please select a genome to search" message
| else
| # show a please wait message
| results = run_job(genome)
| if results.empty?
| # print "nothing found" message
| else
| # print results
| end
| end
| end
|
| cgi.out do
| cgi.html do
| cgi.body {
| header +
| submit_buttons +
| results(genome) +
| footer
| }
| end
| end
|
| This runs but does not (of course) display the "please wait" part.
| Are there any sites similar to the above giving Ruby examples?
| Thanks.
|
| --
| www.sirwilliamhope.org
 
G

Georgy

| blah blah blah
| <script language='JavaScript'>

That line with JavaScript is not needed there. It slipped from my original page. Sorry.

G-:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top