Added js image

This commit is contained in:
Arturo Gonzalez 2017-07-13 12:26:13 +02:00
parent 63d07e1416
commit 19caa3ebfb
3 changed files with 64 additions and 58 deletions

View File

@ -1795,14 +1795,46 @@ function setPercentileBar(id_data, values) {
}
function setEventsBar(id_data, values) {
metaconsole = $("input[name='metaconsole']").val();
var url_hack_metaconsole = '';
if (is_metaconsole()) {
url_hack_metaconsole = '../../';
}
$("#image_" + id_data).attr('src', data);
parameter = Array();
parameter.push ({name: "page", value: "include/ajax/visual_console_builder.ajax"});
parameter.push ({name: "action", value: "get_module_events"});
parameter.push ({name: "id_agent", value: values['id_agent']});
parameter.push ({name: "id_agent_module", value: values['module']});
if (is_metaconsole()) {
parameter.push ({name: "id_metaconsole", value: id_metaconsole});
}
parameter.push ({name: "period", value: values['event_max_time_row']});
parameter.push ({name: "id_visual_console", value: id_visual_console});
jQuery.ajax({
url: get_url_ajax(),
data: parameter,
type: "POST",
dataType: 'json',
success: function (data) {
console.log(data);
if (data['no_data'] == true) {
$("#" + id_data + " img").attr('src', url_hack_metaconsole + 'images/console/signes/module_graph.png');
}
else {
$("#" + id_data + " img").attr('src', url_hack_metaconsole + 'images/console/signes/module_graph.png');
if($('#text-width').val() == 0 || $('#text-height').val() == 0){
$("#" + id_data + " img").css('width', '300px');
$("#" + id_data + " img").css('height', '180px');
}
else{
$("#" + id_data + " img").css('width', $('#text-width').val()+'px');
$("#" + id_data + " img").css('height', $('#text-height').val()+'px');
}
}
}
});
}
function setPercentileBubble(id_data, values) {
@ -2123,7 +2155,7 @@ function createItem(type, values, id_data) {
item = $('<div id="' + id_data + '" class="item" style="text-align: left; position: absolute; display: inline-block; ' + sizeStyle + ' top: ' + values['top'] + 'px; left: ' + values['left'] + 'px;">' +
'<table><tr><td></td></tr><tr><td><span id="text_' + id_data + '" class="text">' + values['label'] + '</span></td></tr><tr><td></td></tr></table>' +
'<img class="image" id="image_' + id_data + '" src="images/spinner.gif" />' +
'</div>'
'</div>'
);
setEventsBar(id_data, values);

View File

@ -143,66 +143,36 @@ switch ($action) {
case 'get_module_events':
$data = array ();
$resolution = $config['graph_res'] * ($event_max_time_row * 2 / 450); // Number of "slices" we want in graph
$interval = (int) ($event_max_time_row / $resolution);
$date = get_system_time ();
$datelimit = $date - $event_max_time_row;
$periodtime = floor ($event_max_time_row / $interval);
$time = array ();
$data = array ();
$legend = array();
$full_legend = array();
$cont = 0;
for ($i = 0; $i < $interval; $i++) {
$bottom = $datelimit + ($periodtime * $i);
$name = date('H:i', $bottom);
// Show less values in legend
if ($cont == 0 or $cont % 2)
$legend[$cont] = $name;
$full_legend[$cont] = $name;
$top = $datelimit + ($periodtime * ($i + 1));
$event = db_get_row_filter ('tevento',
array ('id_agente' => $id_agent,
'id_agentmodule' => $id_module,
'utimestamp > '.$bottom,
'utimestamp < '.$top), 'criticity, utimestamp');
if (!empty($event['utimestamp'])) {
$data[$cont]['utimestamp'] = $periodtime;
switch ($event['criticity']) {
case EVENT_CRIT_WARNING:
$data[$cont]['data'] = 2;
break;
case EVENT_CRIT_CRITICAL:
$data[$cont]['data'] = 3;
break;
default:
$data[$cont]['data'] = 1;
break;
$events = db_get_row_filter ('tevento',
array ('id_agente' => $id_agent,
'id_agentmodule' => $id_module,
'utimestamp > ' . $datelimit,
'utimestamp < ' . $date), 'criticity, utimestamp');
html_debug($events, true);
$return = array();
if (!$events) {
$return['no_data'] = true;
if (!empty($id_metaconsole)) {
$connection = db_get_row_filter ('tmetaconsole_setup',
$id_metaconsole);
if (metaconsole_load_external_db($connection) != NOERR) {
continue;
}
}
else {
$data[$cont]['utimestamp'] = $periodtime;
$data[$cont]['data'] = 1;
$return['url'] = true;
if (!empty($id_metaconsole)) {
metaconsole_restore_db();
}
$cont++;
}
else {
$return['no_data'] = false;
}
$colors = array(1 => COL_NORMAL, 2 => COL_WARNING, 3 => COL_CRITICAL, 4 => COL_UNKNOWN);
$out = flot_slicesbar_graph($data, $period, 450, 15, $full_legend, $colors, $config['fontpath'], $config['round_corner'], $homeurl, '', '', false, $id_agent);
html_debug($out, true);
if (!$out) {
$out = array();
}
echo json_encode($out);
echo json_encode($return);
break;
case 'get_image_sparse':
@ -935,6 +905,8 @@ switch ($action) {
case 'auto_sla_graph':
$values['type'] = AUTO_SLA_GRAPH;
$values['period'] = $event_max_time_row;
$values['width'] = $width;
$values['height'] = $height;
break;
case 'percentile_item':
case 'percentile_bar':

View File

@ -510,7 +510,8 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) {
$form_items_advance['position_row'] = array();
$form_items_advance['position_row']['items'] = array('static_graph',
'percentile_bar', 'percentile_item', 'module_graph',
'simple_value', 'label', 'icon', 'datos', 'box_item');
'simple_value', 'label', 'icon', 'datos', 'box_item',
'auto_sla_graph');
$form_items_advance['position_row']['html'] = '
<td align="left">' . __('Position') . '</td>
<td align="left">(' . html_print_input_text('left', '0', '', 3, 5, true) .
@ -521,7 +522,8 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) {
$form_items_advance['size_row'] = array();
$form_items_advance['size_row']['items'] = array(
'group_item', 'background',
'static_graph', 'icon datos');
'static_graph', 'icon datos',
'auto_sla_graph');
$form_items_advance['size_row']['html'] = '<td align="left">' .
__('Size') .
ui_print_help_tip (