From: Ian Jackson Date: Sun, 18 Oct 2009 17:24:41 +0000 (+0100) Subject: printable routetrades: 2-up versions; fix up tbody X-Git-Tag: 5.0^2~12 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=commitdiff_plain;h=764f11c76036161975282b87c4cc4298be5d1088 printable routetrades: 2-up versions; fix up tbody --- diff --git a/yarrg/CommodsWeb.pm b/yarrg/CommodsWeb.pm index 37bbfe7..ab2a4a3 100644 --- a/yarrg/CommodsWeb.pm +++ b/yarrg/CommodsWeb.pm @@ -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(""); + } else { + $m->print(""); + } +} + package CommodsWeb::ExpectedError; sub emsg ($) { diff --git a/yarrg/web/autohandler b/yarrg/web/autohandler index 55b9a93..f69ef55 100644 --- a/yarrg/web/autohandler +++ b/yarrg/web/autohandler @@ -38,10 +38,18 @@ 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 $@"; diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index 1f8df2a..71cdbd2 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -596,6 +596,8 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( + + % }
  • Data age summary @@ -614,8 +616,15 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(

    Voyage trading plan

    +% my $tbody= sub { +% if (!printable($m)) { return ''; } +%# return " +<% $tbody->(1) %> +<% $tbody->(0) %> % } % $total += $t->{Total}; % my $span= 0 + keys %{ $t->{Stalls} }; % my $td= "td rowspan=$span"; - +% 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_datarow($m,$dline); % $pstall->($stallix); % } % @@ -773,7 +782,7 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( $show_total_now->($totals); } - +<% $tbody->(1) %>

    "; +% my ($c)= qw(40 00)[$_[0]]; +% return "
    "; +% }; +% % foreach my $i (0..$#islandids) { -
    % $iquery->execute($islandids[$i]); % my ($islandname) = $iquery->fetchrow_array(); @@ -720,12 +729,12 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( (Data age: <% prettyprint_age($age) %>) % } elsif (!defined $total) { % $total= 0; -
    Total distance: <% $total_dist %> leagues. Overall net cash flow <%