From 72587d0d7358ca77ecd0ede859abba7f89b1d9d2 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 16 Aug 2009 14:19:35 +0100 Subject: [PATCH] Further refactoring to make query_commod small --- yarrg/web/lookup | 18 +++++++++++++- yarrg/web/qtextstring | 18 ++++++++++++++ yarrg/web/query_commod | 34 +++++++++++++++++++++------ yarrg/web/query_route | 53 +++++++++++++----------------------------- 4 files changed, 78 insertions(+), 45 deletions(-) diff --git a/yarrg/web/lookup b/yarrg/web/lookup index 64860fd..1b85ecc 100755 --- a/yarrg/web/lookup +++ b/yarrg/web/lookup @@ -162,6 +162,13 @@ die if $styles{Query} =~ m/[^a-z]/; dbw_connect($styles{Ocean}); +my $results_head_done=0; +my $someresults= sub { + return if $results_head_done; + $results_head_done=1; + print "\n

Results

\n"; +}; + <%args> $debug => 0 @@ -169,7 +176,16 @@ $debug => 0
-<& "query_$styles{Query}", %baseqf, %queryqf, %styles, quri => $quri &> +<& "query_$styles{Query}", %baseqf, %queryqf, %styles, quri => $quri, + someresults => $someresults, + emsgokorprint => sub { + my ($emsg) = @_; + return 1 unless defined $emsg and length $emsg; + $someresults->(); + print $emsg; + return 0; + } + &>

diff --git a/yarrg/web/qtextstring b/yarrg/web/qtextstring index 45f2e32..3b0bd6b 100644 --- a/yarrg/web/qtextstring +++ b/yarrg/web/qtextstring @@ -37,6 +37,8 @@ <%args> $thingstring +$emsgstore +$perresult $qa => $m->caller_args(1)->{'qa'} <%perl> @@ -94,3 +96,19 @@ window.onload= ts_Needed; >

 

+ +<%perl> +if (length $thingstring) { + my ($emsg,$canonstring,$results)= $m->comp('qtextstringcheck', + what => $thingstring, + ocean => $qa->{Ocean}, + string => $stringval, + format => 'return' + ); + $$emsgstore= $emsg; + + foreach my $entry (@$results) { + $perresult->(@$entry); + } +} + diff --git a/yarrg/web/query_commod b/yarrg/web/query_commod index 2358b41..eddc097 100644 --- a/yarrg/web/query_commod +++ b/yarrg/web/query_commod @@ -36,29 +36,49 @@ <%args> $quri $commodstring => ''; +$someresults +$emsgokorprint -% my $qa= \%ARGS; +<%perl> +my $emsg; +my ($commodname,$commodid); -%#---------- textbox, user enters route as string ---------- -% if (!$qa->{Dropdowns}) { +my $qa= \%ARGS; +

Select commodity

+%#---------- textbox, user enters route as string ---------- +% if (!$qa->{Dropdowns}) { + Enter commodity (abbreviations are OK):
-<&| qtextstring, qa => $qa, thingstring => 'commodstring' &> +<&| qtextstring, qa => $qa, thingstring => 'commodstring', emsgstore => \$emsg, + perresult => sub { ($commodname,$commodid)= @_; } + &> size=80 +% } else { #---------- dropdowns, user selects from menus ---------- + +Not yet implemented. + +% } #---------- end of dropdowns, now common middle of page code ---------- + -% my $ours= sub { $_[0] =~ m/^commodstring/; }; +% my $ours= sub { $_[0] =~ m/^commodstring|^commodid/; }; <& "lookup:formhidden", ours => $ours &>
-% } else { #---------- dropdowns, user selects from menus ---------- +%#========== results ========== +% $emsgokorprint->($emsg) or $commodid=undef; -% } #---------- end of dropdowns, now common middle of page code ---------- +% if (defined $commodid) { +% $someresults->(); +COMMODITY <% $commodid %> named <% $commodname |h %> + +% } diff --git a/yarrg/web/query_route b/yarrg/web/query_route index 8f6d99c..66dee1d 100644 --- a/yarrg/web/query_route +++ b/yarrg/web/query_route @@ -36,9 +36,12 @@ <%args> $quri $routestring => ''; +$someresults +$emsgokorprint -<%perl> +<%perl> +my $emsg; my @archipelagoes; my @islandids; my %islandid2; @@ -56,14 +59,20 @@ Enter route (islands, or archipelagoes, separated by |s or commas;
-<&| qtextstring, qa => $qa, thingstring => 'routestring' &> +<&| qtextstring, qa => $qa, thingstring => 'routestring', emsgstore => \$emsg, + perresult => sub { + my ($canonname, $island, $arch) = @_; + push @islandids, $island; + push @archipelagoes, defined $island ? undef : $arch; + } + &> size=80 % } else { #---------- dropdowns, user selects from menus ---------- <%perl> -my ($sth,$row);; +my ($sth,$row); my @archlistdata; my %islandlistdata; $islandlistdata{'none'}= [ [ "none", "Select island..." ] ]; @@ -161,36 +170,9 @@ function ms_Setarch(dd) {
<%perl> -#========== result computations ========== +#========== results ========== -my $results_head; -$results_head= sub { - print "

Results

\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) = @_; @@ -207,7 +189,7 @@ for my $dd (0..$qa->{Dropdowns}-1) { my $ii= $islandid2{$island}; my $iarch= $ii->{Arch}; if ($iarch ne $arch) { - $results_head->(); + $someresults->(); Specified archipelago <% $arch %> but island <% $ii->{Name} %> @@ -220,12 +202,9 @@ for my $dd (0..$qa->{Dropdowns}-1) { push @islandids, $island; } -}#---------- result processing, common stuff % if (@islandids) { -% $results_head->(); - +% $someresults->(); <& routetrade, islandids => \@islandids, archipelagoes => \@archipelagoes &> - % } -- 2.30.2