First attempt at a search infrastructure.
[collection4.git] / action_list_graphs.c
index 4ec9a30..08d0eb4 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "action_list_graphs.h"
 #include "graph.h"
+#include "graph_ident.h"
 #include "graph_list.h"
 #include "utils_params.h"
 
@@ -62,41 +63,59 @@ static int list_graphs_json (void) /* {{{ */
   return (0);
 } /* }}} int list_graphs_json */
 
+struct callback_data_s
+{
+  graph_config_t *cfg;
+};
+typedef struct callback_data_s callback_data_t;
+
 static int print_graph_inst_html (graph_config_t *cfg, /* {{{ */
     graph_instance_t *inst,
-    __attribute__((unused)) void *user_data)
+    void *user_data)
 {
-  char buffer[1024];
+  callback_data_t *data = user_data;
+  char params[1024];
+  char desc[1024];
 
-  memset (buffer, 0, sizeof (buffer));
-  inst_get_params (cfg, inst, buffer, sizeof (buffer));
+  if (data->cfg != cfg)
+  {
+    if (data->cfg != NULL)
+      printf ("  </ul></li>\n");
 
-  printf ("<li><a href=\"test.fcgi?action=graph;%s\">%s</a></li>\n", buffer, buffer);
+    memset (desc, 0, sizeof (desc));
+    graph_get_title (cfg, desc, sizeof (desc));
 
-  return (0);
-} /* }}} int print_graph_inst_html */
+    printf ("  <li>%s\n  <ul>\n", desc);
 
-static int print_graph_html (graph_config_t *cfg, /* {{{ */
-    __attribute__((unused)) void *user_data)
-{
-  char buffer[1024];
+    data->cfg = cfg;
+  }
 
-  memset (buffer, 0, sizeof (buffer));
-  graph_get_title (cfg, buffer, sizeof (buffer));
+  memset (params, 0, sizeof (params));
+  inst_get_params (cfg, inst, params, sizeof (params));
 
-  printf ("<li>%s\n<ul>\n", buffer);
-  gl_graph_instance_get_all (cfg, print_graph_inst_html, /* user_data = */ NULL);
-  printf ("</ul>\n");
+  memset (desc, 0, sizeof (desc));
+  inst_describe (cfg, inst, desc, sizeof (desc));
+
+  printf ("    <li><a href=\"test.fcgi?action=graph;%s\">%s</a></li>\n",
+      params, desc);
 
   return (0);
-} /* }}} int print_graph_html */
+} /* }}} int print_graph_inst_html */
 
-static int list_graphs_html (void) /* {{{ */
+static int list_graphs_html (const char *term) /* {{{ */
 {
+  callback_data_t data = { NULL };
   printf ("Content-Type: text/html\n\n");
 
   printf ("<ul>\n");
-  gl_graph_get_all (print_graph_html, /* user_data = */ NULL);
+  if (term == NULL)
+    gl_instance_get_all (print_graph_inst_html, /* user_data = */ &data);
+  else
+    gl_search (term, print_graph_inst_html, /* user_data = */ &data);
+
+  if (data.cfg != NULL)
+    printf ("  </ul></li>\n");
+
   printf ("</ul>\n");
 
   return (0);
@@ -115,7 +134,7 @@ int action_list_graphs (void) /* {{{ */
   if (strcmp ("json", format) == 0)
     return (list_graphs_json ());
   else
-    return (list_graphs_html ());
+    return (list_graphs_html (param ("search")));
 } /* }}} int action_list_graphs */
 
 /* vim: set sw=2 sts=2 et fdm=marker : */