chiark / gitweb /
Compress flow ids
[ypp-sc-tools.web-live.git] / yarrg / web / lookup
index 751a99aa1a6916382c3843c610eda6691a02868b..cfffd146af3548c87efcccde44ea0b2db3090c8a 100755 (executable)
@@ -35,9 +35,9 @@
 
 </%doc>
 <%perl>
-my %a;
 my %ahtml;
 my @vars;
+my %styles;
 
 #---------- "mode" argument parsing and mode menu at top of page ----------
 
@@ -56,7 +56,28 @@ my @vars;
        }, {    Name => 'Query',
                Before => 'Query: ',
                Values => [     [ 'route', 'Trades for route' ],
+                               [ 'commod', 'Prices for commodity' ],
                                [ '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 amount at each price' ],
+                               [ 1, 'Show individual stalls' ],
+                       ],
+               QuerySpecific => 1,
        });
 
 foreach my $var (@vars) {
@@ -69,16 +90,34 @@ foreach my $var (@vars) {
                $val= [ $val, encode_entities($val) ];
        }
        if (exists $ARGS{$lname}) {
-               $a{$name}= $ARGS{$lname};
-               my @html= grep { $_->[0] eq $a{$name} } @{ $var->{Values} };
+               $styles{$name}= $ARGS{$lname};
+               my @html= grep { $_->[0] eq $styles{$name} }
+                               @{ $var->{Values} };
                $ahtml{$name}= @html==1 ? $html[0][1] : '???';
        } else {
-               $a{$name}= $var->{Values}[0][0];
+               $styles{$name}= $var->{Values}[0][0];
                $ahtml{$name}= $var->{Values}[0][1];
        }
 }
 
 </%perl>
+
+<%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><head><title><% ucfirst $ahtml{Query} %> - YARRG</title></head><body>
 
 <a href="<% $m->current_comp()->name() |u %>">YARRG</a> -
@@ -88,17 +127,20 @@ foreach my $var (@vars) {
 <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)string |
+                       islandid \d |
+                       archipelago \d |
+                       debug |
+                       [RT]\w+
+                   )$/x;
        my $val= $ARGS{$var};
        next if $val eq 'none';
        $queryqf{$var}= $val;
@@ -110,11 +152,12 @@ my $quri= sub {
        $uri->path_query();
 };
 
-foreach my $var (@vars) {
+my $prselector_core= sub {
+       my ($var)= @_;
        my $name= $var->{Name};
        my $lname= lc $var->{Name};
        my $delim= $var->{Before};
-       my $canon= &{$var->{CmpCanon}}($a{$name});
+       my $canon= &{$var->{CmpCanon}}($styles{$name});
        my $cvalix= 0;
        foreach my $valr (@{ $var->{Values} }) {
                print $delim;  $delim= "\n|\n";
@@ -137,13 +180,37 @@ 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 $a{Query} =~ m/[^a-z]/;
+die if $styles{Query} =~ m/[^a-z]/;
+
+my $mydbh;
+my $dbh= ($mydbh= dbw_connect($styles{Ocean}));
 
-dbw_connect($a{Ocean});
+my $results_head_done=0;
+my $someresults= sub {
+       return if $results_head_done;
+       $results_head_done=1;
+       print "\n<h1>Results</h1>\n";
+};
 
 </%perl>
 <%args>
@@ -152,7 +219,18 @@ $debug => 0
 
 <hr>
 
-<& "query_$a{Query}", %baseqf, %queryqf, quri => $quri, a => \%a &>
+<& "query_$styles{Query}", %baseqf, %queryqf, %styles,
+    quri => $quri, dbh => $dbh,
+    prselector => $prselector,
+    someresults => $someresults,
+    emsgokorprint => sub {
+       my ($emsg) = @_;
+       return 1 unless defined $emsg and length $emsg;
+       $someresults->();
+       print $emsg;
+       return 0;
+    }
+ &>
 
 <p>
 
@@ -182,3 +260,8 @@ use HTML::Entities;
 use URI::Escape;
 
 </%init>
+<%cleanup>
+
+$mydbh->rollback() if $mydbh;
+
+</%cleanup>