Added item to editor

This commit is contained in:
Arturo Gonzalez 2017-10-23 08:32:41 +02:00
parent 1d3a082e5c
commit 05bbdecdd8
4 changed files with 151 additions and 79 deletions

View File

@ -421,39 +421,14 @@ function update_button_palette_callback() {
setModuleGraph(idItem);
break;
case 'bars_graph':
if($('#dir_items').html() == 'horizontal'){
if(parseInt($('#text-left').val()) + (parseInt($('input[name=height_module_graph]').val() * $('#count_items').html())) > parseInt($('#background').css('width'))
|| parseInt($('#text-left').val()) + (parseInt($('input[name=width_module_graph]').val() * $('#count_items').html())) > parseInt($('#background').css('width'))){
alert($('#count_items').html()+' joined graph items are wider than background');
return false;
}
}
if($('#dir_items').html() == 'vertical'){
if(parseInt($('#text-top').val()) + (parseInt($('input[name=height_module_graph]').val() * $('#count_items').html())) > parseInt($('#background').css('height'))){
alert($('#count_items').html()+' joined graph items are higher than background');
return false;
}
}
if($('input[name=width_module_graph]').val() == ''){
if($('input[name=width_percentile]').val() == ''){
alert('Undefined width');
return false;
}
if($('input[name=height_module_graph]').val() == ''){
alert('Undefined height');
return false;
}
if($('#custom_graph_row').css('display') != 'none' && $("#custom_graph option:selected").html() == 'None'){
alert('Undefined graph');
return false;
}
$("#text_" + idItem).html(values['label']);
$("#image_" + idItem).attr("src", "images/spinner.gif");
setBarsGraph(idItem, values);
break;
case 'auto_sla_graph':
@ -701,7 +676,7 @@ function readFields() {
function create_button_palette_callback() {
var values = readFields();
console.log(values);
//VALIDATE DATA
var validate = true;
switch (creationItem) {
@ -804,14 +779,6 @@ function create_button_palette_callback() {
}
break;
case 'bars_graph':
if (values['width_module_graph'] == '') {
alert('Undefined width');
validate = false;
}
if (values['height_module_graph'] == '') {
alert('Undefined height');
validate = false;
}
if ((values['agent'] == '')) {
alert($("#message_alert_no_agent").html());
validate = false;
@ -1811,6 +1778,8 @@ function setBarsGraph(id_data, values) {
url_hack_metaconsole = '../../';
}
width_percentile = values['width_percentile'];
parameter = Array();
parameter.push ({name: "page", value: "include/ajax/visual_console_builder.ajax"});
@ -1825,24 +1794,24 @@ function setBarsGraph(id_data, values) {
dataType: 'json',
success: function (data) {
if (data['no_data'] == true) {
if (values['width'] == "0" || values['height'] == "0") {
if (values['width'] == "0") {
$("#" + id_data + " img").attr('src', url_hack_metaconsole + 'images/console/signes/barras-no.png');
}
else {
$("#" + id_data + " img").attr('src', url_hack_metaconsole + 'images/console/signes/barras-no.png');
$("#" + id_data + " img").css('width', values['width'] + 'px');
$("#" + id_data + " img").css('height', values['height'] + 'px');
$("#" + id_data + " img").css('width', width_percentile + 'px');
$("#" + id_data + " img").css('height', width_percentile + 'px');
}
}
else {
$("#" + id_data + " img").attr('src', url_hack_metaconsole + 'images/console/signes/barras.png');
if($('#text-width').val() == 0 || $('#text-height').val() == 0){
if($('#text-width').val() == 0){
// Image size
}
else{
$("#" + id_data + " img").css('width', $('#text-width').val()+'px');
$("#" + id_data + " img").css('height', $('#text-height').val()+'px');
$("#" + id_data + " img").css('width', $('#text-width_percentile').val()+'px');
$("#" + id_data + " img").css('height', $('#text-width_percentile').val()+'px');
}
}
@ -2344,34 +2313,23 @@ function createItem(type, values, id_data) {
}
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']);
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_'+id_data).css('width', values['width']+'px');
// $('#image_'+id_data).css('height', values['height']+'px');
// }
/*
var $span = $('<span></span>')
.attr('id', 'text_' + id_data)
.attr('class', 'text')
.append(values['label']);
*/
else {
$image.attr('width', values['width'])
.attr('height', values['height']);
}
}
var $input = $('<input></input>')
.attr('id', 'hidden-status_' + id_data)
.attr('type', 'hidden')

View File

@ -624,11 +624,8 @@ switch ($action) {
}
break;
case 'bars_graph':
if ($height_module_graph !== null) {
$values['height'] = $height_module_graph;
}
if ($width_module_graph !== null) {
$values['width'] = $width_module_graph;
if ($width_percentile !== null) {
$values['width'] = $width_percentile;
}
if ($bars_graph_type !== null) {
$values['type_graph'] = $id_custom_graph;
@ -842,8 +839,7 @@ switch ($action) {
$elementFields['height_module_graph'] = $elementFields['height'];
break;
case 'bars_graph':
$elementFields['width_module_graph'] = $elementFields['width'];
$elementFields['height_module_graph'] = $elementFields['height'];
$elementFields['width_percentile'] = $elementFields['width'];
$elementFields['bars_graph_type'] = $elementFields['type_graph'];
break;
case 'box_item':
@ -984,8 +980,12 @@ switch ($action) {
break;
case 'bars_graph':
$values['type'] = BARS_GRAPH;
$values['height'] = $height_module_graph;
$values['width'] = $width_module_graph;
if ($width_percentile == null) {
$values['width'] = 0;
}
else {
$values['width'] = $width_percentile;
}
$values['type_graph'] = $bars_graph_type;
$values['image'] = $background_color;
break;

View File

@ -1080,6 +1080,120 @@ function visual_map_print_item($mode = "read", $layoutData,
}
break;
case BARS_GRAPH:
$imgpos = '';
if($layoutData['label_position']=='left'){
$imgpos = 'float:right';
}
else if($layoutData['label_position']=='right'){
$imgpos = 'float:left';
}
if (!empty($proportion)) {
$width =
((integer)($proportion['proportion_width'] * $width));
$height =
((integer)($proportion['proportion_height'] * $height));
}
//Metaconsole db connection
if ($layoutData['id_metaconsole'] != 0) {
$connection = db_get_row_filter ('tmetaconsole_setup',
array('id' => $layoutData['id_metaconsole']));
if (metaconsole_load_external_db($connection) != NOERR) {
continue;
}
}
if ($isExternalLink)
$homeurl = $config['homeurl'];
else
$homeurl = '';
if ( (get_parameter('action') == 'edit') || (get_parameter('operation') == 'edit_visualmap') ) {
if($width == 0){
if ($layoutData['id_metaconsole'] != 0) {
$img = '<img src="../../images/console/signes/barras.png" style="width:400px;height:400px;'.$imgpos.'">';
}
else{
$img = '<img src="images/console/signes/barras.png" style="width:400px;height:400px;'.$imgpos.'">';
}
}
else{
if ($layoutData['id_metaconsole'] != 0) {
$img = '<img src="../../images/console/signes/barras.png" style="width:'.$width.'px;height:'.$width.'px;'.$imgpos.'">';
}
else{
$img = '<img src="images/console/signes/barras.png" style="width:'.$width.'px;height:'.$width.'px;'.$imgpos.'">';
}
}
}
else {
if ($width == 0) {
if ($layoutData['label_position']=='left') {
$img = '<div style="float:right;height:'.$himg.'px;">'.
grafico_modulo_sparse($id_module, $period,
0, 300, 180, modules_get_agentmodule_name($id_module),null, false, 1, false, 0,
modules_get_unit($id_module), 0, 0, true, $only_image, '', 1, false, '',
false, false, false, $layoutData['image'],
null, true, false, $type_graph) . '</div>';
}
elseif($layoutData['label_position']=='right') {
$img = '<div style="float:left;height:'.$himg.'px;">' .
grafico_modulo_sparse($id_module,
$period, 0, 300, 180, modules_get_agentmodule_name($id_module),null, false,
1, false, 0, modules_get_unit($id_module), 0, 0, true, $only_image, '',
1, false, '', false, false, false,
$layoutData['image'], null, true,
false, $type_graph) . '</div>';
}
else {
$img = grafico_modulo_sparse($id_module,
$period, 0, 300, 180, modules_get_agentmodule_name($id_module),null, false, 1,
false, 0, modules_get_unit($id_module), 0, 0, true, $only_image, '',
1, false, '', false, false, false,
$layoutData['image'], null, true, false, $type_graph);
}
}
else{
if ($layoutData['label_position']=='left') {
$img = '<div style="float:right;height:'.$himg.'px;">' .
grafico_modulo_sparse($id_module, $period,
0, $width, $height, modules_get_agentmodule_name($id_module), null, false, 1,
false, 0, modules_get_unit($id_module), 0, 0, true, $only_image, '',
1, false, '', false, false, false,
$layoutData['image'], null, true,
false, $type_graph) . '</div>';
}
elseif ($layoutData['label_position']=='right') {
$img = '<div style="float:left;height:'.$himg.'px;">' .
grafico_modulo_sparse($id_module, $period,
0, $width, $height, modules_get_agentmodule_name($id_module), null, false, 1,
false, 0, modules_get_unit($id_module), 0, 0, true, $only_image,
'', 1, false, modules_get_unit($id_module), false, false, false,
$layoutData['image'], null, true,
false, $type_graph) . '</div>';
}
else {
$img = grafico_modulo_sparse($id_module,
$period, 0, $width, $height, modules_get_agentmodule_name($id_module), null,
false, 1, false, 0, modules_get_unit($id_module), 0, 0, true,
$only_image, '', 1, false, '', false,
false, false, $layoutData['image'],
null, false, true, $type_graph);
}
}
}
//Restore db connection
if ($layoutData['id_metaconsole'] != 0) {
metaconsole_restore_db();
}
break;
case LABEL:
$z_index = 4 + 1;
break;
@ -1157,7 +1271,7 @@ function visual_map_print_item($mode = "read", $layoutData,
case MODULE_GRAPH:
$class .= "module_graph";
break;
case MODULE_GRAPH:
case BARS_GRAPH:
$class .= "bars_graph";
break;
case SIMPLE_VALUE:

View File

@ -399,7 +399,7 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) {
$form_items['percentile_bar_row_1'] = array();
$form_items['percentile_bar_row_1']['items'] = array('percentile_bar', 'percentile_item', 'datos');
$form_items['percentile_bar_row_1']['items'] = array('percentile_bar', 'percentile_item', 'datos', 'bars_graph');
$form_items['percentile_bar_row_1']['html'] = '<td align="left">' .
__('Width') . '</td>
<td align="left">' . html_print_input_text('width_percentile', 0, '', 3, 5, true) . '</td>';