From: Jakub Narebski Date: Sun, 24 Jan 2010 13:54:50 GMT Subject: [RFC PATCH 11/10] gitweb: Ajax-y "Generating..." page when regenerating cache (WIP) Message-ID: <1264341290-11356-1-git-send-email-jnareb@gmail.com> In-Reply-To: Signed-off-by: Jakub Narebski --- This patch, as you can see, lack proper commit message: it is work in progress (and very much proof of concept patch). This is Ajax-y JavaScript-based activity indicator. It is very bare-bones, without any error checking or fallback in the case we misdetected and JavaScript is turned off. Also currently it would work only for subsequent links from gitweb, with 'js=1' added. We need to mark Ajax request to _not_ create "Generating..." page. I have used there custon 'X-Ajax' HTTP header; we could use 'Pragma: wait', or ejen additional query parameter for that. gitweb/gitweb.perl | 69 +++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 50 insertions(+), 19 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index cb46b8c..d422a4b 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -3219,6 +3219,9 @@ sub blob_contenttype { sub git_generating_data_html { my ($cache, $key, $lock_fh) = @_; + if ($cgi->http('X-Ajax')) { + return; + } if ($action eq 'atom' || $action eq 'rss' || $action eq 'opml' || # feeds $action eq 'blob_plain' || # unknown mimetype $action eq 'commitdiff_plain' || # text/plain @@ -3241,6 +3244,7 @@ sub git_generating_data_html { } } + my $use_javascript = $cgi->param('js'); my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : ''; print STDOUT $cgi->header(-type => 'text/html', -charset => 'utf-8', -status=> '200 OK', -expires => 'now'); @@ -3253,31 +3257,58 @@ sub git_generating_data_html { - +EOF + if (!$use_javascript) { + print STDOUT qq!\n!; + } + print STDOUT <<"EOF"; $title EOF - print STDOUT 'Generating..'; - - my $ready; - my ($wait, $wait_step, $wait_max); # in seconds - $wait = 0; - $wait_step = 2; - $wait_max = 20; - $| = 1; # autoflush - do { - print STDOUT '.'; - - sleep $wait_step if ($wait > 0); - $wait += $wait_step; - - $ready = flock($lock_fh, LOCK_SH|LOCK_NB) - if $lock_fh; - - } while (!$ready && ($wait < $wait_max)); + if ($use_javascript) { + my $url_self = href(-replay=>1); + print STDOUT <<"EOF"; +Generating...
+ + +EOF + } else { + print STDOUT 'Generating..'; + + my $ready; + my ($wait, $wait_step, $wait_max); # in seconds + $wait = 0; + $wait_step = 2; + $wait_max = 20; + $| = 1; # autoflush + do { + print STDOUT '.'; + + sleep $wait_step if ($wait > 0); + $wait += $wait_step; + + $ready = flock($lock_fh, LOCK_SH|LOCK_NB) + if $lock_fh; + + } while (!$ready && ($wait < $wait_max)); + } print STDOUT <<"EOF"; -- 1.6.6.1