Merge branch 'ent-12267-dashboard-mejora-del-widget-de-module-status' into 'develop'

add new filters widget modules status pandora_enterprise#12267

See merge request artica/pandorafms!6734
This commit is contained in:
Rafael Ameijeiras 2024-01-29 09:33:56 +00:00
commit c1b74ab7f0
4 changed files with 164 additions and 181 deletions

View File

@ -1875,6 +1875,8 @@ if (check_login()) {
$table_id = get_parameter('table_id', ''); $table_id = get_parameter('table_id', '');
$search = get_parameter('search', ''); $search = get_parameter('search', '');
$search_agent = get_parameter('search_agent', '');
$groupId = (int) get_parameter('groupId', 0);
$module_name = get_parameter('module_name', ''); $module_name = get_parameter('module_name', '');
$status = get_parameter('status', ''); $status = get_parameter('status', '');
$start = get_parameter('start', 0); $start = get_parameter('start', 0);
@ -1886,13 +1888,36 @@ if (check_login()) {
$nodes = get_parameter('nodes', 0); $nodes = get_parameter('nodes', 0);
$disabled_modules = (bool) get_parameter('disabled_modules', false); $disabled_modules = (bool) get_parameter('disabled_modules', false);
$groups_array = [];
if ($groupId === 0) {
if (users_can_manage_group_all('AR') === false) {
$groups_array = users_get_groups(false, 'AR', false);
}
} else {
$groups_array = [$groupId];
}
$where = '1=1'; $where = '1=1';
$recordsTotal = 0; $recordsTotal = 0;
if (empty($groups_array) === false) {
$where .= sprintf(
' AND (tagente.id_grupo IN (%s)
OR tagent_secondary_group.id_group IN(%s))',
implode(',', $groups_array),
implode(',', $groups_array)
);
}
if (empty($search) === false) { if (empty($search) === false) {
$where .= ' AND tagente_modulo.nombre LIKE "%%'.$search.'%%"'; $where .= ' AND tagente_modulo.nombre LIKE "%%'.$search.'%%"';
} }
if (empty($search_agent) === false) {
$where .= ' AND tagente.alias LIKE "%%'.$search_agent.'%%"';
}
if (str_contains($status, '6') === true) { if (str_contains($status, '6') === true) {
$expl = explode(',', $status); $expl = explode(',', $status);
$exist = array_search('6', $expl); $exist = array_search('6', $expl);
@ -1979,6 +2004,8 @@ if (check_login()) {
ON tagente_modulo.id_agente = tagente.id_agente ON tagente_modulo.id_agente = tagente.id_agente
INNER JOIN tagente_estado INNER JOIN tagente_estado
ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
LEFT JOIN tagent_secondary_group
ON tagente.id_agente = tagent_secondary_group.id_agent
WHERE %s WHERE %s
ORDER BY %s ORDER BY %s
LIMIT %d, %d', LIMIT %d, %d',
@ -1996,6 +2023,8 @@ if (check_login()) {
ON tagente_modulo.id_agente = tagente.id_agente ON tagente_modulo.id_agente = tagente.id_agente
INNER JOIN tagente_estado INNER JOIN tagente_estado
ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
LEFT JOIN tagent_secondary_group
ON tagente.id_agente = tagent_secondary_group.id_agent
WHERE %s', WHERE %s',
$where $where
); );
@ -2023,6 +2052,8 @@ if (check_login()) {
ON tagente_modulo.id_agente = tagente.id_agente ON tagente_modulo.id_agente = tagente.id_agente
INNER JOIN tagente_estado INNER JOIN tagente_estado
ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
LEFT JOIN tagent_secondary_group
ON tagente.id_agente = tagent_secondary_group.id_agent
WHERE %s', WHERE %s',
$where $where
); );
@ -2055,6 +2086,8 @@ if (check_login()) {
ON tagente_modulo.id_agente = tagente.id_agente ON tagente_modulo.id_agente = tagente.id_agente
INNER JOIN tagente_estado INNER JOIN tagente_estado
ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
LEFT JOIN tagent_secondary_group
ON tagente.id_agente = tagent_secondary_group.id_agent
WHERE %s', WHERE %s',
$where $where
); );

View File

@ -4257,15 +4257,15 @@ function ui_print_datatable(array $parameters)
// * END JAVASCRIPT. // * END JAVASCRIPT.
$info_msg_arr = []; $info_msg_arr = [];
$info_msg_arr['message'] = $emptyTable; $info_msg_arr['message'] = $emptyTable;
$info_msg_arr['div_class'] = 'info_box_container invisible_important datatable-msg-info-'.$table_id; $info_msg_arr['div_class'] = 'info_box_container invisible_important datatable-info-massage datatable-msg-info-'.$table_id;
$info_msg_arr_filter = []; $info_msg_arr_filter = [];
$info_msg_arr_filter['message'] = __('Please apply a filter to display the data.'); $info_msg_arr_filter['message'] = __('Please apply a filter to display the data.');
$info_msg_arr_filter['div_class'] = 'info_box_container invisible_important datatable-msg-info-filter-'.$table_id; $info_msg_arr_filter['div_class'] = 'info_box_container invisible_important datatable-info-massage datatable-msg-info-filter-'.$table_id;
$spinner = '<div id="'.$table_id.'-spinner" class="invisible spinner-fixed"><span></span><span></span><span></span><span></span></div>'; $spinner = '<div id="'.$table_id.'-spinner" class="invisible spinner-fixed"><span></span><span></span><span></span><span></span></div>';
$info_msg = '<div>'.ui_print_info_message($info_msg_arr, '', true).'</div>'; $info_msg = '<div class="datatable-container-info-massage">'.ui_print_info_message($info_msg_arr, '', true).'</div>';
$info_msg_filter = '<div>'.ui_print_info_message($info_msg_arr_filter, true).'</div>'; $info_msg_filter = '<div>'.ui_print_info_message($info_msg_arr_filter, true).'</div>';

View File

@ -200,6 +200,14 @@ class ModulesByStatus extends Widget
// Retrieve global - common inputs. // Retrieve global - common inputs.
$values = parent::decoders($decoder); $values = parent::decoders($decoder);
if (isset($decoder['groupId']) === true) {
$values['groupId'] = $decoder['groupId'];
}
if (isset($decoder['search_agent']) === true) {
$values['search_agent'] = $decoder['search_agent'];
}
if (isset($decoder['search']) === true) { if (isset($decoder['search']) === true) {
$values['search'] = $decoder['search']; $values['search'] = $decoder['search'];
} }
@ -240,9 +248,39 @@ class ModulesByStatus extends Widget
// Retrieve global - common inputs. // Retrieve global - common inputs.
$inputs = parent::getFormInputs(); $inputs = parent::getFormInputs();
$return_all_group = false;
if (users_can_manage_group_all('RM') || $values['groupId'] == 0) {
$return_all_group = true;
}
// Groups.
$inputs[] = [
'label' => __('Group'),
'arguments' => [
'type' => 'select_groups',
'name' => 'groupId',
'returnAllGroup' => $return_all_group,
'privilege' => 'AR',
'selected' => $values['groupId'],
'return' => true,
],
];
// Search Agent.
$inputs[] = [
'label' => __('Search agent').ui_print_help_tip(__('Search filter by Agent name field content'), true),
'arguments' => [
'name' => 'search_agent',
'type' => 'text',
'value' => $values['search_agent'],
'return' => true,
'size' => 0,
],
];
// Search. // Search.
$inputs[] = [ $inputs[] = [
'label' => __('Free search').ui_print_help_tip(__('Search filter by Module name field content'), true), 'label' => __('Search module').ui_print_help_tip(__('Search filter by Module name field content'), true),
'arguments' => [ 'arguments' => [
'name' => 'search', 'name' => 'search',
'type' => 'text', 'type' => 'text',
@ -373,7 +411,9 @@ class ModulesByStatus extends Widget
// Retrieve global - common inputs. // Retrieve global - common inputs.
$values = parent::getPost(); $values = parent::getPost();
$values['groupId'] = \get_parameter('groupId', 0);
$values['search'] = \get_parameter('search', ''); $values['search'] = \get_parameter('search', '');
$values['search_agent'] = \get_parameter('search_agent', '');
$values['status'] = \get_parameter('status', ''); $values['status'] = \get_parameter('status', '');
$values['limit'] = \get_parameter('limit', ''); $values['limit'] = \get_parameter('limit', '');
$values['nodes'] = \get_parameter('nodes', ''); $values['nodes'] = \get_parameter('nodes', '');
@ -386,46 +426,10 @@ class ModulesByStatus extends Widget
/** /**
* Draw widget. * Draw widget.
* *
* @return string; * @return void Html output;
*/ */
public function load() public function load()
{ {
$this->size = parent::getSize();
global $config;
$output = '';
if (is_metaconsole() === true) {
$modules = [];
$servers_ids = array_column(metaconsole_get_servers(), 'id');
foreach ($servers_ids as $server_id) {
try {
$node = new Node((int) $server_id);
$node->connect();
$modules_tmp = $this->getInfoModules(
$this->values['search'],
$this->values['status'],
$this->values['nodes']
);
$modules[$node->id()] = $modules_tmp[0];
$node->disconnect();
} catch (\Exception $e) {
// Unexistent modules.
$node->disconnect();
}
}
} else {
$modules = $this->getInfoModules(
$this->values['search'],
$this->values['status']
);
}
if ($modules !== false && empty($modules) === false) {
// Datatables list. // Datatables list.
try { try {
$info_columns = $this->columns(); $info_columns = $this->columns();
@ -447,7 +451,9 @@ class ModulesByStatus extends Widget
'ajax_data' => [ 'ajax_data' => [
'get_data_ModulesByStatus' => 1, 'get_data_ModulesByStatus' => 1,
'table_id' => $tableId, 'table_id' => $tableId,
'search_agent' => $this->values['search_agent'],
'search' => $this->values['search'], 'search' => $this->values['search'],
'groupId' => $this->values['groupId'],
'status' => $this->values['status'], 'status' => $this->values['status'],
'nodes' => $this->values['nodes'], 'nodes' => $this->values['nodes'],
'disabled_modules' => $this->values['disabled_modules'], 'disabled_modules' => $this->values['disabled_modules'],
@ -487,84 +493,6 @@ class ModulesByStatus extends Widget
} catch (\Exception $e) { } catch (\Exception $e) {
echo $e->getMessage(); echo $e->getMessage();
} }
} else {
$output = '';
$output .= '<div class="container-center">';
$output .= \ui_print_info_message(
__('Not found modules'),
'',
true
);
$output .= '</div>';
return $output;
}
}
/**
* Get info modules.
*
* @param string $search Free search.
* @param string $status Modules status.
*
* @return array Data.
*/
private function getInfoModules(string $search, string $status): array
{
if (empty($search) === false) {
$where = 'tagente_modulo.nombre LIKE "%%'.$search.'%%" AND ';
}
if (str_contains($status, '6') === true) {
$expl = explode(',', $status);
$exist = array_search('6', $expl);
if (isset($exist) === true) {
unset($expl[$exist]);
}
array_push($expl, '1', '2', '3', '4', '5');
$status = implode(',', $expl);
}
if (str_contains($status, '5') === true) {
$expl = explode(',', $status);
$exist = array_search('5', $expl);
if (isset($exist) === true) {
unset($expl[$exist]);
}
array_push($expl, '4', '5');
$status = implode(',', $expl);
}
$where .= sprintf(
'tagente_estado.estado IN (%s)
AND tagente_modulo.delete_pending = 0',
$status
);
$sql = sprintf(
'SELECT
COUNT(*) AS "modules"
FROM tagente_modulo
INNER JOIN tagente
ON tagente_modulo.id_agente = tagente.id_agente
INNER JOIN tagente_estado
ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
WHERE %s',
$where
);
$modules = db_get_all_rows_sql($sql);
if ($modules === false) {
$modules = [];
}
return $modules;
} }
@ -591,7 +519,10 @@ class ModulesByStatus extends Widget
'nombre', 'nombre',
'alias', 'alias',
'server_name', 'server_name',
'last_status_change', [
'text' => 'last_status_change',
'class' => '',
],
'estado', 'estado',
]; ];
} else { } else {
@ -605,7 +536,10 @@ class ModulesByStatus extends Widget
$columns = [ $columns = [
'nombre', 'nombre',
'alias', 'alias',
'last_status_change', [
'text' => 'last_status_change',
'class' => '',
],
'estado', 'estado',
]; ];
} }
@ -654,12 +588,12 @@ class ModulesByStatus extends Widget
$height_counter = (((int) count($nodes_fields)) * 20); $height_counter = (((int) count($nodes_fields)) * 20);
$size = [ $size = [
'width' => 450, 'width' => 470,
'height' => (520 + $height_counter), 'height' => (520 + $height_counter),
]; ];
} else { } else {
$size = [ $size = [
'width' => 450, 'width' => 470,
'height' => 480, 'height' => 480,
]; ];
} }

View File

@ -977,3 +977,19 @@ input.resize_button {
.event-cardboard-widget td { .event-cardboard-widget td {
cursor: pointer; cursor: pointer;
} }
.datatable-container-info-massage:not(:has(.invisible_important)) {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
width: 100%;
}
.info_box_information.datatable-info-massage.info_box_container
.info_box.info.textodialogo {
display: flex;
width: 100%;
justify-content: center;
}