chiark / gitweb /
Reorganise docs to include new howto material in intro etc.
[ypp-sc-tools.db-live.git] / yarrg / web / lookup
index a118de0905a4d1e58cd500fcc732b20811f847ef..6fc1cd76e0cafa0d93da1ce9c8d3037f1254616b 100755 (executable)
@@ -37,7 +37,7 @@
 <%perl>
 my %ahtml;
 my @vars;
-my %styleqf;
+my %styles;
 
 #---------- "mode" argument parsing and mode menu at top of page ----------
 
@@ -57,7 +57,35 @@ my %styleqf;
                Before => 'Query: ',
                Values => [     [ 'route', 'Trades for route' ],
                                [ 'commod', 'Prices for commodity' ],
+                               [ 'offers', 'Offers at location' ],
+                               [ 'routesearch', 'Find profitable route' ],
                                [ 'age', 'Data age' ] ]
+       }, {    Name => 'BuySell',
+               Before => '',
+               Values => [     [ 'buy_sell',   'Buy and sell' ],
+                               [ 'sell_buy',   'Sell and buy' ],
+                               [ 'buy',        'Buy offers only' ],
+                               [ 'sell',       'Sell offers only' ],
+                       ],
+               QuerySpecific => 1,
+       }, {    Name => 'ShowBlank',
+               Before => '',
+               Values => [     [ 0, 'Omit islands with no offers' ],
+                               [ 'show', 'Show all islands' ],
+                       ],
+               QuerySpecific => 1,
+       }, {    Name => 'ShowStalls',
+               Before => '',
+               Values => [     [ 0, 'Show total quantity at each price' ],
+                               [ 1, 'Show individual stalls' ],
+                       ],
+               QuerySpecific => 1,
+       }, {    Name => 'RouteSearchType',
+               Before => 'Type of routes to search for: ',
+               Values => [     [ 0, 'Open-ended' ],
+                               [ 1, 'Circular' ],
+                       ],
+               QuerySpecific => 1,
        });
 
 foreach my $var (@vars) {
@@ -70,37 +98,78 @@ foreach my $var (@vars) {
                $val= [ $val, encode_entities($val) ];
        }
        if (exists $ARGS{$lname}) {
-               $styleqf{$name}= $ARGS{$lname};
-               my @html= grep { $_->[0] eq $styleqf{$name} }
+               $styles{$name}= $ARGS{$lname};
+               my @html= grep { $_->[0] eq $styles{$name} }
                                @{ $var->{Values} };
                $ahtml{$name}= @html==1 ? $html[0][1] : '???';
        } else {
-               $styleqf{$name}= $var->{Values}[0][0];
+               $styles{$name}= $var->{Values}[0][0];
                $ahtml{$name}= $var->{Values}[0][1];
        }
 }
 
 </%perl>
-<html><head><title><% ucfirst $ahtml{Query} %> - YARRG</title></head><body>
 
-<a href="<% $m->current_comp()->name() |u %>">YARRG</a> -
- Yet Another Revenue Research Gatherer
-|
-<a href="docs">documentation</a>
+<%shared>
+my %baseqf;
+my %queryqf;
+</%shared>
+
+<%method formhidden>
+<%args>
+$ours
+</%args>
+% foreach my $n (keys %baseqf, keys %queryqf) {
+%      next if $ours->($n);
+%      my $v= exists $baseqf{$n} ? $baseqf{$n} : $queryqf{$n};
+<input type=hidden name=<% $n %> value="<% $v |h %>">
+% }
+</%method>
+
+<html lang="en"><head><title><% ucfirst $ahtml{Query} %> - YARRG</title>
+<style type="text/css">
+<& style.css &>
+  body { color: #000000; background: #c5c7ae; }
+  div.query { background: #d7d8b3; padding: 1em; }
+  div.results { padding: 1em; }
+  table.data { background: #b5b686; }
+  tr.datarow0 { background: #e3e3e3; }
+  tr.datarow1 { background: #ffffff; }
+</style>
+<&| script &>
+  function register_onload(f) {
+    var previous_onload= window.onload;
+    window.onload= function() {
+      if (previous_onload) previous_onload();
+      f();
+    };
+  }
+</&script>
+</head><body>
+
+% if (!printable($m)) {
+<div class="navoptbar">
+<& navbar &>
 <p>
+% }
 <%perl>
 
-my %baseqf;
 foreach my $var (@vars) {
        my $lname= lc $var->{Name};
        next unless exists $ARGS{$lname};
        $baseqf{$lname}= $ARGS{$lname};
 }
 
-my %queryqf;
 foreach my $var (keys %ARGS) {
        next unless $var =~
-               m/^(?:routestring|islandid\d|archipelago\d|debug)$/;
+               m/^(?: (?:route|commod|capacity|capital|island)string |
+                       lossperleague | distance |
+                       commodid |
+                       islandid \d |
+                       archipelago \d |
+                       debug |
+                       [RT]\w+
+                   )$/x;
        my $val= $ARGS{$var};
        next if $val eq 'none';
        $queryqf{$var}= $val;
@@ -112,11 +181,13 @@ my $quri= sub {
        $uri->path_query();
 };
 
-foreach my $var (@vars) {
+my $prselector_core= sub {
+       my ($var)= @_;
+       return if printable($m);
        my $name= $var->{Name};
        my $lname= lc $var->{Name};
        my $delim= $var->{Before};
-       my $canon= &{$var->{CmpCanon}}($styleqf{$name});
+       my $canon= &{$var->{CmpCanon}}($styles{$name});
        my $cvalix= 0;
        foreach my $valr (@{ $var->{Values} }) {
                print $delim;  $delim= "\n|\n";
@@ -139,32 +210,72 @@ foreach my $var (@vars) {
                $cvalix++;
        }
        print "<p>\n\n";
+};
+
+my $prselector= sub {
+       my ($name)= @_;
+       foreach my $var (@vars) {
+               if ($var->{Name} eq $name) {
+                       $prselector_core->($var);
+                       return;
+               }
+       }
+       die $name;
+};
+
+foreach my $var (@vars) {
+       next if $var->{QuerySpecific};
+       $prselector_core->($var);
 }
 
 #---------- initial checks, startup, main entry form ----------
 
-die if $styleqf{Query} =~ m/[^a-z]/;
+die if $styles{Query} =~ m/[^a-z]/;
+
+my $mydbh;
+my $dbh= ($mydbh= dbw_connect($styles{Ocean}));
 
-dbw_connect($styleqf{Ocean});
+my $results_head_done=0;
+my $someresults= sub {
+       return if $results_head_done;
+       $results_head_done=1;
+       my ($h)= @_;
+       $h= 'Results' if !$h;
+       print "\n<h1>$h</h1>\n";
+};
 
 </%perl>
 <%args>
 $debug => 0
 </%args>
 
+% if (!printable($m)) {
+</div>
 <hr>
+% }
 
-<& "query_$styleqf{Query}", %baseqf, %queryqf, %styleqf, quri => $quri &>
-
-<p>
+<& "query_$styles{Query}", %baseqf, %queryqf, %styles,
+    quri => $quri, dbh => $dbh,
+    baseqf => \%baseqf, queryqf => \%queryqf, allargs => \%ARGS,
+    prselector => $prselector,
+    someresults => $someresults,
+    emsgokorprint => sub {
+       my ($emsg) = @_;
+       return 1 unless defined $emsg and length $emsg;
+       $someresults->();
+       print $emsg;
+       return 0;
+    }
+ &>
 
 %#---------- debugging and epilogue ----------
 
 % if ($debug) {
-<p>
+<div class="results">
 <pre id="debug_log">
 Debug log:
 </pre>
+</div>
 % }
 
 <&| script &>
@@ -184,3 +295,8 @@ use HTML::Entities;
 use URI::Escape;
 
 </%init>
+<%cleanup>
+
+$mydbh->rollback() if $mydbh;
+
+</%cleanup>