CGI "please wait" message.

Discussion in 'Ruby' started by Milo Thurston, Jun 3, 2004.

  1. 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
     
    Milo Thurston, Jun 3, 2004
    #1
    1. Advertising

  2. Milo Thurston

    Dan Tapp Guest

    Milo Thurston wrote:
    > 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




    --
    ...
    ... dhtapp is a cox dot net account
    ...
     
    Dan Tapp, Jun 3, 2004
    #2
    1. Advertising

  3. Dan Tapp <dhtapp@see_sig_line.com> wrote:
    > 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.

    --
    www.sirwilliamhope.org
     
    Milo Thurston, Jun 3, 2004
    #3
  4. Milo Thurston

    Carlos Guest

    [Milo Thurston <>, 2004-06-03 12.10 CEST]
    [...]
    > 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>"
     
    Carlos, Jun 3, 2004
    #4
  5. Milo Thurston

    Georgy Guest

    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

    "Milo Thurston" <> wrote in message news:c9mr3p$t6e$...
    | 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
     
    Georgy, Jun 5, 2004
    #5
  6. Milo Thurston

    Georgy Guest

    "Georgy" <> wrote in message news:R0gwc.17076$...
    | blah blah blah
    | <script language='JavaScript'>

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

    G-:
    --
    Georgy Pruss
    E#Mail: 'naabbcaDaddaLryDwksvKmyw'.tr('a-zA-Z','0-9a-z.@')
     
    Georgy, Jun 5, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Craig Deelsnyder

    Re: best way to do a "please wait" message

    Craig Deelsnyder, Aug 3, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    788
  2. A.M

    Please Wait ... message

    A.M, May 11, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    490
  3. Replies:
    2
    Views:
    552
  4. =?Utf-8?B?UG9udGlNYXg=?=

    Long-running task: Show DIV with 'Please wait' message

    =?Utf-8?B?UG9udGlNYXg=?=, Feb 10, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    4,440
    =?Utf-8?B?ZmFsY29u?=
    Feb 11, 2005
  5. Ice Man
    Replies:
    5
    Views:
    471
    Ice Man
    Mar 20, 2007
Loading...

Share This Page