From c207016fddd7b5eadab694676d8c7b1cc7f626bf Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 26 Jun 2010 16:10:07 +0100 Subject: [PATCH] navbar things --- cgi | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 14 deletions(-) diff --git a/cgi b/cgi index 3c0e124..56948a2 100755 --- a/cgi +++ b/cgi @@ -90,10 +90,30 @@ if (param('debug')) { print "Content-Type: text/plain\n\n"; } +our @navsettings; + +sub navsetting ($) { + my ($nav) = @_; + my $var= $nav->{Variable}; + $$var= param($nav->{Param}); + $$var= $nav->{Default} if !defined $$var; + die $nav->{Param} unless grep { $_ eq $$var } @{ $nav->{Values} }; + push @navsettings, $nav; +} + +our $section; + +navsetting({ + Desc => 'Section', + Param => 'section', + Variable => \$section, + Default => $sections[0], + Values => [@sections], + Show => sub { return $_[0]; } +}); + + my $gname= param('graph'); -my $section= param('section'); -$section ||= $sections[0]; -die unless $sections{$section}; if ($gname) { my $g= $graphs{$section,$gname}; @@ -122,18 +142,35 @@ if ($gname) { sub start_page ($) { my ($title) = @_; print header(), start_html($title); - my $delim= ''; - foreach my $s2 (@sections) { - print $delim; - if ($s2 eq $section) { - print "$section"; - } else { - print "$s2"; + my $outerdelim= ''; + foreach my $nav (@navsettings) { + print $outerdelim; + print $nav->{Desc}, ": "; + my $delim= ''; + my $current= $nav->{Variable}; $current= $$current; + foreach my $couldbe (@{ $nav->{Values} }) { + print $delim; + my $show= $nav->{Show}($couldbe); + if ($couldbe eq $current) { + print "$show"; + } else { + print "{Variable}; $current2= $$current2; + $current2= $couldbe if $nav2->{Param} eq $nav->{Param}; + next if $current2 eq $nav2->{Default}; + print $delim2, "$nav2->{Param}=$current2"; + $delim2= '&'; + } + print "\">$show"; + } + $delim= ' | '; } - $delim= ' | '; + $outerdelim= "
\n"; } + print "\n"; + print h1("$title"); } @@ -149,6 +186,20 @@ if ($detail) { exit 0; } +our $sloth; + +navsetting({ + Desc => 'Time interval', + Param => 'sloth', + Variable => \$sloth, + Default => 1, + Values => [0..2], + Show => sub { + my ($sl) = @_; + return ('Narrower', 'Normal', 'Wider')[$sl]; + } +}); + if (param('debug')) { use Data::Dumper; print Dumper(\%graphs); @@ -160,7 +211,7 @@ start_page("$section graphs"); foreach my $gname (@{ $sections{$section} }) { my $g= $graphs{$section,$gname}; print ""; - my $end= $timeranges[$g->{Slower}+1]; + my $end= $timeranges[$g->{Slower}+$sloth]; my $imgurl= "$self?graph=$gname§ion=$section&end=$end"; print "\n"; } -- 2.30.2