diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 9a18bfba98..8852785e6e 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -1904,10 +1904,15 @@ function html_print_input_hidden_extended( * * @return string HTML code if return parameter is true. */ -function html_print_input_color($name, $value, $class=false, $return=false) +function html_print_input_color($name, $value, $id='', $class=false, $return=false) { $attr_type = 'type="color"'; - $attr_id = 'id="color-'.htmlspecialchars($name, ENT_QUOTES).'"'; + if (empty($id) === true) { + $attr_id = 'id="color-'.htmlspecialchars($name, ENT_QUOTES).'"'; + } else { + $attr_id = 'id="'.$id.'"'; + } + $attr_name = 'name="'.htmlspecialchars($name, ENT_QUOTES).'"'; $attr_value = 'value="'.htmlspecialchars($value, ENT_QUOTES).'"'; $attr_class = 'class="'.($class !== false ? htmlspecialchars($class, ENT_QUOTES) : '').'"'; @@ -3495,6 +3500,7 @@ function html_print_input($data, $wrapper='div', $input_only=false) $output .= html_print_input_color( $data['name'], $data['value'], + $data['id'], ((isset($data['class']) === true) ? $data['class'] : false), ((isset($data['return']) === true) ? $data['return'] : false) ); diff --git a/pandora_console/include/functions_visual_map_editor.php b/pandora_console/include/functions_visual_map_editor.php index ed99a7b429..39735b39e4 100755 --- a/pandora_console/include/functions_visual_map_editor.php +++ b/pandora_console/include/functions_visual_map_editor.php @@ -738,13 +738,13 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) $form_items['color_cloud_def_color_row'] = []; $form_items['color_cloud_def_color_row']['items'] = ['color_cloud']; $form_items['color_cloud_def_color_row']['html'] = ''.__('Default color').' - '.html_print_input_color('default_color', $default_color, false, true).''; + '.html_print_input_color('default_color', $default_color, '', false, true).''; // Color ranges $color_range_tip = __('The color of the element will be the one selected in the first range created in which the value of the module is found (with the initial and final values of the range included)').'.'; $form_items['color_cloud_color_ranges_row'] = []; $form_items['color_cloud_color_ranges_row']['items'] = ['color_cloud']; - $form_items['color_cloud_color_ranges_row']['html'] = ''.__('Ranges').ui_print_help_tip($color_range_tip, true).''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.'
'.__('From value').''.html_print_input_text('from_value_new', '', '', 5, 255, true).''.''.html_print_image('images/add.png', true).''.'
'.__('To value').''.html_print_input_text('to_value_new', '', '', 5, 255, true).'
'.__('Color').''.html_print_input_color('color_new', $default_color, false, true).'
'.''; + $form_items['color_cloud_color_ranges_row']['html'] = ''.__('Ranges').ui_print_help_tip($color_range_tip, true).''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.''.'
'.__('From value').''.html_print_input_text('from_value_new', '', '', 5, 255, true).''.''.html_print_image('images/add.png', true).''.'
'.__('To value').''.html_print_input_text('to_value_new', '', '', 5, 255, true).'
'.__('Color').''.html_print_input_color('color_new', $default_color, '', false, true).'
'.''; // End of Color Cloud rows $form_items['show_on_top_row'] = []; diff --git a/pandora_console/include/javascript/pandora_visual_console.js b/pandora_console/include/javascript/pandora_visual_console.js index d6d421048d..96be159319 100755 --- a/pandora_console/include/javascript/pandora_visual_console.js +++ b/pandora_console/include/javascript/pandora_visual_console.js @@ -1678,6 +1678,11 @@ function createColorRange(baseUrl, vcId) { } $("#itemForm-specific ul.wizard:first").append(data); + + // Default values. + document.getElementById("rangeDefaultFrom").value = 0; + document.getElementById("rangeDefaultTo").value = 0; + document.getElementById("color-rangeDefaultColor").value = "#000000"; return; }; @@ -1760,6 +1765,16 @@ function createColorRangeVisualConsole( }; } +/** + * Delete color ranges. + * @param {string} id UniqId for row range. + * @return {Void} + */ +// eslint-disable-next-line no-unused-vars +function removeColorRange(id) { + $("#li-" + id).remove(); +} + /** * Onchange time-zone. * @return {void} diff --git a/pandora_console/include/rest-api/index.php b/pandora_console/include/rest-api/index.php index 188d8c4fbf..dae52bc7dc 100644 --- a/pandora_console/include/rest-api/index.php +++ b/pandora_console/include/rest-api/index.php @@ -248,6 +248,7 @@ if ($getVisualConsole === true) { echo json_encode($count); return; } else if ($createColorRangeVisualConsole) { + $uniqId = \uniqid(); $baseUrl = ui_get_full_url('/', false, false, false); $from = get_parameter('from', 0); $to = get_parameter('to', 0); @@ -281,10 +282,11 @@ if ($getVisualConsole === true) { 'type' => 'button', 'attributes' => 'class="remove-item-img"', 'return' => true, - 'script' => 'removeColorRange(\''.$baseUrl.'\',\''.$visualConsoleId.'\')', + 'script' => 'removeColorRange(\''.$uniqId.'\')', ]; - $liRangeColor = '
  • '; + $classRangeColor = 'interval-color-ranges flex-row flex-start w100p'; + $liRangeColor = '
  • '; $liRangeColor .= ''; $liRangeColor .= html_print_input($rangeFrom); $liRangeColor .= ''; diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/ColorCloud.php b/pandora_console/include/rest-api/models/VisualConsole/Items/ColorCloud.php index 1eee684d59..768f131c5e 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/ColorCloud.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/ColorCloud.php @@ -39,21 +39,27 @@ final class ColorCloud extends Item { $colorRangeArray = []; - if (isset($data['colorRanges']) === true) { - foreach ($data['colorRanges'] as $colorRange) { - if (\is_numeric($colorRange['fromValue']) === true - && \is_numeric($colorRange['toValue']) === true - && static::notEmptyStringOr( - $colorRange['color'], - null - ) !== null - ) { - $colorRangeArray[] = [ - 'color' => $colorRange['color'], - 'from_value' => (float) $colorRange['fromValue'], - 'to_value' => (float) $colorRange['toValue'], - ]; + if (isset($data['colorRanges']) === true + && is_array($data['colorRanges']) === true + ) { + if (empty($data['colorRanges']) === false) { + foreach ($data['colorRanges'] as $colorRange) { + if (\is_numeric($colorRange['fromValue']) === true + && \is_numeric($colorRange['toValue']) === true + && static::notEmptyStringOr( + $colorRange['color'], + null + ) !== null + ) { + $colorRangeArray[] = [ + 'color' => $colorRange['color'], + 'from_value' => (float) $colorRange['fromValue'], + 'to_value' => (float) $colorRange['toValue'], + ]; + } } + } else { + $colorRangeArray = []; } } @@ -105,7 +111,7 @@ final class ColorCloud extends Item $return['label'] = json_encode( [ 'default_color' => ($defaultColor !== null) ? $defaultColor : $prevDataDefaultColor, - 'color_ranges' => ($colorRanges !== null && (count($colorRanges) > 0)) ? $colorRanges : $prevDataColorRanges, + 'color_ranges' => ($colorRanges !== null) ? $colorRanges : $prevDataColorRanges, ] ); } @@ -426,7 +432,7 @@ final class ColorCloud extends Item // Label. $inputs[] = [ - 'label' => __('Default').':', + 'label' => __('Add new range').':', ]; $baseUrl = ui_get_full_url('/', false, false, false); @@ -481,7 +487,7 @@ final class ColorCloud extends Item // Label. $inputs[] = [ - 'label' => __('Ranges').':', + 'label' => __('Current ranges').':', ]; if (isset($values['colorRanges']) === true @@ -489,7 +495,9 @@ final class ColorCloud extends Item && empty($values['colorRanges']) === false ) { foreach ($values['colorRanges'] as $k => $v) { + $uniqId = \uniqid(); $inputs[] = [ + 'block_id' => $uniqId, 'class' => 'interval-color-ranges flex-row flex-start w100p', 'direct' => 1, 'block_content' => [ @@ -515,6 +523,7 @@ final class ColorCloud extends Item 'label' => __('Color'), 'arguments' => [ 'wrapper' => 'div', + 'id' => 'rangeColor'.$uniqId, 'name' => 'rangeColor[]', 'type' => 'color', 'value' => $v['color'], @@ -523,12 +532,14 @@ final class ColorCloud extends Item ], [ 'arguments' => [ - 'name' => 'Remove', + 'name' => 'remove-'.$uniqId, 'label' => '', 'type' => 'button', 'attributes' => 'class="remove-item-img"', 'return' => true, - 'script' => 'removeColorRange(\''.$baseUrl.'\',\''.$values['vCId'].'\')', + 'script' => 'removeColorRange( + \''.$uniqId.'\' + )', ], ], ], diff --git a/pandora_console/include/rest-api/models/VisualConsole/View.php b/pandora_console/include/rest-api/models/VisualConsole/View.php index de20f68a76..fd26b33257 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/View.php +++ b/pandora_console/include/rest-api/models/VisualConsole/View.php @@ -104,7 +104,7 @@ class View extends \HTML 'img' => 'event_responses_col.png', ], ]; - } else if ($type === BOX_ITEM) { + } else if ($type === BOX_ITEM || $type === COLOR_CLOUD) { $activetabs = 1; $tabs = [ [