Changeset 23137


Ignore:
Timestamp:
2010-10-14T23:30:24+13:00 (11 years ago)
Author:
davidb
Message:

Preparation work to support monitoring of multiple files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/cgi-bin/talkback-progressbar.pl

    r23089 r23137  
    3737   
    3838    my $per = 0;
    39     if($ENV{CONTENT_LENGTH} >  0){
     39    if ($ENV{CONTENT_LENGTH} > 0) {
    4040        $per = int(($bytes_read * 100) / $ENV{CONTENT_LENGTH});
    4141    }
     
    4545    # Useful debug to slow down a 'fast' upload
    4646    # Sleep for 10 msecs
    47     #select(undef, undef, undef, 0.01);
     47    select(undef, undef, undef, 0.01);
    4848}
    4949
     
    160160#=====
    161161
    162 # accessed from HTML web page through perlAjax
    163 
    164 sub check_status {
    165    
    166     my $filename = $gsdl_cgi->param('uploadedfile');
    167     $filename =~ s{^(.*)\/}{};
    168 
     162
     163
     164sub inc_wait_dots
     165{
    169166    my $wait_filename = &util::filename_cat($gsdl_tmp_dir,"wait.txt");
    170167    open(WIN,"<$wait_filename");
     
    179176    close(WOUT);
    180177
    181     my $monitor_filename = "$gsdl_tmp_dir/$filename-progress.txt";
     178    return $wait_dots;
     179}
     180
     181sub check_status_single_file
     182{
     183    my ($filename) = @_;
     184    $filename =~ s{^(.*)\/}{};
     185
     186    my $monitor_filename = &util::filename_cat($gsdl_tmp_dir,
     187                           "$filename-progress.txt");
    182188
    183189    if (! -f  $monitor_filename ) {
    184 
    185     return $wait_dots;
    186     }
    187        
    188        
     190    return "";
     191    }
     192               
    189193    open my $PROGRESS, '<', $monitor_filename or die $!;
    190194    my $s = do { local $/; <$PROGRESS> };
    191195    close ($PROGRESS);
    192196   
    193     my $small = 300 - ($s * 3);
    194     my $big = $s * 3;
    195    
    196     my $r = "$wait_dots ";
    197     $r .= '<div style="width:' . $big . 'px;height:10px;background-color:#dddd00;float:left"></div>';
    198     $r .= '<div style="width:' . $small . 'px;height:10px;background-color:#008000;float:left"></div>';
    199     $r .= '<div style="float:left;width: 80px">&nbsp;' . $s . '%</div>';
     197    my $fgwidth = int($s * 1.5);
     198    my $bgwidth = 150 - $fgwidth;
     199 
     200    my $fgcol = "background-color:#dddd00;";
     201    my $bgcol = "background-color:#008000;";
     202
     203    my $style_base = "height:10px; float:left;";
     204
     205    my $r = "";
     206    $r .= "<div style=\"float:left;\">$filename:</div>";
     207    $r .= "<div style=\"width: ${fgwidth}px; $fgcol $style_base\"></div>";
     208    $r .= "<div style=\"width: ${bgwidth}px; $bgcol $style_base\"></div>";
     209    $r .= "<div style=\"float:left; width: 80px\">&nbsp;$s%</div>";
     210    $r .= "<br>";
    200211
    201212    return $r;
    202    
    203 }
    204 
    205 
    206 
     213}
     214
     215
     216sub check_status_all
     217{
     218    my $file_central = &util::filename_cat($gsdl_tmp_dir,"file-central.txt");
     219
     220    my $html = "";
     221
     222    if (open my $FC, '<', $file_central) {
     223    # Read entire file in all at once
     224    my $file_list_str = do { local $/; <$FC> };
     225    my @file_list = split(/\n/,$file_list_str);
     226
     227    foreach my $f (@file_list) {
     228        $html .= check_status_single_file($f);
     229    }
     230
     231    close ($FC);
     232    }
     233    else {
     234    # error
     235    $html = "Failed to open $file_central: $!\n";
     236    }
     237
     238    return $html;
     239
     240}
    207241
    208242 
     243# Accessed from HTML web page through the majic of perlAjax
     244
     245sub check_status
     246{   
     247
     248    my $wait_dots = inc_wait_dots();
     249    my $html = "$wait_dots<br>";
     250
     251    my $filename = $gsdl_cgi->param('uploadedfile');
     252    if (defined $filename) {
     253    $html .= check_status_single_file($filename);
     254    }
     255    else {
     256    $html .= check_status_all();
     257    }
     258
     259    return $html;
     260}
Note: See TracChangeset for help on using the changeset viewer.