2 * collection4 - action_show_graph.c
3 * Copyright (C) 2010 Florian octo Forster
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
21 * Florian octo Forster <ff at octo.it>
32 #include "action_show_graph.h"
35 #include "graph_ident.h"
36 #include "graph_instance.h"
37 #include "graph_list.h"
38 #include "utils_cgi.h"
41 #include <fcgi_stdio.h>
43 #define OUTPUT_ERROR(...) do { \
44 printf ("Content-Type: text/plain\n\n"); \
45 printf (__VA_ARGS__); \
49 #define MAX_SHOW_GRAPHS 10
51 struct show_graph_data_s
55 typedef struct show_graph_data_s show_graph_data_t;
57 static int show_time_selector (__attribute__((unused)) void *user_data) /* {{{ */
61 pl = param_create (/* query string = */ NULL);
62 param_set (pl, "begin", NULL);
63 param_set (pl, "end", NULL);
64 param_set (pl, "button", NULL);
66 printf ("<form action=\"%s\" method=\"get\">\n", script_name ());
68 param_print_hidden (pl);
70 printf (" <select name=\"begin\">\n"
71 " <option value=\"-3600\">Hour</option>\n"
72 " <option value=\"-86400\">Day</option>\n"
73 " <option value=\"-604800\">Week</option>\n"
74 " <option value=\"-2678400\">Month</option>\n"
75 " <option value=\"-31622400\">Year</option>\n"
77 " <input type=\"submit\" name=\"button\" value=\"Go\" />\n");
84 } /* }}} int show_time_selector */
86 static int left_menu (__attribute__((unused)) void *user_data) /* {{{ */
88 printf ("\n<ul class=\"menu left\">\n"
89 " <li><a href=\"%s?action=list_graphs\">All graphs</a></li>\n"
94 } /* }}} int left_menu */
96 static int show_instance_cb (graph_instance_t *inst, /* {{{ */
99 show_graph_data_t *data = user_data;
103 memset (descr, 0, sizeof (descr));
104 inst_describe (data->cfg, inst, descr, sizeof (descr));
105 html_escape_buffer (descr, sizeof (descr));
107 memset (params, 0, sizeof (params));
108 inst_get_params (data->cfg, inst, params, sizeof (params));
109 html_escape_buffer (params, sizeof (params));
111 printf (" <li class=\"instance\"><a href=\"%s?action=show_instance;%s\">"
113 script_name (), params, descr);
116 } /* }}} int show_instance_cb */
118 static int show_graph (void *user_data) /* {{{ */
120 show_graph_data_t *data = user_data;
122 printf ("<h2>Available instances</h2>\n");
123 printf ("<ul class=\"instance_list\">\n");
124 graph_inst_foreach (data->cfg, show_instance_cb, data);
128 } /* }}} int show_graph */
130 int action_show_graph (void) /* {{{ */
132 page_callbacks_t pg_callbacks = PAGE_CALLBACKS_INIT;
133 show_graph_data_t pg_data;
138 memset (&pg_data, 0, sizeof (pg_data));
139 pg_data.cfg = gl_graph_get_selected ();
140 if (pg_data.cfg == NULL)
141 OUTPUT_ERROR ("gl_graph_get_selected () failed.\n");
143 memset (tmp, 0, sizeof (tmp));
144 graph_get_title (pg_data.cfg, tmp, sizeof (tmp));
145 snprintf (title, sizeof (title), "Graph \"%s\"", tmp);
146 title[sizeof (title) - 1] = 0;
148 pg_callbacks.top_right = html_print_search_box;
149 pg_callbacks.middle_left = left_menu;
150 pg_callbacks.middle_center = show_graph;
151 pg_callbacks.middle_right = show_time_selector;
153 html_print_page (title, &pg_callbacks, &pg_data);
156 } /* }}} int action_show_graph */
158 /* vim: set sw=2 sts=2 et fdm=marker : */