X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Faction_list_graphs.c;h=92d82d7e2e779092fa80c546cfceea20ba883634;hb=66e1c8fe2814ddaf803ceee092f1d1dd02a5e981;hp=395d8a14ade0066ccea7ee691d5e4aa0ac64a3e0;hpb=f3a56fb50f24f64724769541096881083a2c29a3;p=collection4.git diff --git a/src/action_list_graphs.c b/src/action_list_graphs.c index 395d8a1..92d82d7 100644 --- a/src/action_list_graphs.c +++ b/src/action_list_graphs.c @@ -5,8 +5,9 @@ #include "action_list_graphs.h" #include "graph.h" +#include "graph_ident.h" #include "graph_list.h" -#include "utils_params.h" +#include "utils_cgi.h" #include #include @@ -62,13 +63,34 @@ static int list_graphs_json (void) /* {{{ */ return (0); } /* }}} int list_graphs_json */ +struct callback_data_s +{ + graph_config_t *cfg; + int limit; +}; +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) { + callback_data_t *data = user_data; char params[1024]; char desc[1024]; + if (data->cfg != cfg) + { + if (data->cfg != NULL) + printf (" \n"); + + memset (desc, 0, sizeof (desc)); + graph_get_title (cfg, desc, sizeof (desc)); + + printf ("
  • %s\n
      \n", desc); + + data->cfg = cfg; + } + memset (params, 0, sizeof (params)); inst_get_params (cfg, inst, params, sizeof (params)); @@ -78,31 +100,47 @@ static int print_graph_inst_html (graph_config_t *cfg, /* {{{ */ printf ("
    • %s
    • \n", script_name (), params, desc); + if (data->limit > 0) + data->limit--; + + /* Abort scan if limit is reached. */ + if (data->limit == 0) + return (1); + return (0); } /* }}} int print_graph_inst_html */ -static int print_graph_html (graph_config_t *cfg, /* {{{ */ - __attribute__((unused)) void *user_data) +static int list_graphs_html (const char *term) /* {{{ */ { - char buffer[1024]; - - memset (buffer, 0, sizeof (buffer)); - graph_get_title (cfg, buffer, sizeof (buffer)); + callback_data_t data = { NULL, /* limit = */ 20 }; + printf ("Content-Type: text/html\n\n"); - printf ("
    • %s\n
        \n", buffer); - gl_graph_instance_get_all (cfg, print_graph_inst_html, /* user_data = */ NULL); - printf ("
    • \n"); + printf ("\n \n"); + if (term != NULL) + printf (" c4: Graphs matching "%s"\n", term); + else + printf (" c4: List of all graphs\n"); + printf (" \n \n"); + + printf ("
      \n" + " \n" + " \n" + " \n" + "
      \n", + script_name (), (term != NULL) ? term : ""); + + printf ("
        \n"); + 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); - return (0); -} /* }}} int print_graph_html */ + if (data.cfg != NULL) + printf ("
      \n"); -static int list_graphs_html (void) /* {{{ */ -{ - printf ("Content-Type: text/html\n\n"); + printf ("
    \n"); - printf ("
      \n"); - gl_graph_get_all (print_graph_html, /* user_data = */ NULL); - printf ("
    \n"); + printf (" \n\n"); return (0); } /* }}} int list_graphs_html */ @@ -120,7 +158,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 : */