lilalo

changeset 88:385499ec544a

Начал работу над текстовым представлением +
редактором журнала.
Пока что в textarea выводится текстовое представление.

Редактировать можно, но сохранять пока нельзя.

Пытался сделать автоматическое позиционирование курсора
на нужную строку.
Во-первых, не работает в Konqueror и с этим, я так понимаю,
ничего пока сделать нельзя.

Во-вторых, неверно вычисляется строка на которую нужно
позиционировать курсор.

Это, я думаю, можно подправить.

Потом, что-то намутил с utf8. Надо будет более детально
это рассмотреть
author devi
date Thu Mar 02 00:06:54 2006 +0200 (2006-03-02)
parents c70be67ed3d4
children 62001c1e3295
files l3-cgi l3-frontend
line diff
     1.1 --- a/l3-cgi	Tue Feb 28 13:11:26 2006 +0200
     1.2 +++ b/l3-cgi	Thu Mar 02 00:06:54 2006 +0200
     1.3 @@ -81,22 +81,22 @@
     1.4              my $t = $Trainings{$tdate};
     1.5              $print .= "<tr>";
     1.6              $print .= "<td>".$t->{date}."</td>";
     1.7 -            $print .= "<td>".$t->{course}."</td>";
     1.8 +            $print .= "<td colspan='7'>".$t->{course}."</td>";
     1.9              $print .= "</tr>\n";
    1.10 -            $print .= "<tr>";
    1.11 -            $print .= "<td/>";
    1.12 -            $print .= "<td><pre>";
    1.13              for my $host (sort keys %{$t->{host}}) {
    1.14 +                my %row;
    1.15 +                my @row_keys = qw{
    1.16 +                    name email company host root user
    1.17 +                };
    1.18                  my $h = $t->{host}->{$host};
    1.19 -                $print .= "$host";
    1.20 -                $print .= " ".$h->{firstname}." ".$h->{surname}." ";
    1.21 -                $print .= " ".$h->{company}." ";
    1.22 -                $print .= "<a href='/cgi-bin/l3/".$tdate."/".$host."/root'>root</a> ";
    1.23 -                $print .= "<a href='/cgi-bin/l3/".$tdate."/".$host."/".$h->{user}."'>".$h->{user}."</a> ";
    1.24 -                $print .= "\n";
    1.25 +                $row{name}= $h->{firstname}." ".$h->{surname};
    1.26 +                $row{email}= $h->{email};
    1.27 +                $row{company} = $h->{company};
    1.28 +                $row{host} =  "$host";
    1.29 +                $row{root} = "<a href='/cgi-bin/l3/".$tdate."/".$host."/root'>root</a> ";
    1.30 +                $row{user} = "<a href='/cgi-bin/l3/".$tdate."/".$host."/".$h->{user}."'>".$h->{user}."</a> ";
    1.31 +                $print .= "<tr>".join("", map("<td style='$_'>$row{$_}</td>", @row_keys))."</tr>";
    1.32              }
    1.33 -            $print .= "</pre><td>";
    1.34 -            $print .= "</tr>\n";
    1.35          }
    1.36          $print .= "</table>\n";
    1.37          $print .= "</body>\n";
     2.1 --- a/l3-frontend	Tue Feb 28 13:11:26 2006 +0200
     2.2 +++ b/l3-frontend	Thu Mar 02 00:06:54 2006 +0200
     2.3 @@ -3,7 +3,7 @@
     2.4  use IO::Socket;
     2.5  use lib '.';
     2.6  use l3config;
     2.7 -use locale;
     2.8 +use utf8;
     2.9  
    2.10  our @Command_Lines;
    2.11  our @Command_Lines_Index;
    2.12 @@ -41,12 +41,13 @@
    2.13  
    2.14  sub minutes_passed;
    2.15  
    2.16 -sub print_all;
    2.17 -sub print_command_lines;
    2.18 -sub print_files;
    2.19 -sub print_stat;
    2.20 -sub print_header;
    2.21 -sub print_footer;
    2.22 +sub print_all_txt;
    2.23 +sub print_all_html;
    2.24 +sub print_command_lines_html;
    2.25 +sub print_files_html;
    2.26 +sub print_stat_html;
    2.27 +sub print_header_html;
    2.28 +sub print_footer_html;
    2.29  
    2.30  main();
    2.31  
    2.32 @@ -64,7 +65,7 @@
    2.33      load_sessions_from_xml($Config{"backend_datafile"});
    2.34      sort_command_lines;
    2.35      process_command_lines;
    2.36 -    print_all($Config{"output"});
    2.37 +    print_all_txt($Config{"output"});
    2.38      close_mywi_socket;
    2.39  }
    2.40  
    2.41 @@ -420,9 +421,9 @@
    2.42                  $$cl=0;
    2.43              }
    2.44          }
    2.45 -        if ($$cl->{"class"} == "note") {
    2.46 +        if ($$cl->{"class"} eq "note") {
    2.47                  my $note_html = $$cl->{note};
    2.48 -                $note_html = join ("\n", map ("<p>$_</p>", split (/-\n/, $note)));
    2.49 +                $note_html = join ("\n", map ("<p>$_</p>", split (/-\n/, $note_html)));
    2.50                  $note_html =~ s@(http:[a-zA-Z.0-9/?\_%-]*)@<a href='$1'>$1</a>@g;
    2.51                  $note_html =~ s@(www\.[a-zA-Z.0-9/?\_%-]*)@<a href='$1'>$1</a>@g;
    2.52                  $$cl->{"note_html"} = $note_html;
    2.53 @@ -439,7 +440,7 @@
    2.54  Разобранный lab-скрипт должен находиться в массиве @Command_Lines
    2.55  =cut
    2.56  
    2.57 -sub print_command_lines
    2.58 +sub print_command_lines_html
    2.59  {
    2.60  
    2.61      my @toc;                # Оглавление
    2.62 @@ -706,7 +707,7 @@
    2.63  }
    2.64  
    2.65  #############
    2.66 -# print_all
    2.67 +# make_new_entries_table
    2.68  #
    2.69  # Напечатать таблицу неизвестных команд
    2.70  #
    2.71 @@ -757,7 +758,7 @@
    2.72  }
    2.73  
    2.74  #############
    2.75 -# print_all
    2.76 +# minutes_passed
    2.77  #
    2.78  #
    2.79  #
    2.80 @@ -809,23 +810,238 @@
    2.81  }
    2.82  
    2.83  #############
    2.84 -# print_all
    2.85 +# print_all_txt
    2.86  #
    2.87 -#
    2.88 +# Вывести журнал в текстовом формате
    2.89  #
    2.90  # In:       $_[0]       output_filename
    2.91  # Out:
    2.92  
    2.93 +sub print_all_txt
    2.94 +{
    2.95  
    2.96 -sub print_all
    2.97 +    my $output_filename=$_[0];
    2.98 +    my $note_number=0;
    2.99 +
   2.100 +    my $result = q();
   2.101 +    my $this_day_resut = q();
   2.102 +    
   2.103 +    my $cl;
   2.104 +    my $last_tty="";
   2.105 +    my $last_session="";
   2.106 +    my $last_day=q();
   2.107 +    my $last_wday=q();
   2.108 +    my $in_range=0;
   2.109 +
   2.110 +    my $current_command=0;
   2.111 +
   2.112 +    my $cursor_position = 0;
   2.113 +
   2.114 +
   2.115 +    if ($Config{filter}) {
   2.116 +        # Инициализация фильтра
   2.117 +        for (split /&/,$Config{filter}) {
   2.118 +            my ($var, $val) = split /=/;
   2.119 +            $filter{$var} = $val || "";
   2.120 +        }
   2.121 +    }
   2.122 +
   2.123 +
   2.124 +COMMAND_LINE:
   2.125 +    for my $k (@Command_Lines_Index) {
   2.126 +
   2.127 +        my $cl=$Command_Lines[$Command_Lines_Index[$current_command++]];
   2.128 +        next unless $cl;
   2.129 +
   2.130 +
   2.131 +# Пропускаем строки, которые противоречат фильтру
   2.132 +# Если у нас недостаточно информации о том, подходит строка под  фильтр или нет, 
   2.133 +# мы её выводим
   2.134 +
   2.135 +        for my $filter_key (keys %filter) {
   2.136 +            next COMMAND_LINE 
   2.137 +                if defined($cl->{local_session_id})
   2.138 +                && defined($Sessions{$cl->{local_session_id}}->{$filter_key})
   2.139 +                && $Sessions{$cl->{local_session_id}}->{$filter_key} ne $filter{$filter_key};
   2.140 +        }
   2.141 +
   2.142 +# Пропускаем строки, выходящие за границу "signature",
   2.143 +# при условии, что границы указаны
   2.144 +# Пропускаем неправильные/прерванные/другие команды
   2.145 +        if ($Config{"from"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"from"}/) {
   2.146 +            $in_range=1;
   2.147 +            next;
   2.148 +        }
   2.149 +        if ($Config{"to"} && $cl->{"cline"} =~ /$Config{"signature"}\s*$Config{"to"}/) {
   2.150 +            $in_range=0;
   2.151 +            next;
   2.152 +        }
   2.153 +        next    if ($Config{"from"} && $Config{"to"}   && !$in_range) 
   2.154 +                || ($Config{"skip_empty"} =~ /^y/i     && $cl->{"cline"} =~ /^\s*$/ )
   2.155 +                || ($Config{"skip_wrong"} =~ /^y/i     && $cl->{"err"} != 0)
   2.156 +                || ($Config{"skip_interrupted"} =~ /^y/i && $cl->{"err"} == 130);
   2.157 +
   2.158 +
   2.159 +#
   2.160 +##
   2.161 +## Начинается собственно вывод
   2.162 +##
   2.163 +#
   2.164 +
   2.165 +### Сначала обрабатываем границы разделов
   2.166 +### Если тип команды "note", это граница
   2.167 +
   2.168 +        if ($cl->{class} eq "note") {
   2.169 +            $this_day_result .= " === ".$cl->{note_title}." === \n" if $cl->{note_title};
   2.170 +            $this_day_result .= $cl->{note}."\n";
   2.171 +            next;
   2.172 +        }
   2.173 +
   2.174 +        my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime($cl->{time});
   2.175 +
   2.176 +        # Добавляем спереди 0 для удобочитаемости
   2.177 +        $min  = "0".$min  if $min  =~ /^.$/;
   2.178 +        $hour = "0".$hour if $hour =~ /^.$/;
   2.179 +        $sec  = "0".$sec  if $sec  =~ /^.$/;
   2.180 +
   2.181 +        $class=$cl->{"class"};
   2.182 +
   2.183 +# DAY CHANGE
   2.184 +        if ( $last_day ne $day) {
   2.185 +            if ($last_day) {
   2.186 +                $result .= "== ".$Day_Name[$last_wday]." == \n";
   2.187 +                $result .= $this_day_result;
   2.188 +            }
   2.189 +            $last_day   = $day;
   2.190 +            $last_wday  = $wday;
   2.191 +            $this_day_result = q();
   2.192 +        }
   2.193 +
   2.194 +# CONSOLE CHANGE
   2.195 +        if ($cl->{"tty"} && $last_tty ne $cl->{"tty"} && 0) {
   2.196 +            my $tty = $cl->{"tty"};
   2.197 +            $this_day_result .= "         #l3: ------- другая консоль ----\n";
   2.198 +            $last_tty=$cl->{"tty"};
   2.199 +        }
   2.200 +
   2.201 +# Session change
   2.202 +        if ( $last_session ne $cl->{"local_session_id"}) {
   2.203 +            $this_day_result .= "# ------------------------------------------------------------"
   2.204 +                             .  "  l3: local_session_id=".$cl->{"local_session_id"}
   2.205 +                             .  " ---------------------------------- \n";
   2.206 +            $last_session=$cl->{"local_session_id"};
   2.207 +        }
   2.208 +
   2.209 +# TIME
   2.210 +        my @nl_counter = split (/\n/, $result);
   2.211 +        $cursor_position=length($result) - @nl_counter;
   2.212 +
   2.213 +        if ($Config{"show_time"} =~ /^y/i) {
   2.214 +            $this_day_result .= "$hour:$min:$sec" 
   2.215 +        }
   2.216 +
   2.217 +# COMMAND
   2.218 +        $this_day_result .= " ".$cl->{"prompt"}.$cl->{"cline"}."\n";
   2.219 +        if ($cl->{"err"}) {
   2.220 +            $this_day_result .= "         #l3: err=".$cl->{'err'}."\n";
   2.221 +        }
   2.222 +
   2.223 +# OUTPUT
   2.224 +        my $last_command = $cl->{"last_command"};
   2.225 +        if (!( 
   2.226 +        $Config{"suppress_editors"} =~ /^y/i && grep ($_ eq $last_command, @{$Config{"editors"}}) ||
   2.227 +        $Config{"suppress_pagers"}  =~ /^y/i && grep ($_ eq $last_command, @{$Config{"pagers"}}) ||
   2.228 +        $Config{"suppress_terminal"}=~ /^y/i && grep ($_ eq $last_command, @{$Config{"terminal"}})
   2.229 +            )) {
   2.230 +            my $output = $cl->{short_output};
   2.231 +            if ($output) {
   2.232 +                 $output =~ s/^/         |/mg;
   2.233 +            }
   2.234 +            $this_day_result .= $output;
   2.235 +        }
   2.236 +
   2.237 +# DIFF
   2.238 +        if ( $Config{"show_diffs"} =~ /^y/i && $cl->{"diff"}) {
   2.239 +            my $diff = $cl->{"diff"};
   2.240 +            $diff =~ s/^/         |/mg;
   2.241 +            $this_day_result .= $diff;
   2.242 +        };
   2.243 +# SHOT
   2.244 +        if ($Config{"show_screenshots"} =~ /^y/i && $cl->{"screenshot"}) {
   2.245 +            $this_day_result .= "         #l3: screenshot=".$cl->{'screenshot'}."\n";
   2.246 +        }
   2.247 +
   2.248 +#NOTES
   2.249 +        if ( $Config{"show_notes"} =~ /^y/i && $cl->{"note"}) {
   2.250 +            my $note=$cl->{"note"};
   2.251 +            $note =~ s/\n/\n#^/msg;
   2.252 +            $this_day_result .= "#^ == ".$cl->{note_title}." ==\n" if $cl->{note_title};
   2.253 +            $this_day_result .= "#^ ".$note."\n";
   2.254 +        }
   2.255 +
   2.256 +    }
   2.257 +    last: {
   2.258 +        $result .= "== ".$Day_Name[$last_wday]." == \n";
   2.259 +        $result .= $this_day_result;
   2.260 +   }
   2.261 +
   2.262 +
   2.263 +
   2.264 +
   2.265 +  my $SetCursorPosition_JS = <<JS;
   2.266 +function setCursorPosition(oInput,oStart,oEnd) {
   2.267 +    oInput.focus();
   2.268 +    if( oInput.setSelectionRange ) {
   2.269 +        oInput.setSelectionRange(oStart,oEnd);
   2.270 +    } else if( oInput.createTextRange ) {
   2.271 +        var range = oInput.createTextRange();
   2.272 +        range.collapse(true);
   2.273 +        range.moveEnd('character',oEnd);
   2.274 +        range.moveStart('character',oStart);
   2.275 +        range.select();
   2.276 +    }
   2.277 +}
   2.278 +JS
   2.279 +
   2.280 +    if ($output_filename eq "-") {
   2.281 +        print 
   2.282 +               "<html>"
   2.283 +              ."<script>"
   2.284 +              .$SetCursorPosition_JS
   2.285 +              ."</script>"
   2.286 +              ."<body onLoad='setCursorPosition(document.all.mytextarea, $cursor_position, $cursor_position+10)'>"
   2.287 +              ."<textarea rows='30' cols='100' wrap='off' id='mytextarea'>$result</textarea>"
   2.288 +              ."</body>"
   2.289 +              ."</html>"
   2.290 +              ;
   2.291 +    }
   2.292 +    else {
   2.293 +        open(OUT, ">", $output_filename)
   2.294 +            or die "Can't open $output_filename for writing\n";
   2.295 +        print OUT "<pre>$result</pre>";
   2.296 +        close(OUT);
   2.297 +    }
   2.298 +}
   2.299 +
   2.300 +
   2.301 +#############
   2.302 +# print_all_html
   2.303 +#
   2.304 +#
   2.305 +#
   2.306 +# In:       $_[0]       output_filename
   2.307 +# Out:
   2.308 +
   2.309 +
   2.310 +sub print_all_html
   2.311  {
   2.312      my $output_filename=$_[0];
   2.313  
   2.314      my $result;
   2.315 -    my ($command_lines,$toc)  = print_command_lines;
   2.316 -    my $files_section         = print_files;
   2.317 +    my ($command_lines,$toc)  = print_command_lines_html;
   2.318 +    my $files_section         = print_files_html;
   2.319  
   2.320 -    $result = print_header($toc);
   2.321 +    $result = print_header_html($toc);
   2.322  
   2.323  
   2.324  #    $result.= join " <br/>", keys %Sessions;
   2.325 @@ -839,7 +1055,7 @@
   2.326      $result.= "<h2 id='stat'>Статистика</h2>"  . print_stat;
   2.327      $result.= "<h2 id='help'>Справка</h2>"     . $Html_Help . "<br/>"; 
   2.328      $result.= "<h2 id='about'>О программе</h2>". $Html_About. "<br/>"; 
   2.329 -    $result.= print_footer;
   2.330 +    $result.= print_footer_html;
   2.331  
   2.332      if ($output_filename eq "-") {
   2.333          print $result;
   2.334 @@ -853,14 +1069,14 @@
   2.335  }
   2.336  
   2.337  #############
   2.338 -# print_header
   2.339 +# print_header_html
   2.340  #
   2.341  #
   2.342  #
   2.343  # In:   $_[0]       Содержание
   2.344  # Out:              Распечатанный заголовок
   2.345  
   2.346 -sub print_header
   2.347 +sub print_header_html
   2.348  {
   2.349      my $toc = $_[0];
   2.350      my $course_name = $Config{"course-name"};
   2.351 @@ -978,14 +1194,14 @@
   2.352  
   2.353  
   2.354  #############
   2.355 -# print_footer
   2.356 +# print_footer_html
   2.357  #
   2.358  #
   2.359  #
   2.360  #
   2.361  #
   2.362  
   2.363 -sub print_footer
   2.364 +sub print_footer_html
   2.365  {
   2.366      return "</body>\n</html>\n";
   2.367  }
   2.368 @@ -994,14 +1210,14 @@
   2.369  
   2.370  
   2.371  #############
   2.372 -# print_stat
   2.373 +# print_stat_html
   2.374  #
   2.375  #
   2.376  #
   2.377  # In:
   2.378  # Out:
   2.379  
   2.380 -sub print_stat
   2.381 +sub print_stat_html
   2.382  {
   2.383      %StatNames = (
   2.384          FirstCommand        => "Время первой команды журнала",
   2.385 @@ -1106,7 +1322,7 @@
   2.386  }
   2.387  
   2.388  
   2.389 -sub print_files
   2.390 +sub print_files_html
   2.391  {
   2.392      my $result = qq(); 
   2.393      my @toc;