Add show_statistics option for group item - #1245

This commit is contained in:
enriquecd 2017-08-31 15:09:04 +02:00
parent a99b75da4c
commit f6c6e2a6ba
6 changed files with 283 additions and 76 deletions

View File

@ -303,34 +303,64 @@ function update_button_palette_callback() {
alert('Undefined height');
return false;
}
$("#text_" + idItem).html(values['label']);
if ((values['width'] == 0) || (values['height'] == 0)) {
if($('#preview > img')[0].naturalWidth > 150 || $('#preview > img')[0].naturalHeight > 150){
$("#image_" + idItem).removeAttr('width');
$("#image_" + idItem).removeAttr('height');
$("#image_" + idItem).attr('width', 70);
$("#image_" + idItem).attr('height', 70);
$("#image_" + idItem).css('width', '70px');
$("#image_" + idItem).css('height', '70px');
if(values['show_statistics'] == 1){
if ((values['width'] == 0) || (values['height'] == 0)) {
$("#image_" + idItem).removeAttr('width');
$("#image_" + idItem).removeAttr('height');
$("#image_" + idItem).attr('width', 450);
$("#image_" + idItem).attr('height', 80);
$("#image_" + idItem).css('width', '450px');
$("#image_" + idItem).css('height', '80px');
$("#image_" + idItem).attr('src', 'images/console/signes/group_status.png');
}
else{
else {
$("#image_" + idItem).removeAttr('width');
$("#image_" + idItem).removeAttr('height');
$("#image_" + idItem).attr('width', $('#preview > img')[0].naturalHeight);
$("#image_" + idItem).attr('height', $('#preview > img')[0].naturalHeight);
$("#image_" + idItem).css('width', $('#preview > img')[0].naturalHeight+'px');
$("#image_" + idItem).css('height', $('#preview > img')[0].naturalHeight+'px');
}
$("#image_" + idItem).attr('width', values['width']);
$("#image_" + idItem).attr('height', values['height']);
$("#image_" + idItem).css('width', values['width'] + 'px');
$("#image_" + idItem).css('height', values['height'] + 'px');
$("#image_" + idItem).attr('src', 'images/console/signes/group_status.png');
}
}
else {
$("#image_" + idItem).removeAttr('width');
$("#image_" + idItem).removeAttr('height');
$("#image_" + idItem).attr('width', values['width']);
$("#image_" + idItem).attr('height', values['height']);
$("#image_" + idItem).css('width', values['width'] + 'px');
$("#image_" + idItem).css('height', values['height'] + 'px');
else{
if ((values['width'] == 0) || (values['height'] == 0)) {
if($('#preview > img')[0].naturalWidth > 150 || $('#preview > img')[0].naturalHeight > 150){
$("#image_" + idItem).removeAttr('width');
$("#image_" + idItem).removeAttr('height');
$("#image_" + idItem).attr('width', 70);
$("#image_" + idItem).attr('height', 70);
$("#image_" + idItem).css('width', '70px');
$("#image_" + idItem).css('height', '70px');
}
else{
$("#image_" + idItem).removeAttr('width');
$("#image_" + idItem).removeAttr('height');
$("#image_" + idItem).attr('width', $('#preview > img')[0].naturalHeight);
$("#image_" + idItem).attr('height', $('#preview > img')[0].naturalHeight);
$("#image_" + idItem).css('width', $('#preview > img')[0].naturalHeight+'px');
$("#image_" + idItem).css('height', $('#preview > img')[0].naturalHeight+'px');
}
}
else {
$("#image_" + idItem).removeAttr('width');
$("#image_" + idItem).removeAttr('height');
$("#image_" + idItem).attr('width', values['width']);
$("#image_" + idItem).attr('height', values['height']);
$("#image_" + idItem).css('width', values['width'] + 'px');
$("#image_" + idItem).css('height', values['height'] + 'px');
}
}
break;
case 'percentile_bar':
case 'percentile_item':
@ -613,6 +643,7 @@ function readFields() {
$("input[name='line_width']").val());
values['line_color'] = $("input[name='line_color']").val();
values['label_position'] = $(".labelpos[sel=yes]").attr('position');
values['show_statistics'] = $("input[name=show_statistics]").is(':checked') ? 1 : 0;
if (is_metaconsole()) {
values['metaconsole'] = 1;
@ -1140,6 +1171,17 @@ function loadFieldsFromDB(item) {
}
}
if (key == 'show_statistics') {
if (val == "1") {
$("input[name=show_statistics]")
.prop("checked", true);
}
else {
$("input[name=show_statistics]")
.prop("checked", false);
}
}
if (key == 'type_graph') {
$("select[name=type_graph]").val(val);
}
@ -1427,6 +1469,9 @@ function hiddenFields(item) {
$("#enable_link_row").css('display', 'none');
$("#enable_link_row." + item).css('display', '');
$("#show_statistics_row").css('display', 'none');
$("#show_statistics_row." + item).css('display', '');
$("#preview_row").css('display', 'none');
$("#preview_row." + item).css('display', '');
@ -1621,11 +1666,13 @@ function set_static_graph_status(idElement, image, status) {
data: parameter,
success: function (data) {
set_static_graph_status(idElement, image, data);
if($('#'+idElement+' table').css('float') == 'right' || $('#'+idElement+ ' table').css('float') == 'left'){
$('#'+idElement+ ' img').css('margin-top', parseInt($('#'+idElement).css('height'))/2 - parseInt($('#'+idElement+ ' img').css('height'))/2);
}
else{
$('#'+idElement+ ' img').css('margin-left', parseInt($('#'+idElement).css('width'))/2 - parseInt($('#'+idElement+ ' img').css('width'))/2);
if(values['show_statistics'] == 1){
if($('#'+idElement+' table').css('float') == 'right' || $('#'+idElement+ ' table').css('float') == 'left'){
$('#'+idElement+ ' img').css('margin-top', parseInt($('#'+idElement).css('height'))/2 - parseInt($('#'+idElement+ ' img').css('height'))/2);
}
else{
$('#'+idElement+ ' img').css('margin-left', parseInt($('#'+idElement).css('width'))/2 - parseInt($('#'+idElement+ ' img').css('width'))/2);
}
}
}
});
@ -1660,15 +1707,25 @@ function set_static_graph_status(idElement, image, status) {
}
function set_image(type, idElement, image) {
if (type == "image") {
if(image == 'show_statistics_bad.png' || image == 'show_statistics_ok.png' || image == 'show_statistics_warning.png' || image == 'show_statistics.png'){
item = "#image_" + idElement;
img_src = "images/console/icons/" + image;
img_src = "images/console/signes/group_status.png";
}
else if (type == "background") {
item = "#background_img";
img_src = "images/console/background/" + image;
else{
if (type == "image") {
item = "#image_" + idElement;
img_src = "images/console/icons/" + image;
}
else if (type == "background") {
item = "#background_img";
img_src = "images/console/background/" + image;
}
}
var params = [];
params.push("get_image_path=1");
params.push("img_src=" + img_src);
@ -1682,6 +1739,12 @@ function set_image(type, idElement, image) {
url: get_url_ajax(),
success: function (data) {
$(item).attr('src', data);
if(image == 'show_statistics_bad.png' || image == 'show_statistics_ok.png' || image == 'show_statistics_warning.png' || image == 'show_statistics.png'){
$(item).attr('width', 450);
$(item).attr('height', 80);
}
}
});
}
@ -2173,21 +2236,28 @@ function createItem(type, values, id_data) {
}
if ((values['width'] == 0) || (values['height'] == 0)) {
// Do none
if($('#preview > img')[0].naturalWidth > 150 || $('#preview > img')[0].naturalHeight > 150){
$image.attr('width', '70')
.attr('height', '70');
if(values['show_statistics'] != 1){
if ((values['width'] == 0) || (values['height'] == 0)) {
// Do none
if($('#preview > img')[0].naturalWidth > 150 || $('#preview > img')[0].naturalHeight > 150){
$image.attr('width', '70')
.attr('height', '70');
}
else{
$image.attr('width', $('#preview > img')[0].naturalWidth)
.attr('height', $('#preview > img')[0].naturalHeight);
}
}
else {
$image.attr('width', values['width'])
.attr('height', values['height']);
}
}
else{
$image.attr('width', $('#preview > img')[0].naturalWidth)
.attr('height', $('#preview > img')[0].naturalHeight);
}
}
else {
$image.attr('width', values['width'])
.attr('height', values['height']);
}
// else{
// $('#image_'+id_data).css('width', values['width']+'px');
// $('#image_'+id_data).css('height', values['height']+'px');
// }
/*
var $span = $('<span></span>')
.attr('id', 'text_' + id_data)
@ -2245,8 +2315,32 @@ function createItem(type, values, id_data) {
.append($image)
.append($input);
}
set_static_graph_status(id_data, values['image']);
if(values['show_statistics'] != 1){
set_static_graph_status(id_data, values['image']);
}
else{
set_static_graph_status(id_data, 'show_statistics');
}
if(values['show_statistics'] != 1){
if ((values['width'] == 0) || (values['height'] == 0)) {
// Do none
if($('#preview > img')[0].naturalWidth > 150 || $('#preview > img')[0].naturalHeight > 150){
$image.attr('width', '70')
.attr('height', '70');
}
else{
$image.attr('width', $('#preview > img')[0].naturalWidth)
.attr('height', $('#preview > img')[0].naturalHeight);
}
}
else {
$image.attr('width', values['width'])
.attr('height', values['height']);
}
}
break;
case 'auto_sla_graph':
@ -2580,9 +2674,9 @@ function updateDB_visual(type, idElement , values, event, top, left) {
case 'static_graph':
if ((event != 'resizestop') && (event != 'show_grid')
&& (event != 'dragstop')) {
set_static_graph_status(idElement, values['image']);
if(values['show_statistics'] != 1){
set_static_graph_status(idElement, values['image']);
}
}
break;
case 'percentile_item':
@ -2811,6 +2905,9 @@ function updateDB(type, idElement , values, event) {
}
function copyDB(idItem) {
console.log(idItem);
metaconsole = $("input[name='metaconsole']").val();
parameter = Array();

View File

@ -357,6 +357,7 @@ switch ($activeTab) {
break;
case GROUP_ITEM:
$values['id_group'] = get_parameter('group_' . $id, 0);
$values['show_statistics'] = get_parameter('show_statistics', 0);
break;
}
$agentName = get_parameter('agent_' . $id, '');
@ -410,6 +411,7 @@ switch ($activeTab) {
$width = (int) get_parameter ("width", 0);
$height = (int) get_parameter ("height", 0);
$period = (int) get_parameter ("period", 0);
$show_statistics = get_parameter ("show_statistics", 0);
$process_value = (int) get_parameter ("process_value", 0);
$percentileitem_width = (int) get_parameter ("percentileitem_width", 0);
$max_value = (int) get_parameter ("max_value", 0);

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@ -132,6 +132,7 @@ $get_element_status = get_parameter('get_element_status', 0);
$enable_link = get_parameter('enable_link', 1);
$type_graph = get_parameter('type_graph', 'area');
$label_position = get_parameter('label_position', 'down');
$show_statistics = get_parameter('show_statistics', 0);
switch ($action) {
case 'get_font':
@ -569,6 +570,9 @@ switch ($action) {
if ($height !== null) {
$values['height'] = $height;
}
if ($show_statistics !== null) {
$values['show_statistics'] = $show_statistics;
}
break;
case 'module_graph':
if ($height_module_graph !== null) {
@ -640,6 +644,7 @@ switch ($action) {
switch ($type) {
case 'group_item':
unset($values['id_group']);
unset($values['show_statistics']);
break;
case 'module_graph':
unset($values['image']);
@ -948,6 +953,7 @@ switch ($action) {
$values['width'] = $width;
$values['height'] = $height;
$values['id_group'] = $id_group;
$values['show_statistics'] = $show_statistics;
breaK;
case 'simple_value':
//This allows min, max and avg process in a simple value

View File

@ -1274,35 +1274,130 @@ function visual_map_print_item($mode = "read", $layoutData,
$varsize = getimagesize($img);
if ($width == 0 || $height == 0) {
if($varsize[0] > 150 || $varsize[1] > 150){
echo html_print_image($img, true,
array("class" => "image",
"id" => "image_" . $id,
"width" => "70px",
"height" => "70px",
"title" => $img_style_title,
"style" => $borderStyle.$imgpos), false,
false, false, $isExternalLink);
if($layoutData['show_statistics'] == 1){
if (get_parameter('action') == 'edit') {
if ($width == 0 || $height == 0) {
echo '<img id="image_'.$id.'" src="images/console/signes/group_status.png" style="width:450px;height:80px;'.$imgpos.'">';
}
else{
echo '<img id="image_'.$id.'" src="images/console/signes/group_status.png" style="width:'.$width.'px;height:'.$height.'px;'.$imgpos.'">';
}
}
else{
echo html_print_image($img, true,
array("class" => "image",
"id" => "image_" . $id,
"title" => $img_style_title,
"style" => $borderStyle.$imgpos), false,
false, false, $isExternalLink);
$agents_critical = agents_get_agents(array (
'disabled' => 0,
'id_grupo' => $layoutData['id_group'],
'status' => AGENT_STATUS_CRITICAL),
array ('COUNT(*) as total'), 'AR', false);
$agents_warning = agents_get_agents(array (
'disabled' => 0,
'id_grupo' => $layoutData['id_group'],
'status' => AGENT_STATUS_WARNING),
array ('COUNT(*) as total'), 'AR', false);
$agents_unknown = agents_get_agents(array (
'disabled' => 0,
'id_grupo' => $layoutData['id_group'],
'status' => AGENT_STATUS_UNKNOWN),
array ('COUNT(*) as total'), 'AR', false);
$agents_ok = agents_get_agents(array (
'disabled' => 0,
'id_grupo' => $layoutData['id_group'],
'status' => AGENT_STATUS_OK),
array ('COUNT(*) as total'), 'AR', false);
$total_agents = $agents_critical[0]['total'] + $agents_warning[0]['total'] + $agents_unknown[0]['total'] + $agents_ok[0]['total'];
$stat_agent_ok = $agents_ok[0]['total']/$total_agents*100;
$stat_agent_wa = $agents_warning[0]['total']/$total_agents*100;
$stat_agent_cr = $agents_critical[0]['total']/$total_agents*100;
$stat_agent_un = $agents_unknown[0]['total']/$total_agents*100;
if($width == 0 || $height == 0){
$dyn_width = 450;
$dyn_height = 80;
}
else{
$dyn_width = $width;
$dyn_height = $height;
}
echo '<table cellpadding="0" cellspacing="0" border="0" class="databox" style="width:'.$dyn_width.'px;height:'.$dyn_height.'px;text-align:center;';
if($layoutData['label_position'] == 'left'){
echo "float:right;";
}
elseif ($layoutData['label_position'] == 'right') {
echo "float:left;";
}
echo '">';
echo "<tr style='height:10%;'>";
echo "<th style='text-align:center;background-color:#9d9ea0;color:black;font-weight:bold;'>" .groups_get_name($layoutData['id_group'],true) . "</th>";
echo "</tr>";
echo "<tr style='background-color:whitesmoke;height:90%;'>";
echo "<td>";
echo "<div style='margin-left:2%;color: #FFF;font-size: 15px;display:inline;background-color:#FC4444;position:relative;height:80%;width:9.4%;height:80%;border-radius:2px;text-align:center;padding:5px;'>". remove_right_zeros(number_format($stat_agent_cr, 2)) ."%</div>";
echo "<div style='background-color:white;color: black ;font-size: 15px;display:inline;position:relative;height:80%;width:9.4%;height:80%;border-radius:2px;text-align:center;padding:5px;'>Critical</div>";
echo "<div style='margin-left:2%;color: #FFF;font-size: 15px;display:inline;background-color:#f8db3f;position:relative;height:80%;width:9.4%;height:80%;border-radius:2px;text-align:center;padding:5px;'>". remove_right_zeros(number_format($stat_agent_wa, 2)) ."%</div>";
echo "<div style='background-color:white;color: black ;font-size: 15px;display:inline;position:relative;height:80%;width:9.4%;height:80%;border-radius:2px;text-align:center;padding:5px;'>Warning</div>";
echo "<div style='margin-left:2%;color: #FFF;font-size: 15px;display:inline;background-color:#84b83c;position:relative;height:80%;width:9.4%;height:80%;border-radius:2px;text-align:center;padding:5px;'>". remove_right_zeros(number_format($stat_agent_ok, 2)) ."%</div>";
echo "<div style='background-color:white;color: black ;font-size: 15px;display:inline;position:relative;height:80%;width:9.4%;height:80%;border-radius:2px;text-align:center;padding:5px;'>Normal</div>";
echo "<div style='margin-left:2%;color: #FFF;font-size: 15px;display:inline;background-color:#9d9ea0;position:relative;height:80%;width:9.4%;height:80%;border-radius:2px;text-align:center;padding:5px;'>". remove_right_zeros(number_format($stat_agent_un, 2)) ."%</div>";
echo "<div style='background-color:white;color: black ;font-size: 15px;display:inline;position:relative;height:80%;width:9.4%;height:80%;border-radius:2px;text-align:center;padding:5px;'>Unknown</div>";
echo "</td>";
echo "</tr>";
echo "</table>";
}
}
else{
echo html_print_image($img, true,
array("class" => "image",
"id" => "image_" . $id,
"width" => $width,
"height" => $height,
"title" => $img_style_title,
"style" => $borderStyle.$imgpos), false,
false, false, $isExternalLink);
if ($width == 0 || $height == 0) {
if($varsize[0] > 150 || $varsize[1] > 150){
echo html_print_image($img, true,
array("class" => "image",
"id" => "image_" . $id,
"width" => "70px",
"height" => "70px",
"title" => $img_style_title,
"style" => $borderStyle.$imgpos), false,
false, false, $isExternalLink);
}
else{
echo html_print_image($img, true,
array("class" => "image",
"id" => "image_" . $id,
"title" => $img_style_title,
"style" => $borderStyle.$imgpos), false,
false, false, $isExternalLink);
}
}
else{
echo html_print_image($img, true,
array("class" => "image",
"id" => "image_" . $id,
"width" => $width,
"height" => $height,
"title" => $img_style_title,
"style" => $borderStyle.$imgpos), false,
false, false, $isExternalLink);
}
}
}

View File

@ -453,6 +453,13 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) {
$form_items['period_row']['html'] = '<td align="left">' . __('Period') . '</td>
<td align="left">' . html_print_extended_select_for_time ('period', SECONDS_5MINUTES, '', '', '', false, true) . '</td>';
$form_items['show_statistics_row'] = array();
$form_items['show_statistics_row']['items'] = array('group_item');
$form_items['show_statistics_row']['html'] =
'<td align="left" style="">' . __('Show statistics') . '</td>
<td align="left" style="">' .
html_print_checkbox('show_statistics', 1, '', true) . '</td>';
$form_items['module_graph_size_row'] = array();
$form_items['module_graph_size_row']['items'] = array('module_graph', 'datos');