chiark / gitweb /
navbar things
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 26 Jun 2010 15:10:07 +0000 (16:10 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 26 Jun 2010 15:10:07 +0000 (16:10 +0100)
cgi

diff --git a/cgi b/cgi
index 3c0e124df4dffdba101d6a8b3c066f77d2c3f926..56948a2e2b93f3208b11d43f1aaa3c8566efbb63 100755 (executable)
--- 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 "<b>$section</b>";
-       } else {
-           print "<a href=\"$self";
-           if ($s2 ne $sections[0]) { print "?section=$s2"; }
-           print "\">$s2</a>";
+    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 "<b>$show</b>";
+           } else {
+               print "<a href=\"$self";
+               my $delim2= '?';
+               foreach my $nav2 (@navsettings) {
+                   my $current2= $nav2->{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</a>";
+           }
+           $delim= ' | ';
        }
-       $delim= ' | ';
+       $outerdelim= "<br>\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 "<a href=\"$self?detail=$gname&section=$section\">";
-    my $end= $timeranges[$g->{Slower}+1];
+    my $end= $timeranges[$g->{Slower}+$sloth];
     my $imgurl= "$self?graph=$gname&section=$section&end=$end";
     print "<img src=\"$imgurl\"></a>\n";
 }