chiark / gitweb /
printable routetrades: 2-up versions; fix up tbody
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 18 Oct 2009 17:24:41 +0000 (18:24 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 18 Oct 2009 17:24:41 +0000 (18:24 +0100)
yarrg/CommodsWeb.pm
yarrg/web/autohandler
yarrg/web/routetrade

index 37bbfe7dcbcc2d878eb5a2d7016458b616358e35..ab2a4a30a322e002135422a558eb1ecaff0b4c3e 100644 (file)
@@ -50,8 +50,9 @@ BEGIN {
     @ISA         = qw(Exporter);
     @EXPORT      = qw(&dbw_connect &dbw_filename &ocean_list &sourcebasedir
                      &to_json_shim &to_json_protecttags
-                     &set_ctype_utf8 &webdatadir &printable
+                     &set_ctype_utf8 &webdatadir
                      &expected_error &dbw_lookup_string
+                     &printable &tr_datarow
                      &prettyprint_age &meta_prettyprint_age);
     %EXPORT_TAGS = ( );
 
@@ -203,12 +204,24 @@ sub expected_error ($) {
 sub printable ($) { # printable($m)  where $m is the Mason request object
     my ($m) = @_;
     my $a= scalar $m->caller_args(-1);
-    foreach my $t (qw(pdf ps html)) {
+    foreach my $t (qw(pdf ps html pdf2 ps2)) {
        return $t if $a->{"printable_$t"};
     }
     return 0;
 }
 
+sub tr_datarow ($$) {
+    my ($m, $lineno) = @_;
+    $lineno &= 1;
+    if (!printable($m)) {
+       $m->print("<tr class=\"datarow$lineno\">");
+    } else {
+       $m->print("<tr bgcolor=\"".
+                 ($lineno ? "#ffffff" : "#e3e3e3" ).
+                 "\">");
+    }
+}
+
 package CommodsWeb::ExpectedError;
 
 sub emsg ($) {
index 55b9a93695552295b4899d5a52fd0fd5ca4f3651..f69ef55a53d92529c3a68f29d673e4238504d2ed 100644 (file)
 use CommodsWeb;
 
 my $printable= printable($m);
-if ($printable eq 'pdf' || $printable eq 'ps') {
+if ($printable =~ m/^pdf|^ps/) {
        my $output;
        my $got= $m->call_self(\$output);
        if ($got) {
+               my @htargs= qw(htmldoc --continuous --gray --size 210x279mm);
+               $printable =~ m/^[a-z]+/;
+               push @htargs, '-t',$&;
+               if ($printable =~ m/2$/) {
+                       push @htargs, qw(--nup 2);
+               }
+               push @htargs, qw(-);
+
                my $tmpfile= IO::File::new_tmpfile();
                print $tmpfile $output or die $!;
                $tmpfile->flush() or die $!;
@@ -52,8 +60,8 @@ if ($printable eq 'pdf' || $printable eq 'ps') {
                        eval {
                                $ENV{'HTMLDOC_NOCGI'}=1;
                                open STDIN, '<&', $tmpfile or die $!;
-                               exec qw(htmldoc -t),$printable,qw(
-                                   --continuous --gray --size 210x279mm -);
+
+                               exec @htargs;
                                die $!;
                        };
                        print STDERR "HTMLDOC FAILURE $@";
index 1f8df2a5afdb6eafd5215a38f71cce74ad03dce5..71cdbd2152b7ba870e9cb4994e9993758f16a84d 100644 (file)
@@ -596,6 +596,8 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
          <input type=submit name=printable_pdf value="PDF">
          <input type=submit name=printable_html value="HTML">
          <input type=submit name=printable_ps value="PostScript">
+         <input type=submit name=printable_pdf2 value="PDF 2-up">
+         <input type=submit name=printable_ps2 value="PostScript 2-up">
   </ul>
 % }
  <li><a href="#dataage">Data age summary</a>
@@ -614,8 +616,15 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
 <h2><a name="plan">Voyage trading plan</a></h2>
 
 <table rules=groups>
+% my $tbody= sub {
+%      if (!printable($m)) { return '<tbody>'; }
+%#  return "<tr><td colspan=7><hr>";
+%      my ($c)= qw(40 00)[$_[0]];
+%      return "<tr><td bgcolor=\"#${c}${c}${c}\" height=1 colspan=7>";
+% };
+%
 % foreach my $i (0..$#islandids) {
-<tbody>
+<% $tbody->(1) %>
 <tr><td colspan=4>
 %      $iquery->execute($islandids[$i]);
 %      my ($islandname) = $iquery->fetchrow_array();
@@ -720,12 +729,12 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
 (Data age: <span id="<% $cellid %>"><% prettyprint_age($age) %></span>)
 %              } elsif (!defined $total) {
 %                      $total= 0;
-<tbody>
+<% $tbody->(0) %>
 %              }
 %              $total += $t->{Total};
 %              my $span= 0 + keys %{ $t->{Stalls} };
 %              my $td= "td rowspan=$span";
-<tr class="datarow<% $dline %>">
+% tr_datarow($m,$dline);
 <<% $td %>><% $collectdeliver %>
 <<% $td %>><% $t->{'commodname'} |h %>
 %
@@ -741,7 +750,7 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
 <<% $td %> align=right><% $t->{Total} |h %> total
 %
 %              foreach my $stallix (1..$#stalls) {
-<tr class="datarow<% $dline %>">
+% tr_datarow($m,$dline);
 %                      $pstall->($stallix);
 %              }
 %
@@ -773,7 +782,7 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
      $show_total_now->($totals);
 }
 </%perl><a name="summary"></a>
-<tbody><tr>
+<% $tbody->(1) %><tr>
 <td colspan=2>Total distance: <% $total_dist %> leagues.
 <td colspan=3 align=right>Overall net cash flow
 <td align=right><strong><%