From bdba5c4c05a79ccf54b3523c1802663e4ca3bb55 Mon Sep 17 00:00:00 2001 From: m-lopez-f Date: Mon, 12 Sep 2016 16:22:58 +0200 Subject: [PATCH] Add label with macros in reports. Ticket: #37 (cherry picked from commit a804040d7973fdc7c02d072526586496cba61b70) --- .../reporting_builder.item_editor.php | 68 ++++++++- .../godmode/reporting/reporting_builder.php | 68 +++++++++ pandora_console/include/functions_agents.php | 11 ++ pandora_console/include/functions_graph.php | 2 +- pandora_console/include/functions_modules.php | 11 ++ .../include/functions_reporting.php | 122 +++++++++++++++- .../include/functions_reporting_html.php | 20 ++- pandora_console/include/graphs/fgraph.php | 3 +- .../graphs/flot/jquery.flot.axislabels.js | 137 ++++++++++++++++++ .../include/graphs/flot/pandora.flot.js | 5 +- .../include/graphs/functions_flot.php | 19 ++- .../help/en/help_reports_label_field.php | 25 ++++ .../help/es/help_reports_label_field.php | 25 ++++ 13 files changed, 490 insertions(+), 26 deletions(-) create mode 100755 pandora_console/include/graphs/flot/jquery.flot.axislabels.js create mode 100755 pandora_console/include/help/en/help_reports_label_field.php create mode 100755 pandora_console/include/help/es/help_reports_label_field.php diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index bafa4d4536..5ccd6c7b9c 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -51,6 +51,7 @@ $idAgent = null; $idAgentModule = null; $idCustomGraph = null; $text = null; +$label = null; $header = null; $idCustom = null; $url = null; @@ -553,7 +554,33 @@ switch ($action) { $max_values = $item ['top_n_value']; // Max values break; } - + switch ($type) { + case 'event_report_agent': + case 'simple_graph': + case 'agent_configuration': + case 'event_report_module': + case 'alert_report_agent': + case 'alert_report_module': + case 'historical_data': + case 'sumatory': + case 'database_serialized': + case 'monitor_report': + case 'min_value': + case 'max_value': + case 'avg_value': + case 'projection_graph': + case 'prediction_date': + case 'TTRT': + case 'TTO': + case 'MTBF': + case 'MTTR': + case 'simple_baseline_graph': + $label = (isset($style['label'])) ? $style['label'] : ''; + break; + default: + $label = ''; + break; + } //Restore db connection if ($meta && $server_name != '') { metaconsole_restore_db(); @@ -640,7 +667,6 @@ $class = 'databox filters'; ?> - @@ -650,6 +676,16 @@ $class = 'databox filters'; + + + + + + + diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index b177f82e93..e51c0b8fa6 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -38,7 +38,7 @@ include_once($config['homedir'] . "/include/functions_ui.php"); include_once($config['homedir'] . "/include/functions_netflow.php"); function reporting_html_header(&$table, $mini, $title, $subtitle, - $period, $date, $from, $to) { + $period, $date, $from, $to, $label = '') { global $config; @@ -73,7 +73,8 @@ function reporting_html_header(&$table, $mini, $title, $subtitle, $data = array(); if (empty($subtitle) && (empty($date_text))) { - $data[] = $sizh . $title . $sizhfin; + $title = $sizh . $title . $sizhfin; + $data[] = $title; $table->colspan[0][0] = 3; } else if (empty($subtitle)) { @@ -87,7 +88,11 @@ function reporting_html_header(&$table, $mini, $title, $subtitle, $table->colspan[0][1] = 2; } else { - $data[] = $sizh . $title . $sizhfin; + $title = $sizh . $title; + if ($label != '') { + $title .= '
' . __('Label: ') . $label; + } + $data[] = $title . $sizhfin; $data[] = $sizh . $subtitle . $sizhfin; $data[] = "
" . $sizh . $date_text . $sizhfin . "
"; } @@ -111,14 +116,19 @@ function reporting_html_print_report($report, $mini = false) { $table->colspan = array (); $table->rowstyle = array (); - + if (isset($item['label']) && $item['label'] != '') { + $label = reporting_label_macro($item, $item['label']); + } + else + $label = ''; reporting_html_header($table, $mini, $item['title'], $item['subtitle'], $item['date']['period'], $item['date']['date'], $item['date']['from'], - $item['date']['to']); + $item['date']['to'], + $label); if ($item["description"] != "") { $table->data['description_row']['description'] = $item["description"]; diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 703f309a1a..7724607f76 100644 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -265,7 +265,8 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color, $vconsole, $agent_module_id, $font, - $font_size); + $font_size, + $xaxisname); } else { $graph = array(); diff --git a/pandora_console/include/graphs/flot/jquery.flot.axislabels.js b/pandora_console/include/graphs/flot/jquery.flot.axislabels.js new file mode 100755 index 0000000000..a89dddc2a8 --- /dev/null +++ b/pandora_console/include/graphs/flot/jquery.flot.axislabels.js @@ -0,0 +1,137 @@ +/* +CAxis Labels Plugin for flot. :P +Copyright (c) 2010 Xuan Luo +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +(function ($) { + var options = { }; + + function init(plot) { + // This is kind of a hack. There are no hooks in Flot between + // the creation and measuring of the ticks (setTicks, measureTickLabels + // in setupGrid() ) and the drawing of the ticks and plot box + // (insertAxisLabels in setupGrid() ). + // + // Therefore, we use a trick where we run the draw routine twice: + // the first time to get the tick measurements, so that we can change + // them, and then have it draw it again. + var secondPass = false; + plot.hooks.draw.push(function (plot, ctx) { + if (!secondPass) { + // MEASURE AND SET OPTIONS + $.each(plot.getAxes(), function(axisName, axis) { + var opts = axis.options // Flot 0.7 + || plot.getOptions()[axisName]; // Flot 0.6 + if (!opts || !opts.axisLabel) + return; + + var w, h; + if (opts.axisLabelUseCanvas != false) + opts.axisLabelUseCanvas = true; + + if (opts.axisLabelUseCanvas) { + // canvas text + if (!opts.axisLabelFontSizePixels) + opts.axisLabelFontSizePixels = 14; + if (!opts.axisLabelFontFamily) + opts.axisLabelFontFamily = 'sans-serif'; + // since we currently always display x as horiz. + // and y as vertical, we only care about the height + w = opts.axisLabelFontSizePixels; + h = opts.axisLabelFontSizePixels; + + } else { + // HTML text + var elem = $('
' + opts.axisLabel + '
'); + plot.getPlaceholder().append(elem); + w = elem.outerWidth(true); + h = elem.outerHeight(true); + elem.remove(); + } + + if (axisName.charAt(0) == 'x') + axis.labelHeight += h; + else + axis.labelWidth += w; + opts.labelHeight = axis.labelHeight; + opts.labelWidth = axis.labelWidth; + }); + // re-draw with new label widths and heights + secondPass = true; + plot.setupGrid(); + plot.draw(); + + + } else { + // DRAW + $.each(plot.getAxes(), function(axisName, axis) { + var opts = axis.options // Flot 0.7 + || plot.getOptions()[axisName]; // Flot 0.6 + if (!opts || !opts.axisLabel) + return; + + if (opts.axisLabelUseCanvas) { + // canvas text + var ctx = plot.getCanvas().getContext('2d'); + ctx.save(); + ctx.font = opts.axisLabelFontSizePixels + 'px ' + + opts.axisLabelFontFamily; + var width = ctx.measureText(opts.axisLabel).width; + var height = opts.axisLabelFontSizePixels; + var x, y; + if (axisName.charAt(0) == 'x') { + x = plot.getPlotOffset().left + plot.width()/2 - width/2; + y = plot.getCanvas().height; + } else { + x = height * 0.72; + y = plot.getPlotOffset().top + plot.height()/2 - width/2; + } + ctx.translate(x, y); + ctx.rotate((axisName.charAt(0) == 'x') ? 0 : -Math.PI/2); + ctx.fillText(opts.axisLabel, 0, 0); + ctx.restore(); + + } else { + // HTML text + plot.getPlaceholder().find('#' + axisName + 'Label').remove(); + var elem = $('
' + opts.axisLabel + '
'); + if (axisName.charAt(0) == 'x') { + //~ elem.css('left', plot.getPlotOffset().left + plot.width()/4 - elem.outerWidth()/2 + 'px'); + elem.css('bottom', '0px'); + elem.css('width', '100%'); + } else { + elem.css('top', plot.getPlotOffset().top + plot.height()/2 - elem.outerHeight()/2 + 'px'); + elem.css('left', '0px'); + } + plot.getPlaceholder().append(elem); + } + }); + secondPass = false; + } + }); + } + + + + $.plot.plugins.push({ + init: init, + options: options, + name: 'axisLabels', + version: '1.0' + }); +})(jQuery); \ No newline at end of file diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 7cf3fbc779..748e6119f6 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -829,7 +829,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, alert_ids, legend_alerts, yellow_threshold, red_threshold, force_integer, separator, separator2, yellow_up, red_up, yellow_inverse, red_inverse, - series_suffix_str, dashboard, vconsole) { + series_suffix_str, dashboard, vconsole, xaxisname) { var threshold = true; var thresholded = false; @@ -1510,6 +1510,9 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, markings: markings }, xaxes: [ { + axisLabelFontSizePixels: font_size, + axisLabelUseCanvas: false, + axisLabel: xaxisname, tickFormatter: xFormatter, minTickSize: steps, color: '#000' diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 050185f4e4..a37536d795 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -51,6 +51,8 @@ function include_javascript_dependencies_flot_graph($return = false) { + '; $output .= " "; @@ -757,7 +760,7 @@ function flot_vcolumn_chart ($graph_data, $width, $height, $color, $legend, $lon return $return; } -function flot_slicesbar_graph ($graph_data, $period, $width, $height, $legend, $colors, $fontpath, $round_corner, $homeurl, $watermark = '', $adapt_key = '', $stat_win = false) { +function flot_slicesbar_graph ($graph_data, $period, $width, $height, $legend, $colors, $fontpath, $round_corner, $homeurl, $watermark = '', $adapt_key = '', $stat_win = false, $id_agent = 0) { global $config; include_javascript_dependencies_flot_graph(); @@ -877,7 +880,7 @@ function flot_slicesbar_graph ($graph_data, $period, $width, $height, $legend, $ // Javascript code $return .= ""; diff --git a/pandora_console/include/help/en/help_reports_label_field.php b/pandora_console/include/help/en/help_reports_label_field.php new file mode 100755 index 0000000000..b9a553af85 --- /dev/null +++ b/pandora_console/include/help/en/help_reports_label_field.php @@ -0,0 +1,25 @@ + +

Reports - Label field macros

+

+ +The following macros are also available:
+