contrib/collection3: Minor HTML work-around for some browsers.
[collectd.git] / contrib / collection3 / bin / index.cgi
index 927767e..54d4102 100755 (executable)
@@ -27,11 +27,11 @@ use HTML::Entities ('encode_entities');
 
 use Data::Dumper;
 
-use Collectd::Graph::Config (qw(gc_read_config));
+use Collectd::Graph::Config (qw(gc_read_config gc_get_scalar));
 use Collectd::Graph::TypeLoader (qw(tl_load_type));
 use Collectd::Graph::Common (qw(get_files_from_directory get_all_hosts
       get_timespan_selection get_selected_files get_host_selection
-      get_plugin_selection));
+      get_plugin_selection flush_files));
 use Collectd::Graph::Type ();
 
 our $Debug = param ('debug') ? 1 : 0;
@@ -145,7 +145,7 @@ HTML
     <title>collection.cgi, Version 3</title>
     <link rel="icon" href="../share/shortcut-icon.png" type="image/png" />
     <link rel="stylesheet" href="../share/style.css" type="text/css" />
-    <script type="text/javascript" src="../share/navigate.js" />
+    <script type="text/javascript" src="../share/navigate.js"></script>
   </head>
   <body onload="nav_init ($begin, $end);">
 HTML
@@ -210,17 +210,6 @@ HTML
        <input type="hidden" name="action" value="show_selection" />
        <input type="submit" name="ok_button" value="OK" />
       </fieldset>
-      <fieldset>
-       <legend>Move all graphs</legend>
-       <input type="button" name="earlier" value="&#x2190;" title="Earlier"
-         onclick="nav_move_earlier ('*');" />
-       <input type="button" name="zoom_out" value="-" title="Zoom out"
-         onclick="nav_zoom_out ('*');" />
-       <input type="button" name="zoom_in" value="+" title="Zoom in"
-         onclick="nav_zoom_in ('*');" />
-       <input type="button" name="later" value="&#x2192;" title="Later"
-         onclick="nav_move_later ('*');" />
-      </fieldset>
     </form>
 HTML
 } # show_selector
@@ -282,20 +271,28 @@ sub action_show_selection
   start_html ();
   show_selector ();
 
-  my $ident = {};
-
   my $all_files;
+  my $timespan;
+
   my $types = {};
 
   my $id_counter = 0;
 
   $all_files = get_selected_files ();
+  $timespan = get_timespan_selection ();
 
   if ($Debug)
   {
     print "<pre>", Data::Dumper->Dump ([$all_files], ['all_files']), "</pre>\n";
   }
 
+  # Send FLUSH command to the daemon if necessary and possible.
+  flush_files ($all_files,
+      begin => time () - $timespan,
+      end => time (),
+      addr => gc_get_scalar ('UnixSockAddr', undef),
+      interval => gc_get_scalar ('Interval', 10));
+
   for (@$all_files)
   {
     my $file = $_;
@@ -324,8 +321,6 @@ sub action_show_selection
     my $type = $_;
     my $graphs_num = $types->{$type}->getGraphsNum ();
 
-    my $timespan = get_timespan_selection ();
-
     for (my $i = 0; $i < $graphs_num; $i++)
     {
       my $args = $types->{$type}->getGraphArgs ($i);
@@ -340,8 +335,7 @@ sub action_show_selection
             <div class="graph_float">
               <img id="${id}" class="graph_image"
                 alt="A graph"
-                src="$url"
-               ondblclick="nav_handle_dblclick (event);" />
+                src="$url" />
               <div class="controls zoom">
                 <div title="Earlier"
                   onclick="nav_move_earlier ('${id}');">&#x2190;</div>
@@ -363,6 +357,8 @@ sub action_show_selection
                   onclick="nav_time_reset ('${id}', 31 * 86400);">M</div>
                 <div title="Show current year"
                   onclick="nav_time_reset ('${id}', 366 * 86400);">Y</div>
+                <div title="Set all images to this timespan"
+                  onclick="nav_set_reference ('${id}');">!</div>
               </div>
             </div>
           </div>