chiark / gitweb /
Vessel names for capacity seem to work
[ypp-sc-tools.db-test.git] / yarrg / web / query_route
index dd8644f1675694d200e28341d0b32bc5d6396422..ed9fa4406c70ba1fd7aaaaad7dab4fe02f89a50e 100644 (file)
 </%doc>
 <%args>
 $quri
+$dbh
+$prselector
 $routestring => '';
+$capacitystring => '';
+$lossperleague => '';
+$someresults
+$emsgokorprint
 </%args>
-<%perl>
 
+<%perl>
+my $emsg;
 my @archipelagoes;
 my @islandids;
 my %islandid2;
+my ($max_volume, $max_mass);
+my $lossperleaguepct;
 
 my $qa= \%ARGS;
+
+my $be_post;
+my $startform= sub {
+       ($be_post)= @_;
+</%perl>
+<form action="<% $quri->() |h %>" method="<% $be_post ? 'post' : 'get' %>">
+<%perl>
+};
+my $goupdate= sub { $be_post ? 'Update' : 'Go' };
+
 </%perl>
 
+<h1>Specify route</h1>
+
+% $prselector->('ShowStalls');
+
 %#---------- textbox, user enters route as string ----------
 % if (!$qa->{Dropdowns}) {
 
-<h1>Specify route</h1>
+Enter route (islands, or archipelagoes, separated by |s or commas;
+ abbreviations are OK):<br>
 
-<form action="<% $quri->() |h %>" method="get">
+% $startform->($routestring =~ m/\S/);
 
-<&| qtextstring, qa => $qa, thingstring => 'routestring' &>
+<&| qtextstring, qa => $qa, dbh => $dbh,
+    thingstring => 'routestring', emsgstore => \$emsg,
+    perresult => sub {
+       my ($canonname, $island, $arch) = @_;
+       push @islandids, $island;
+       push @archipelagoes, defined $island ? undef : $arch;
+    }
+ &>
  size=80
 </&>
 
+<strong>Advanced options - you may leave these blank:</strong>
+<p>
+<table>
+<tr>
+<td>
+
+Vessel or capacity:
+<&| qtextstring, qa => $qa, dbh => $dbh, prefix => 'cs',
+    thingstring => 'capacitystring', emsgstore => \$emsg,
+    perresult => sub {
+        ($max_mass,$max_volume) = @_;
+    }
+ &>
+ size=40
+</&>
+
+<td>
+&nbsp;
+&nbsp;
+
+<td>
+Expected losses:
+
+<&| qtextstring, qa => $qa, dbh => $dbh, prefix => 'll',
+    thingstring => 'lossperleague', emsgstore => \$emsg,
+    perresult => sub { ($lossperleaguepct)= @_; }
+ &>
+ size=10
+</&>
+
+</table>
+
 % } else { #---------- dropdowns, user selects from menus ----------
 
+% $startform->(grep {
+%              defined $ARGS{"archipelago$_"} ||
+%              defined $ARGS{"islandid$_"}
+%      } (0..$qa->{Dropdowns}-1));
+
 <%perl>
-my ($sth,$row);;
+my ($sth,$row);
 my @archlistdata;
 my %islandlistdata;
 $islandlistdata{'none'}= [ [ "none", "Select island..." ] ];
@@ -78,8 +146,6 @@ my $optionlistmap= sub {
        return $out;
 };
 
-my $dbh= dbw_connect($qa->{Ocean});
-
 $sth= $dbh->prepare("SELECT DISTINCT archipelago FROM islands
                            ORDER BY archipelago;");
 $sth->execute();
@@ -108,12 +174,8 @@ foreach my $arch (keys %islandlistdata) {
                $optionlistmap->($islandlistdata{$arch}, '');
 }
 
-$dbh->rollback();
-
 </%perl>
 
-<input type=hidden name=dropdowns value="<% $qa->{Dropdowns} |h %>">
-
 <&| script &>
 ms_lists= <% to_json_protecttags(\%resetislandlistdata) %>;
 function ms_Setarch(dd) {
@@ -154,40 +216,16 @@ function ms_Setarch(dd) {
 
 % } #---------- end of dropdowns, now common middle of page code ----------
 
-<input type=submit name=submit value="Go">
-</form>
+<input type=submit name=submit value="<% $goupdate->() %>">
+% my $ours= sub { $_[0] =~
+%  m/^island|^archipelago|^routestring|^capacitystring|^lossperleague|^[RT]/;
+% };
+<& "lookup:formhidden", ours => $ours &>
 
 <%perl>
-#========== result computations ==========
+#========== results ==========
 
-my $results_head;
-$results_head= sub {
-       print "<h1>Results</h1>\n";
-       $results_head= sub { };
-};
-
-#---------- result computation - textstring ----------
-if (!$qa->{Dropdowns}) {
-  if (length $routestring) {
-       $results_head->();
-       my ($emsg,$canonstring,$results)= $m->comp('qtextstringcheck',
-               what => 'routestring',
-               ocean => $qa->{Ocean},
-               string => $routestring,
-               format => 'return'
-       );
-       if (length $emsg) {
-               print encode_entities($emsg);
-       } else {
-               foreach my $entry (@$results) {
-                       push @islandids, $entry->[1];
-                       push @archipelagoes,
-                               defined $entry->[1] ? undef : $entry->[2];
-               } 
-       }
-  }
-
-} else { #---------- results - dropdowns ----------
+$emsgokorprint->($emsg) or @islandids=();
 
 my $argorundef= sub {
        my ($dd,$base) = @_;
@@ -204,7 +242,7 @@ for my $dd (0..$qa->{Dropdowns}-1) {
                my $ii= $islandid2{$island};
                my $iarch= $ii->{Arch};
                if ($iarch ne $arch) {
-                       $results_head->();
+                       $someresults->();
 </%perl>
  Specified archipelago <% $arch %> but
  island <% $ii->{Name} %>
@@ -217,12 +255,18 @@ for my $dd (0..$qa->{Dropdowns}-1) {
        push @islandids, $island;
 }
 
-}#---------- result processing, common stuff
 </%perl>
 
 % if (@islandids) {
-%      $results_head->();
-
-<& routetrade, islandids => \@islandids, archipelagoes => \@archipelagoes &>
-
+%      $someresults->('Relevant trades');
+<& routetrade,
+   dbh => $dbh,
+   islandids => \@islandids,
+   archipelagoes => \@archipelagoes,
+   qa => $qa,
+   max_mass => $max_mass,
+   max_volume => $max_volume,
+   lossperleaguepct => $lossperleaguepct
+ &>
+</form>
 % }