From 0dd0ae4b4c132e7aac0b3249f77479ef7a6551a5 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Diaz Date: Wed, 30 Sep 2015 10:52:12 +0200 Subject: [PATCH] Fixed module graph problems in visual console. Ticket#2825 --- .../visual_console_builder.editor.js | 21 ++++++++++++------- .../ajax/visual_console_builder.ajax.php | 21 ++++++++++++++----- .../include/functions_visual_map.php | 5 +++-- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/pandora_console/godmode/reporting/visual_console_builder.editor.js b/pandora_console/godmode/reporting/visual_console_builder.editor.js index 57150bfe24..7bc9c91963 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.editor.js +++ b/pandora_console/godmode/reporting/visual_console_builder.editor.js @@ -1221,14 +1221,12 @@ function set_image(type, idElement, image) { function setModuleGraph(id_data) { var parameter = Array(); - - parameter.push ({name: "page", - value: "include/ajax/visual_console_builder.ajax"}); + + parameter.push ({name: "page", value: "include/ajax/visual_console_builder.ajax"}); parameter.push ({name: "action", value: "get_layout_data"}); parameter.push ({name: "id_element", value: id_data}); - parameter.push ({name: "id_visual_console", - value: id_visual_console}); - + parameter.push ({name: "id_visual_console", value: id_visual_console}); + jQuery.ajax({ url: get_url_ajax(), data: parameter, @@ -1258,6 +1256,7 @@ function setModuleGraph(id_data) { if (is_metaconsole()) { parameter.push ({name: "id_metaconsole", value: id_metaconsole}); } + parameter.push ({name: "type", value: 'module_graph'}); parameter.push ({name: "height", value: height}); parameter.push ({name: "width", value: width}); parameter.push ({name: "period", value: period}); @@ -1268,10 +1267,16 @@ function setModuleGraph(id_data) { url: get_url_ajax(), data: parameter, type: "POST", - dataType: 'text', //The ajax return the data as text. + dataType: 'json', //The ajax return the data as text. success: function (data) { - $("#image_" + id_data).attr('src', data); + console.log(data); + if (data['no_data'] == true) { + $('#' + id_data).html(data['url']); + } + else { + $("#image_" + id_data).attr('src', data['url']); + } } }); } diff --git a/pandora_console/include/ajax/visual_console_builder.ajax.php b/pandora_console/include/ajax/visual_console_builder.ajax.php index 36b1211d70..e051e964b0 100755 --- a/pandora_console/include/ajax/visual_console_builder.ajax.php +++ b/pandora_console/include/ajax/visual_console_builder.ajax.php @@ -158,8 +158,8 @@ switch ($action) { } else { $img = grafico_modulo_sparse($id_agent_module, - $period, false, $width, $height, '', null, false, 1, - false, 0, '', 0, 0, true, true, '', 1, false, '', + $period, 0, $width, $height, '', null, false, 1, + false, 0, '', 0, 0, true, true, '', 1, false, '', false, false, true, $background_color); } @@ -167,11 +167,22 @@ switch ($action) { if (!empty($id_metaconsole)) { metaconsole_restore_db(); } - + + $data_image = array(); preg_match("/src=[\'\"](.*)[\'\"]/", $img, $matches); $url = $matches[1]; - - echo $url; + + if (empty($url) && ($type == 'module_graph')) { + $data_image['url'] = $img; + $data_image['no_data'] = true; + $data_image['message'] = __('No data to show'); + } + else{ + $data_image['url'] = $matches[1]; + $data_image['no_data'] = false; + } + + echo json_encode($data_image); break; diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php index 31beffc2f6..5e4d8a30d6 100755 --- a/pandora_console/include/functions_visual_map.php +++ b/pandora_console/include/functions_visual_map.php @@ -733,8 +733,9 @@ function visual_map_print_item($mode = "read", $layoutData, if ($layoutData['id_metaconsole'] != 0) { metaconsole_restore_db(); } - - $img = str_replace('>', 'class="image" id="image_' . $id . '" />', $img); + + //$img = str_replace('>', 'class="image" id="image_' . $id . '" />', $img); + break; case LABEL: $z_index = 4 + 1;