chiark / gitweb /
Fix dropdowns for route and commod
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 26 Aug 2009 02:05:21 +0000 (03:05 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 26 Aug 2009 02:05:21 +0000 (03:05 +0100)
yarrg/TODO
yarrg/web/lookup
yarrg/web/query_commod
yarrg/web/query_route

index e6d969e91648011f9866514d17651030c043e397..f21dabff31aeac200c71f4d9737b8778514cf56e 100644 (file)
@@ -23,8 +23,6 @@ commodity mass/volume in live database
 WEBSITE
 -------
 
-dropdowns are broken sometimes
-
 initial/final stocks feature
 
 adjustable potential cost of losses (rather than fixed 1e-BIG per league)
index 4dbd7558e68a8161ad3394f669bb54d5d161c4b8..8fb3bb142a077ce644fd37a3efb1be25046f7390 100755 (executable)
@@ -154,6 +154,7 @@ foreach my $var (@vars) {
 foreach my $var (keys %ARGS) {
        next unless $var =~
                m/^(?: (?:route|commod)string |
+                       commodid |
                        islandid \d |
                        archipelago \d |
                        debug |
index 957526037a81b5107ad30f20ba805ceaf924d5e0..c87b4400fdf9c8b690a274f9f5ce3242e53f9c32 100644 (file)
@@ -36,6 +36,7 @@
 <%args>
 $quri
 $dbh
+$commodid => undef;
 $commodstring => '';
 $prselector
 $someresults
@@ -44,7 +45,7 @@ $emsgokorprint
 
 <%perl>
 my $emsg;
-my ($commodname,$commodid);
+my ($commodname,$cmid);
 
 my $qa= \%ARGS;
 </%perl>
@@ -54,23 +55,34 @@ my $qa= \%ARGS;
 % $prselector->('BuySell');
 % $prselector->('ShowBlank');
 
+<form action="<% $quri->() |h %>" method="get">
+
 %#---------- textbox, user enters route as string ----------
 % if (!$qa->{Dropdowns}) {
 
 Enter commodity (abbreviations are OK):<br>
 
-<form action="<% $quri->() |h %>" method="get">
-
 <&| qtextstring, qa => $qa, dbh => $dbh,
     thingstring => 'commodstring', emsgstore => \$emsg,
-    perresult => sub { ($commodname,$commodid)= @_; }
+    perresult => sub { ($commodname,$cmid)= @_; }
  &>
  size=80
 </&>
 
 % } else { #---------- dropdowns, user selects from menus ----------
 
-Not yet implemented.
+%      my $sth= $dbh->prepare("SELECT commodname,commodid FROM commods
+%                                      ORDER BY commodname");
+%      $sth->execute();
+%      my $row;
+<select name="commodid">
+<option value="">Select commodity...</option>
+%      while ($row= $sth->fetchrow_arrayref) {
+%              my $selected= $commodid eq $row->[1] ? 'selected' : '';
+<option value="<% $row->[1] %>" <% $selected %>><% $row->[0] |h %></option>
+%              ($commodname,$cmid) = @$row if $selected;
+%      }
+</select>
 
 % } #---------- end of dropdowns, now common middle of page code ----------
 
@@ -83,8 +95,8 @@ Not yet implemented.
 %#========== results ==========
 <%perl>
 
-$emsgokorprint->($emsg) or $commodid=undef;
-return unless defined $commodid;
+$emsgokorprint->($emsg) or $cmid=undef;
+return unless defined $cmid;
 $someresults->();
 
 #---------- actually compute the results and print them ----------
@@ -131,13 +143,13 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {
 <th>+/-10%
 <th>Any
 </tr>
-%      $islands->execute($commodid);
+%      $islands->execute($cmid);
 %      my $island;
 %      my %ts_sortkeys;
 %      my $rowix= 0;
 %      while ($island= $islands->fetchrow_hashref) {
 %              my $islandid= $island->{'islandid'};
-%              $offers->execute($commodid, $islandid);
+%              $offers->execute($cmid, $islandid);
 %              my ($offer, $bestprice, $marginal, @beststalls);
 %              my $tqty= $island->{'tqty'};
 %              my $cqty= '';
@@ -176,7 +188,7 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {
 %                      $stallname= sprintf "%d offers", scalar @beststalls;
 %              }
 %
-%              $cqty == $tqty or die "$bs $cqty $tqty $commodid $islandid ";
+%              $cqty == $tqty or die "$bs $cqty $tqty $cmid $islandid ";
 <tr id=<% $rowid %> class="<% 'datarow'.($rowix & 1) %>">
      <td><% $s->[0]= $island->{'archipelago'} |h %>
      <td><% $s->[1]= $island->{'islandname'} |h %>
index ee457f57abd41502ad3d54f58385b16638e8ced5..393e7a668755145d05262a56b56ed005330669c1 100644 (file)
@@ -86,10 +86,10 @@ Enter route (islands, or archipelagoes, separated by |s or commas;
 
 % } else { #---------- dropdowns, user selects from menus ----------
 
-$startform->(grep {
-               defined %ARGS{"archipelago$dd"} ||
-               defined %ARGS{"islandid$dd"}
-       } (0..$qa->{Dropdowns}-1));
+$startform->(grep {
+%              defined $ARGS{"archipelago$_"} ||
+%              defined $ARGS{"islandid$_"}
+%      } (0..$qa->{Dropdowns}-1));
 
 <%perl>
 my ($sth,$row);