From f0fe30fc3a810f219be49f4e01e2f484bcdc807b Mon Sep 17 00:00:00 2001 From: enriquecd Date: Thu, 2 Nov 2017 15:54:18 +0100 Subject: [PATCH] Now can create static graphs a group items without images, fix bugs - #1407 --- .../visual_console_builder.editor.js | 589 +++++++++++++++++- .../include/functions_visual_map.php | 13 +- .../include/functions_visual_map_editor.php | 2 +- 3 files changed, 563 insertions(+), 41 deletions(-) diff --git a/pandora_console/godmode/reporting/visual_console_builder.editor.js b/pandora_console/godmode/reporting/visual_console_builder.editor.js index dbac5adb4b..f833898c64 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.editor.js +++ b/pandora_console/godmode/reporting/visual_console_builder.editor.js @@ -289,6 +289,157 @@ function update_button_palette_callback() { } break; case 'group_item': + if((values['image'] == '' || values['image'] == 'none') && (values['label'] == '') && (values['show_statistics'] == false)){ + alert('Undefined image'); + return false; + } + + $("#text_" + idItem).html(values['label']); + + if(values['show_statistics'] == 1){ + + if (!$('#image_'+idItem).length) { + + if(values['label_position'] == 'left'){ + + var $image = $('') + .attr('id', 'image_' + idItem) + .attr('class', 'image') + .attr('src', 'images/console/icons/'+values["image"]+".png") + .attr('style','float:right;'); + + } + else if(values['label_position'] == 'right'){ + + var $image = $('') + .attr('id', 'image_' + idItem) + .attr('class', 'image') + .attr('src', 'images/console/icons/'+values["image"]+".png") + .attr('style','float:left;'); + + } + else{ + + var $image = $('') + .attr('id', 'image_' + idItem) + .attr('class', 'image') + .attr('src', 'images/console/icons/'+values["image"]+".png"); + + } + + + $('#'+idItem).append($image); + + } + + if ((values['width'] == 0) || (values['height'] == 0)) { + $("#image_" + idItem).removeAttr('width'); + $("#image_" + idItem).removeAttr('height'); + $("#image_" + idItem).attr('width', 520); + $("#image_" + idItem).attr('height', 80); + $("#image_" + idItem).css('width', '520px'); + $("#image_" + idItem).css('height', '80px'); + $("#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'); + $("#image_" + idItem).attr('src', 'images/console/signes/group_status.png'); + } + + } + else{ + + if ((values['width'] == 0) || (values['height'] == 0)) { + + if(values['image'] != '' && values['image'] != 'none'){ + + if (!$('#image_'+idItem).length) { + + if(values['label_position'] == 'left'){ + + var $image = $('') + .attr('id', 'image_' + idItem) + .attr('class', 'image') + .attr('src', 'images/console/icons/'+values["image"]+".png") + .attr('style','float:right;'); + + } + else if(values['label_position'] == 'right'){ + + var $image = $('') + .attr('id', 'image_' + idItem) + .attr('class', 'image') + .attr('src', 'images/console/icons/'+values["image"]+".png") + .attr('style','float:left;'); + + } + else{ + + var $image = $('') + .attr('id', 'image_' + idItem) + .attr('class', 'image') + .attr('src', 'images/console/icons/'+values["image"]+".png"); + + } + + + $('#'+idItem).append($image); + + } + + + 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', 70); + $("#image_" + idItem).attr('height', 70); + $("#image_" + idItem).css('width', '70px'); + $("#image_" + idItem).css('height', '70px'); + $("#image_" + idItem).remove(); + } + + } + 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 'static_graph': if($('input[name=width]').val() == ''){ @@ -299,7 +450,7 @@ function update_button_palette_callback() { alert('Undefined height'); return false; } - if(((values['image'] == '') && (values['show_statistics']) == false)){ + if(((values['image'] == '' || values['image'] == 'none') && (values['label'] == ''))){ alert('Undefined image'); return false; } @@ -333,22 +484,75 @@ function update_button_palette_callback() { else{ if ((values['width'] == 0) || (values['height'] == 0)) { - if($('#preview > img')[0].naturalWidth > 150 || $('#preview > img')[0].naturalHeight > 150){ + + if(values['image'] != '' && values['image'] != 'none'){ + + if (!$('#image_'+idItem).length) { + + if(values['label_position'] == 'left'){ + + var $image = $('') + .attr('id', 'image_' + idItem) + .attr('class', 'image') + .attr('src', 'images/console/icons/'+values["image"]+".png") + .attr('style','float:right;'); + + } + else if(values['label_position'] == 'right'){ + + var $image = $('') + .attr('id', 'image_' + idItem) + .attr('class', 'image') + .attr('src', 'images/console/icons/'+values["image"]+".png") + .attr('style','float:left;'); + + } + else{ + + var $image = $('') + .attr('id', 'image_' + idItem) + .attr('class', 'image') + .attr('src', 'images/console/icons/'+values["image"]+".png"); + + } + + + $('#'+idItem).append($image); + + } + + + 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', 70); $("#image_" + idItem).attr('height', 70); $("#image_" + idItem).css('width', '70px'); $("#image_" + idItem).css('height', '70px'); + $("#image_" + idItem).remove(); } - 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'); @@ -485,7 +689,7 @@ function update_button_palette_callback() { alert('Undefined height'); return false; } - if(values['image'] == ''){ + if(values['image'] == '' || values['image'] == 'none'){ alert('Undefined image'); return false; } @@ -697,6 +901,11 @@ function create_button_palette_callback() { } break; case 'group_item': + if((values['image'] == '' || values['image'] == 'none') && (values['label'] == '') && (values['show_statistics'] == false)){ + alert('Undefined images'); + validate = false; + } + break; case 'static_graph': if ((values['width'] == '')) { alert('Undefined width'); @@ -706,10 +915,11 @@ function create_button_palette_callback() { alert('Undefined height'); validate = false; } - if((values['image'] == '') && (values['show_statistics']) == false){ + if((values['image'] == '' || values['image'] == 'none') && (values['label']) == false){ alert('Undefined image'); validate = false; } + break; case 'auto_sla_graph': @@ -739,7 +949,7 @@ function create_button_palette_callback() { alert('Undefined height'); validate = false; } - if ((values['image'] == '')) { + if ((values['image'] == '' || values['image'] == 'none')) { alert($("#message_alert_no_image").html()); validate = false; } @@ -2478,6 +2688,262 @@ function createItem(type, values, id_data) { break; case 'group_item': + + switch (type) { + case 'group_item': + class_type = "group_item"; + break; + case 'static_graph': + class_type = "static_graph"; + break; + } + + img_src = "images/spinner.gif"; + + item = $('
') + .attr('id', id_data) + .attr('class', 'item ' + class_type) + .css('text-align', 'left') + .css('position', 'absolute') + .css('display', 'inline-block') + .css('top', values['top'] + 'px') + .css('left', values['left'] + 'px'); + + + + if(values['show_statistics'] != 1){ + if(values['label_position'] == 'left'){ + + var $image = $('') + .attr('id', 'image_' + id_data) + .attr('class', 'image') + .attr('src', 'images/console/signes/group_status.png') + .attr('style','float:right;'); + + } + else if(values['label_position'] == 'right'){ + + var $image = $('') + .attr('id', 'image_' + id_data) + .attr('class', 'image') + .attr('src', 'images/console/signes/group_status.png') + .attr('style','float:left;'); + + } + else{ + + var $image = $('') + .attr('id', 'image_' + id_data) + .attr('class', 'image') + .attr('src', 'images/console/signes/group_status.png'); + + } + } + else{ + if(values['label_position'] == 'left'){ + + var $image = $('') + .attr('id', 'image_' + id_data) + .attr('class', 'image') + .attr('src', img_src) + .attr('style','float:right;'); + + } + else if(values['label_position'] == 'right'){ + + var $image = $('') + .attr('id', 'image_' + id_data) + .attr('class', 'image') + .attr('src', img_src) + .attr('style','float:left;'); + + } + else{ + + var $image = $('') + .attr('id', 'image_' + id_data) + .attr('class', 'image') + .attr('src', img_src); + + } + } + + + + if(values['show_statistics'] != 1){ + + if ((values['width'] == 0) || (values['height'] == 0)) { + // Do none + if(values['image'] != '' && values['image'] != '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', '70') + .attr('height', '70'); + } + + + } + else { + $image.attr('width', values['width']) + .attr('height', values['height']); + } + } + + var $input = $('') + .attr('id', 'hidden-status_' + id_data) + .attr('type', 'hidden') + .attr('value', -1) + .attr('name', 'status_' + id_data); + + if(values['label_position'] == 'up'){ + + if(values['image'] == '' || values['image'] == 'none'){ + item + .append('
'+values['label']+'
') + .append($input); + } + else{ + item + .append('
'+values['label']+'
') + .append($image) + .append($image) + .append($input); + } + + } + else if(values['label_position'] == 'down'){ + + if(values['image'] == '' || values['image'] == 'none'){ + item + .append('
'+values['label']+'
') + .append($input); + + } + else{ + item + .append($image) + .append($image) + .append('
'+values['label']+'
') + .append($input); + } + + } + else if(values['label_position'] == 'left'){ + + if(values['height'] == 0){ + item + .append('
'+values['label']+'
'); + } + else{ + item + .append('
'+values['label']+'
') + } + + if(values['image'] == '' || values['image'] == 'none'){ + item + .append($input); + } + else{ + item + .append($image) + .append($image) + .append($input); + } + + + } + else if(values['label_position'] == 'right'){ + if(values['height'] == 0){ + item + .append('
'+values['label']+'
'); + } + else{ + item + .append('
'+values['label']+'
') + } + + if(values['image'] == '' || values['image'] == 'none'){ + item + .append($input); + } + else{ + item + .append($image) + .append($image) + .append($input); + } + + + + } + + 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)) { + + if(values['image'] != '' && values['image'] != 'none'){ + // 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', '70') + .attr('height', '70'); + } + } + else { + $image.attr('width', values['width']) + .attr('height', values['height']); + } + } + else{ + if ((values['width'] == 0) || (values['height'] == 0)) { + $("#image_" + idItem).removeAttr('width'); + $("#image_" + idItem).removeAttr('height'); + $("#image_" + idItem).attr('width', 520); + $("#image_" + idItem).attr('height', 80); + $("#image_" + idItem).css('width', '520px'); + $("#image_" + idItem).css('height', '80px'); + $("#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'); + $("#image_" + idItem).attr('src', 'images/console/signes/group_status.png'); + } + } + + break; + case 'static_graph': switch (type) { case 'group_item': @@ -2532,6 +2998,8 @@ function createItem(type, values, id_data) { if ((values['width'] == 0) || (values['height'] == 0)) { // Do none + if(values['image'] != '' && values['image'] != 'none'){ + if($('#preview > img')[0].naturalWidth > 150 || $('#preview > img')[0].naturalHeight > 150){ $image.attr('width', '70') .attr('height', '70'); @@ -2539,7 +3007,16 @@ function createItem(type, values, id_data) { else{ $image.attr('width', $('#preview > img')[0].naturalWidth) .attr('height', $('#preview > img')[0].naturalHeight); - } + } + + + } + else{ + $image.attr('width', '70') + .attr('height', '70'); + } + + } else { $image.attr('width', values['width']) @@ -2564,19 +3041,37 @@ function createItem(type, values, id_data) { .attr('name', 'status_' + id_data); if(values['label_position'] == 'up'){ - item - .append('
'+values['label']+'
') - .append($image) - .append($image) - .append($input); + + if(values['image'] == '' || values['image'] == 'none'){ + item + .append('
'+values['label']+'
') + .append($input); + } + else{ + item + .append('
'+values['label']+'
') + .append($image) + .append($image) + .append($input); + } } else if(values['label_position'] == 'down'){ - item - .append($image) - .append($image) - .append('
'+values['label']+'
') - .append($input); + + if(values['image'] == '' || values['image'] == 'none'){ + item + .append('
'+values['label']+'
') + .append($input); + + } + else{ + item + .append($image) + .append($image) + .append('
'+values['label']+'
') + .append($input); + } + } else if(values['label_position'] == 'left'){ @@ -2588,10 +3083,19 @@ function createItem(type, values, id_data) { item .append('
'+values['label']+'
') } + + if(values['image'] == '' || values['image'] == 'none'){ + item + .append($input); + } + else{ item .append($image) .append($image) - .append($input); + .append($input); + } + + } else if(values['label_position'] == 'right'){ if(values['height'] == 0){ @@ -2602,10 +3106,20 @@ function createItem(type, values, id_data) { item .append('
'+values['label']+'
') } + + if(values['image'] == '' || values['image'] == 'none'){ + item + .append($input); + } + else{ item .append($image) .append($image) - .append($input); + .append($input); + } + + + } if(values['show_statistics'] != 1){ @@ -2618,15 +3132,22 @@ function createItem(type, values, id_data) { if(values['show_statistics'] != 1){ if ((values['width'] == 0) || (values['height'] == 0)) { + + if(values['image'] != '' && values['image'] != 'none'){ // Do none - if($('#preview > img')[0].naturalWidth > 150 || $('#preview > img')[0].naturalHeight > 150){ - $image.attr('width', '70') - .attr('height', '70'); + 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', $('#preview > img')[0].naturalWidth) - .attr('height', $('#preview > img')[0].naturalHeight); - } + $image.attr('width', '70') + .attr('height', '70'); + } } else { $image.attr('width', values['width']) @@ -4226,7 +4747,7 @@ function showPreviewStaticGraph(staticGraph) { .css('text-align', 'right') .append($spinner); - if(staticGraph == ''){ + if(staticGraph == '' || staticGraph == 'none'){ if (is_metaconsole()) { $spinner.prop("src", "../../images/image_problem_area.png"); @@ -4282,7 +4803,7 @@ function showPreviewIcon(icon) { .append($spinner); - if (icon == '') { + if (icon == '' || icon == 'none') { if (is_metaconsole()) { $spinner.prop("src", "../../images/image_problem_area.png"); } diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php index df12edd408..05bfc2866a 100755 --- a/pandora_console/include/functions_visual_map.php +++ b/pandora_console/include/functions_visual_map.php @@ -442,7 +442,7 @@ function visual_map_print_item($mode = "read", $layoutData, // Link to an module if (empty($layoutData['id_metaconsole'])) { $url = $config['homeurl'] . - 'index.php?sec=view&sec2=operation/agentes/status_monitor&id_module=' . $layoutData['id_agente_modulo']; + 'index.php?sec=estado&sec2=operation/agentes/status_monitor&id_module=' . $layoutData['id_agente_modulo']; } else { $url = ui_meta_get_url_console_child( @@ -613,7 +613,7 @@ function visual_map_print_item($mode = "read", $layoutData, // Link to an module if (empty($layoutData['id_metaconsole'])) { $url = $config['homeurl'] . - 'index.php?sec=view&sec2=operation/agentes/status_monitor&id_module=' . $layoutData['id_agente_modulo']; + 'index.php?sec=estado&sec2=operation/agentes/status_monitor&id_module=' . $layoutData['id_agente_modulo']; } else { $url = ui_meta_get_url_console_child( @@ -662,11 +662,11 @@ function visual_map_print_item($mode = "read", $layoutData, $url = $server["server_url"] . - '/index.php?sec=view&sec2=operation/agentes/status_monitor&id_module=' . $layoutData['id_agente_modulo']; + '/index.php?sec=estado&sec2=operation/agentes/status_monitor&id_module=' . $layoutData['id_agente_modulo']; } else { $url = - $config['homeurl'].'/index.php?sec=view&sec2=operation/agentes/status_monitor&id_module=' . $layoutData['id_agente_modulo']; + $config['homeurl'].'/index.php?sec=estado&sec2=operation/agentes/status_monitor&id_module=' . $layoutData['id_agente_modulo']; } } else { @@ -730,7 +730,7 @@ function visual_map_print_item($mode = "read", $layoutData, else { if (empty($layoutData['id_metaconsole'])) { $url = $config['homeurl'] . - '/index.php?sec=view&sec2=operation/agentes/status_monitor&id_module=' . $layoutData['id_agente_modulo']; + '/index.php?sec=estado&sec2=operation/agentes/status_monitor&id_module=' . $layoutData['id_agente_modulo']; } else { $url = ui_meta_get_url_console_child( @@ -1607,7 +1607,8 @@ function visual_map_print_item($mode = "read", $layoutData, break; case STATIC_GRAPH: case GROUP_ITEM: - if ($layoutData['image'] != null || $layoutData['show_statistics'] == 1) { + + if (($layoutData['image'] != null && $layoutData['image'] != 'none') || $layoutData['show_statistics'] == 1) { $img_style_title = strip_tags($label); diff --git a/pandora_console/include/functions_visual_map_editor.php b/pandora_console/include/functions_visual_map_editor.php index 1333f5e73a..b406a0e360 100755 --- a/pandora_console/include/functions_visual_map_editor.php +++ b/pandora_console/include/functions_visual_map_editor.php @@ -201,7 +201,7 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) { $form_items['image_row']['html'] = '' . __('Image') . ' ' . - html_print_select ($images_list, 'image', '', 'showPreview(this.value);', 'None', '', true) . + html_print_select ($images_list, 'image', '', 'showPreview(this.value);', 'None', 'none', true) . '';