X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=action_list_graphs.c;h=c239222051679003587bbcf769d407d9b2abd4df;hb=8f210aa3a93bafab43eba645c9bc2babab999b93;hp=8c78ac10428e508ccd9c494923b0acbb72bc1bb8;hpb=5cc627425e6502b8a025cee810c14136e69071cc;p=collection4.git diff --git a/action_list_graphs.c b/action_list_graphs.c index 8c78ac1..c239222 100644 --- a/action_list_graphs.c +++ b/action_list_graphs.c @@ -6,9 +6,11 @@ #include #include +#include "action_list_graphs.h" #include "graph_list.h" +#include "utils_params.h" -static int print_graph (const graph_list_t *gl, void *user_data) /* {{{ */ +static int print_graph_json (const graph_list_t *gl, void *user_data) /* {{{ */ { _Bool *first; @@ -39,19 +41,75 @@ static int print_graph (const graph_list_t *gl, void *user_data) /* {{{ */ printf ("}"); return (0); -} /* }}} int print_graph */ +} /* }}} int print_graph_json */ -int action_list_graphs (void) /* {{{ */ +static int print_graph_inst_html (graph_config_t *cfg, /* {{{ */ + graph_instance_t *inst, + __attribute__((unused)) void *user_data) { - _Bool first = 1; + char buffer[1024]; - printf ("Content-Type: text/plain\n\n"); + memset (buffer, 0, sizeof (buffer)); + gl_instance_get_params (cfg, inst, buffer, sizeof (buffer)); - gl_update (); + printf ("
  • %s
  • \n", buffer, buffer); + + return (0); +} /* }}} int print_graph_inst_html */ + +static int print_graph_html (graph_config_t *cfg, /* {{{ */ + __attribute__((unused)) void *user_data) +{ + char buffer[1024]; + + memset (buffer, 0, sizeof (buffer)); + gl_graph_get_title (cfg, buffer, sizeof (buffer)); + + printf ("
  • %s\n
      \n", buffer); + gl_graph_instance_get_all (cfg, print_graph_inst_html, /* user_data = */ NULL); + printf ("
    \n"); + + return (0); +} /* }}} int print_graph_html */ + +static int list_graphs_json (void) /* {{{ */ +{ + _Bool first = 1; + + printf ("Content-Type: application/json\n\n"); printf ("[\n"); - gl_foreach (print_graph, /* user_data = */ &first); + gl_foreach (print_graph_json, /* user_data = */ &first); printf ("\n]"); + + return (0); +} /* }}} int list_graphs_json */ + +static int list_graphs_html (void) /* {{{ */ +{ + printf ("Content-Type: text/html\n\n"); + + printf ("
      \n"); + gl_graph_get_all (print_graph_html, /* user_data = */ NULL); + printf ("
    \n"); + + return (0); +} /* }}} int list_graphs_html */ + +int action_list_graphs (void) /* {{{ */ +{ + const char *format; + + gl_update (); + + format = param ("format"); + if (format == NULL) + format = "html"; + + if (strcmp ("json", format) == 0) + return (list_graphs_json ()); + else + return (list_graphs_html ()); } /* }}} int action_list_graphs */ /* vim: set sw=2 sts=2 et fdm=marker : */