From: Ian Jackson Date: Sun, 23 Aug 2009 15:16:07 +0000 (+0100) Subject: Turn @columns=qw(..) into @cols=( {Name=>...}... ) X-Git-Tag: 3.4~132 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.web-live.git;a=commitdiff_plain;h=7f92b134aef043ef30305f3175d3559829b04805 Turn @columns=qw(..) into @cols=( {Name=>...}... ) --- diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index 45e0f81..ee15afb 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -142,17 +142,33 @@ my $sth= $dbh->prepare($stmt); $sth->execute(@query_params); my @flows; -my @columns; +my @cols; + +my $addcols= sub { + my $base= shift @_; + foreach my $name (@_) { + push @cols, { Name => $name, %$base }; + } +}; + if ($qa->{ShowStalls}) { - push @columns, qw(org_name org_stallname dst_name dst_stallname); + $addcols->({ Text => 1 }, qw( + org_name org_stallname + dst_name dst_stallname + )); } else { - push @columns, qw(org_name dst_name); + $addcols->({Text => 1 }, qw( + org_name dst_name + )); } -my $ntextcolumns= @columns+1; -push @columns, qw(commodname - org_qty org_price dst_qty dst_price - Margin unitprofit - MaxQty MaxCapital MaxProfit); +$addcols->({ Text => 1 }, qw(commodname)); +$addcols->({}, + qw( org_qty org_price dst_qty dst_price + Margin unitprofit MaxQty + )); +$addcols->({ Total => 1 }, qw( + MaxCapital MaxProfit + )); @@ -365,7 +381,12 @@ if ($qa->{'debug'}) { die unless $found_section; }; -push @columns, qw(OptQty OptCapital OptProfit); +$addcols->({}, qw( + OptQty + )); +$addcols->({ Total => 1 }, qw( + OptCapital OptProfit + )); @@ -425,12 +446,11 @@ push @columns, qw(OptQty OptCapital OptProfit); {UidShort} %> value=""> {UidShort} %> value="" <% $flow->{Suppress} ? '' : 'checked' %> > -% foreach my $ci (0..$#columns) { -% my $col= $columns[$ci]; -% my $v= $flow->{$col}; -% my $isnum= $ci >= $ntextcolumns; -% $v='' if $isnum && !$v; -><% $v |h %> +% foreach my $ci (0..$#cols) { +% my $col= $cols[$ci]; +% my $v= $flow->{$col->{Name}}; +% $v='' if !$col->{Text} && !$v; +{Text} ? '' : 'align=right' %>><% $v |h %> % } % }