Merge branch 'ent-13059-mejorar-visualizacion-de-modulos-en-widget-de-agent-module-view' into 'develop'

Ent 13059 mejorar visualizacion de modulos en widget de agent module view

See merge request artica/pandorafms!7116
This commit is contained in:
Jose Martin 2024-04-09 13:32:35 +00:00
commit 95d25eab2c
8 changed files with 491 additions and 18 deletions

View File

@ -16,7 +16,7 @@
* @package Include
* @subpackage HTML
*/
use PandoraFMS\Enterprise\Metaconsole\Node;
if (!isset($config)) {
$working_dir = getcwd();
$working_dir = str_replace('\\', '/', $working_dir);
@ -1854,6 +1854,301 @@ function html_print_select_multiple_modules_filtered(array $data):string
}
/**
* Form multiple inputs for slect groups.
*
* @param array $data Data inputs.
*
* @return string Html output.
*/
function html_print_select_multiple_modules_filtered_formated(array $data):string
{
if (is_ajax() === true) {
ui_require_javascript_file(
'multiselect_filtered',
'include/javascript/',
true
);
ui_require_css_file(
'multiselect_filtered',
'include/styles/',
true
);
} else {
ui_require_javascript_file('multiselect_filtered');
ui_require_css_file('multiselect_filtered');
}
$uniqId = $data['uniqId'];
$return_all_group = isset($data['mReturnAllGroup']) ? $data['mReturnAllGroup'] : true;
// Group.
$output = '<div class="w98p">';
$output .= html_print_input(
[
'label' => __('Group'),
'label_class' => 'font-title-font',
'name' => 'filtered-module-group-'.$uniqId,
'returnAllGroup' => $return_all_group,
'privilege' => 'AR',
'type' => 'select_groups',
'return' => true,
'script' => 'fmAgentChange(\''.$uniqId.'\')',
'selected' => $data['mGroup'],
]
);
// Groups module.
$module_groups = db_get_all_rows_sql(
'SELECT * FROM tmodule_group ORDER BY name'
);
$module_groups = array_reduce(
$module_groups,
function ($carry, $item) {
$carry[$item['id_mg']] = $item['name'];
return $carry;
}
);
$output .= html_print_input(
[
'label' => __('Module group'),
'label_class' => 'font-title-font',
'type' => 'select',
'fields' => $module_groups,
'name' => 'filtered-module-module-group-'.$uniqId,
'selected' => $data['mModuleGroup'],
'return' => true,
'nothing' => __('All'),
'nothing_value' => 0,
'script' => 'fmModuleChange(\''.$uniqId.'\', '.(int) is_metaconsole().')',
]
);
$output .= '</div>';
$output .= '<div class="recursive-modules mrgn_lft_20px_important">';
// Recursion.
$output .= html_print_input(
[
'label' => __('Recursion'),
'label_class' => 'font-title-font',
'type' => 'switch',
'name' => 'filtered-module-recursion-'.$uniqId,
'value' => (empty($data['mRecursion']) === true) ? false : true,
'checked' => (empty($data['mRecursion']) === true) ? false : true,
'return' => true,
'id' => 'filtered-module-recursion-'.$uniqId,
'onchange' => 'fmAgentChange(\''.$uniqId.'\')',
]
);
$commonModules = 0;
if (empty($data['mShowCommonModules']) === false) {
$commonModules = 1;
}
$output .= html_print_input(
[
'label' => __('Only common modules'),
'label_class' => 'font-title-font',
'type' => 'switch',
'checked' => $commonModules,
'value' => $commonModules,
'name' => 'filtered-module-show-common-modules-'.$uniqId,
'id' => 'filtered-module-show-common-modules-'.$uniqId,
'return' => true,
'onchange' => 'fmModuleChange(\''.$uniqId.'\', '.(int) is_metaconsole().')',
]
);
$output .= '</div>';
if (empty($data['searchBar']) === false && $data['searchBar'] === true) {
$output .= '<div>';
$output .= '<div>';
$output .= html_print_input(
[
'type' => 'text',
'name' => 'agent-searchBar-'.$uniqId,
'onKeyUp' => 'searchAgent(\''.$uniqId.'\')',
'placeholder' => __('Type to search agents'),
'return' => true,
]
);
$output .= '</div>';
$output .= '<div>';
$output .= html_print_input(
[
'type' => 'text',
'name' => 'module-searchBar-'.$uniqId,
'onKeyUp' => 'searchModule(\''.$uniqId.'\')',
'return' => true,
'placeholder' => __('Type to search modules'),
]
);
$output .= '</div>';
$output .= '</div>';
}
$output .= '<div class="w98p">';
// Agent.
$agents = agents_get_group_agents(
// Id_group.
$data['mGroup'],
// Search.
false,
// Case.
'lower',
// NoACL.
false,
// ChildGroups.
false,
// Serialized.
false,
// Separator.
'|',
// Add_alert_bulk_op.
false,
// Force_serialized.
false,
// Meta_fields.
($data['mMetaFields'] ?? is_metaconsole())
);
if ((empty($agents)) === true || $agents == -1) {
$agents = [];
}
if ($data['mShowSelectedOtherGroups']) {
$selected_agents = explode(',', $data['mAgents']);
foreach ($selected_agents as $agent_id) {
if (!array_key_exists($agent_id, $agents)) {
$agents[$agent_id] = agents_get_alias($agent_id);
}
}
}
if (is_metaconsole() === true) {
$output .= html_print_input(
[
'label' => __('Agents'),
'label_class' => 'font-title-font',
'type' => 'select',
'fields' => $agents,
'name' => 'filtered-module-agents-'.$uniqId,
'selected' => explode(',', $data['mAgents']),
'return' => true,
'multiple' => true,
'style' => 'min-width: 200px;max-width:200px;',
'script' => 'fmModuleChange(\''.$uniqId.'\', '.(int) is_metaconsole().')',
'placeholder' => (isset($data['placeholderAgents']) === true) ? $data['placeholderAgents'] : '',
'truncate_size' => 300,
]
);
} else {
$output .= html_print_input(
[
'label' => __('Agents'),
'label_class' => 'font-title-font',
'type' => 'select_from_sql',
'sql' => 'SELECT `id_agente`,`alias` FROM tagente',
'name' => 'filtered-module-agents-'.$uniqId,
'selected' => explode(',', $data['mAgents']),
'return' => true,
'multiple' => true,
'style' => 'min-width: 200px;max-width:200px;',
'script' => 'fmModuleChange(\''.$uniqId.'\', '.(int) is_metaconsole().')',
'placeholder' => (isset($data['placeholderAgents']) === true) ? $data['placeholderAgents'] : '',
'truncate_size' => 300,
]
);
}
if (empty($data['mAgents']) === false
&& empty($data['mModuleGroup'] === false)
) {
$all_modules = get_modules_agents(
$data['mModuleGroup'],
explode(',', $data['mAgents']),
!$commonModules,
!is_metaconsole(),
is_metaconsole(),
false
);
} else {
$all_modules = [];
}
$mModules = $data['mModules'];
if (is_array($data['mModules']) === false) {
$mModules = explode(
',',
$data['mModules']
);
} else {
if (is_metaconsole()) {
foreach ($data['mModules'] as $row) {
$exp = explode('|', $row);
if (empty($exp[0]) === false) {
if (is_numeric($exp[1]) === false) {
if (is_metaconsole() === true) {
$node = new Node($exp[0]);
$node->connect();
}
$module = explode('&#x20;&raquo;&#x20;', $exp[1]);
$id_agente = db_get_sql(sprintf('SELECT id_agente FROM tagente WHERE nombre = "%s"', $module[1]));
$id_agente_modulo = db_get_sql(sprintf('SELECT id_agente_modulo FROM tagente_modulo WHERE nombre = "%s" AND id_agente = %s', $module[2], $id_agente));
$array = [
$exp[0].'|'.$id_agente_modulo => $exp[0].'|'.$id_agente_modulo,
];
$mModules = array_merge($mModules, $array);
if (is_metaconsole() === true) {
$node->disconnect();
}
}
}
}
}
}
$result = [];
// Clean double safe input.
foreach ($mModules as $name) {
$result[] = io_safe_output($name);
}
$output .= html_print_input(
[
'label' => __('Modules'),
'label_class' => 'font-title-font',
'type' => 'select',
'fields' => $all_modules,
'name' => 'filtered-module-modules-'.$uniqId,
'selected' => $result,
'return' => true,
'multiple' => true,
'style' => 'max-width:98%;',
'input_class' => 'flex-colum-center-important',
'truncate_size' => 300,
]
);
$output .= '</div>';
if ($data['return'] === false) {
echo $output;
}
return $output;
}
/**
* Prints an array of fields in a popup menu of a form based on a SQL query.
* The first and second columns of the query will be used.
@ -1896,6 +2191,7 @@ function html_print_select_from_sql(
$class='',
$required=false,
$placeholder='',
$title=false,
) {
global $config;
@ -1943,7 +2239,8 @@ function html_print_select_from_sql(
'',
false,
null,
$placeholder
$placeholder,
$title
);
}
@ -5727,6 +6024,7 @@ function html_print_input($data, $wrapper='div', $input_only=false)
((isset($data['class']) === true) ? $data['class'] : ''),
((isset($data['required']) === true) ? $data['required'] : false),
((isset($data['placeholder']) === true) ? $data['placeholder'] : null),
((isset($data['title']) === true) ? $data['title'] : false),
);
break;
@ -6112,6 +6410,10 @@ function html_print_input($data, $wrapper='div', $input_only=false)
$output .= html_print_select_multiple_modules_filtered($data);
break;
case 'select_multiple_modules_filtered_formated':
$output .= html_print_select_multiple_modules_filtered_formated($data);
break;
case 'datalist':
$output .= html_print_datalist(
$data['name'],

View File

@ -218,6 +218,7 @@ function fmModuleChange(uniqId, isMeta) {
"#filtered-module-show-common-modules-" + uniqId
).attr("type");
var select_mode = isMeta === 1 ? 0 : 1;
var showCommonModules = +(
$("#filtered-module-show-common-modules-" + uniqId).prop("checked") == false
);
@ -229,7 +230,8 @@ function fmModuleChange(uniqId, isMeta) {
get_modules_group_json: 1,
id_module_group: idModuleGroup,
id_agents: idAgents,
selection: showCommonModules
selection: showCommonModules,
select_mode: select_mode
},
function(data) {
$("#filtered-module-modules-" + uniqId).html("");
@ -247,9 +249,13 @@ function fmModuleChange(uniqId, isMeta) {
? value["id_node"] + "|" + value["id_agente_modulo"]
: value["id_agente_modulo"]
)
.attr("title", value)
.html(value["nombre"]);
} else {
option.attr("value", id).html(value);
option
.attr("value", id)
.attr("title", value)
.html(value);
}
$("#filtered-module-modules-" + uniqId).append(option);

View File

@ -1,6 +1,7 @@
/* globals $, GridStack, load_modal, TreeController, forced_title_callback, createVisualConsole, UndefineTinyMCE*/
// eslint-disable-next-line no-unused-vars
function show_option_dialog(settings) {
$("#modal-config-widget").html("");
load_modal({
target: $("#modal-update-dashboard"),
form: "form-update-dashboard",
@ -280,6 +281,8 @@ function initialiceLayout(data) {
});
$("#configure-widget-" + id).click(function() {
widgetId =
widgetId === 0 ? $("#hidden-widget_id_" + id).val() : widgetId;
getSizeModalConfiguration(id, widgetId);
});
@ -329,7 +332,20 @@ function initialiceLayout(data) {
},
dataType: "json",
success: function(data) {
addCell(data.cellId, 0, 0, 4, 4, true, 0, 2000, 0, 2000, 0, true);
addCell(
data.cellId,
0,
0,
4,
4,
true,
0,
2000,
0,
2000,
original_widgetId,
true
);
},
error: function(xhr, textStatus, errorMessage) {
console.log("ERROR" + errorMessage + textStatus + xhr);
@ -801,6 +817,8 @@ function initialiceLayout(data) {
});
$("#configure-widget-" + cellId).click(function() {
widgetId =
widgetId === 0 ? $("#hidden-widget_id_" + cellId).val() : widgetId;
getSizeModalConfiguration(cellId, widgetId);
});

View File

@ -179,7 +179,7 @@ class AgentModuleWidget extends Widget
// This forces at least a first configuration.
$this->configurationRequired = false;
if (isset($this->values['mModules']) === false) {
if (isset($this->values['mModules']) === false || (isset($this->values['mModules']) === true && empty($this->values['mModules'][0]) === true)) {
$this->configurationRequired = true;
}
@ -297,10 +297,10 @@ class AgentModuleWidget extends Widget
}
$inputs[] = [
'class' => 'flex flex-row',
'id' => 'select_multiple_modules_filtered',
'class' => 'flex-colum-center-important',
'id' => 'select_multiple_modules_filtered_formated',
'arguments' => [
'type' => 'select_multiple_modules_filtered',
'type' => 'select_multiple_modules_filtered_formated',
'uniqId' => $this->cellId,
'mGroup' => (isset($this->values['mGroup']) === true) ? $this->values['mGroup'] : $mgroup,
'mRecursion' => (isset($this->values['mRecursion']) === true) ? $this->values['mRecursion'] : '',
@ -514,6 +514,10 @@ class AgentModuleWidget extends Widget
$array_names = [];
foreach ($allModules as $module_name) {
if (is_numeric($module_name)) {
$module_name = io_safe_output(modules_get_agentmodule_name($module_name));
}
$file_name = ui_print_truncate_text(
\io_safe_output($module_name),
'module_small',
@ -744,13 +748,17 @@ class AgentModuleWidget extends Widget
$fullname = $item[1];
if ($this->values['mShowCommonModules'] !== 'on') {
$item = explode('&#x20;&raquo;&#x20;', $fullname);
$name = $item[1];
$name = $item[2];
$carry['modules_selected'][$serverId][$name] = null;
$carry['modules'][$name] = null;
} else {
$carry['modules'][$fullname] = null;
}
} else {
if (is_numeric($item) === true) {
$item = modules_get_agentmodule_name($item);
}
$carry['modules'][$item] = null;
}
@ -817,7 +825,7 @@ class AgentModuleWidget extends Widget
}
$key_name_module = $module->name();
if (array_key_exists($key_name_module, $allModules) === true) {
if ($this->values['mTypeShow'] === '1') {
$mod = $module->toArray();
$mod['datos'] = $module->lastValue();
@ -827,6 +835,7 @@ class AgentModuleWidget extends Widget
$visualData[$agent_id]['modules'][$key_name_module] = $module->getStatus()->estado();
}
}
}
if ((bool) is_metaconsole() === true) {
metaconsole_restore_db();

View File

@ -0,0 +1,118 @@
#select_multiple_modules_filtered_formated {
border: 1px solid #c1c1c1;
border-radius: 10px;
width: auto;
}
#select_multiple_modules_filtered_formated > div {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin: 5px;
}
#select_multiple_modules_filtered_formated > div > div {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
flex-wrap: wrap;
width: 48%;
}
#select_multiple_modules_filtered_formated .recursive-modules {
flex: auto;
width: 100%;
}
#select_multiple_modules_filtered_formated .recursive-modules > div {
display: flex;
flex-wrap: nowrap;
flex-direction: row-reverse;
justify-content: flex-end;
}
#select_multiple_modules_filtered_formated .recursive-modules > div > label {
max-width: unset;
font-weight: unset;
}
#select_multiple_modules_filtered_formated > div > div > select {
min-width: 250px !important;
}
#select_multiple_modules_filtered_formated > div > div > label.p-switch {
width: 10%;
}
#select_multiple_modules_filtered_formated > div > div > label.font-title-font {
margin-top: 5px;
}
#select_multiple_modules_filtered_formated > div > div > .select2 {
min-width: 250px !important;
}
form.modal-dashboard ul.wizard li {
align-items: flex-start;
}
form.modal-dashboard ul.wizard li label {
max-width: 100% !important;
width: 100%;
}
.flex-colum-center-important > select {
width: 95%;
height: 119px;
min-height: auto;
}
.wizard > li:nth-of-type(1) {
display: flex !important;
flex-direction: column !important;
grid-area: titulo;
}
.wizard > li:nth-of-type(1) > input {
width: 100%;
}
.wizard > li:nth-of-type(2) {
grid-area: color;
display: flex !important;
flex-direction: column !important;
}
.wizard > li:nth-of-type(3) {
grid-area: show;
display: flex !important;
flex-direction: column !important;
}
ul.wizard > li.flex-row > label {
width: 100%;
max-width: 100% !important;
min-height: 30px;
}
.wizard > li:nth-of-type(4) {
grid-area: todo;
width: 100% !important;
}
ul.wizard {
display: grid;
grid-template:
"titulo show color"
"todo todo todo";
grid-template-columns: 40% 40% 20%;
}
#wr_background > input {
background-color: #f6f7fb;
padding: 5px;
border-radius: 10px;
border: 1px solid #8a96a6;
}

View File

@ -7205,6 +7205,10 @@ div.graph div.legend table {
margin-left: 20px;
}
.mrgn_lft_20px_important {
margin-left: 20px !important;
}
.mrgn_lft_23px {
margin-left: 23px;
}
@ -12056,10 +12060,20 @@ div[role="dialog"] {
align-items: center;
}
.flex-colum-center-important {
display: flex !important;
flex-direction: column !important;
align-items: center !important;
}
.flex-colum-center > img {
margin: 5px;
}
.flex-none {
flex: none !important;
}
.space-between {
justify-content: space-between;
}

View File

@ -71,6 +71,7 @@ if ($manageDashboards !== 0 || $writeDashboards !== 0) {
$output .= '<a id="configure-widget-'.$cellData['id'].'" class="">';
$widget_description = db_get_value_sql('SELECT description FROM twidget WHERE id ='.$cellData['id_widget']);
$output .= html_print_input_hidden('widget_name_'.$cellData['id'], $widget_description, true);
$output .= html_print_input_hidden('widget_id_'.$cellData['id'], $cellData['id_widget'], true);
$output .= html_print_image(
'images/configuration@svg.svg',
true,

View File

@ -32,6 +32,7 @@ ui_require_javascript_file('tinymce', 'vendor/tinymce/tinymce/', true);
ui_require_javascript_file('pandora', 'include/javascript/', true);
$output = '';
$widgetId = json_decode(io_safe_output(get_parameter('extradata')), true)['widgetId'];
$form = [
'action' => '#',
@ -64,4 +65,8 @@ HTML::printForm(
]
);
if ($widgetId == '10') {
$output .= ui_require_css_file('agent_module_view', 'include/styles/', true, true);
}
echo $output;