From 56c5f324b07f254b3d39ff038ffe94bb7d7ba0ca Mon Sep 17 00:00:00 2001 From: Calvo Date: Thu, 15 Sep 2022 18:01:16 +0200 Subject: [PATCH] Fix alerts metaconsole datatable order --- .../include/ajax/alert_list.ajax.php | 73 ++++++++++--------- .../operation/agentes/alerts_status.php | 8 +- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/pandora_console/include/ajax/alert_list.ajax.php b/pandora_console/include/ajax/alert_list.ajax.php index bf2bf6bacc..b4c9fc571f 100644 --- a/pandora_console/include/ajax/alert_list.ajax.php +++ b/pandora_console/include/ajax/alert_list.ajax.php @@ -885,12 +885,47 @@ if ($get_agent_alerts_datatable === true) { } } + // Order and pagination metacosole. + if (is_metaconsole() === true) { + + + /** + * Auxiliar Ordenation function + * + * @param string $sort Direction of sort. + * @param string $sortField Field for perform the sorting. + */ + function arrayOutputSorting($sort, $sortField) + { + return function ($a, $b) use ($sort, $sortField) { + if ($sort === 'asc') { + if (is_string($a[$sortField]) === true) { + return strnatcmp($a[$sortField], $b[$sortField]); + } else { + return ($a[$sortField] - $b[$sortField]); + } + } else { + if (is_string($a[$sortField]) === true) { + return strnatcmp($b[$sortField], $a[$sortField]); + } else { + return ($a[$sortField] + $b[$sortField]); + } + } + }; + } + + + usort($alerts['alerts_simple'], arrayOutputSorting($sort, $sortField)); + $data = array_slice($alerts['alerts_simple'], $start, $length); + } + $data = []; if ($alerts['alerts_simple']) { foreach ($alerts['alerts_simple'] as $alert) { $data[] = ui_format_alert_row($alert, true, $url, 'font-size: 7pt;'); } + $data = array_reduce( $data, function ($carry, $row) { @@ -902,9 +937,9 @@ if ($get_agent_alerts_datatable === true) { $tmp->policy = $row[0]; $tmp->standby = $row[1]; $tmp->force = $row[2]; - $tmp->agent = $row[3]; - $tmp->module = $row[4]; - $tmp->template = $row[5]; + $tmp->agent_name = $row[3]; + $tmp->agent_module_name = $row[4]; + $tmp->template_name = $row[5]; $tmp->action = $row[6]; $tmp->lastFired = $row[7]; $tmp->status = $row[8]; @@ -916,38 +951,6 @@ if ($get_agent_alerts_datatable === true) { ); } - if (is_metaconsole() === true) { - - - /** - * Auxiliar Ordenation function - * - * @param string $sort Direction of sort. - * @param string $sortField Field for perform the sorting. - */ - function arrayOutputSorting($sort, $sortField) - { - return function ($a, $b) use ($sort, $sortField) { - if ($sort === 'asc') { - if (is_string($a->$sortField) === true) { - return strnatcmp($a->$sortField, $b->$sortField); - } else { - return ($a->$sortField - $b->$sortField); - } - } else { - if (is_string($a->$sortField) === true) { - return strnatcmp($b->$sortField, $a->$sortField); - } else { - return ($a->$sortField + $b->$sortField); - } - } - }; - } - - - usort($data, arrayOutputSorting($sort, $sortField)); - $data = array_slice($data, $start, $length); - } // Datatables format: RecordsTotal && recordsfiltered. echo json_encode( diff --git a/pandora_console/operation/agentes/alerts_status.php b/pandora_console/operation/agentes/alerts_status.php index 65f8537b17..9dcc079baf 100755 --- a/pandora_console/operation/agentes/alerts_status.php +++ b/pandora_console/operation/agentes/alerts_status.php @@ -294,7 +294,7 @@ if ($free_search != '') { $columns = array_merge( $columns, - ['agent'] + ['agent_name'] ); } @@ -309,8 +309,8 @@ if ($free_search != '') { $columns = array_merge( $columns, - ['module'], - ['template'], + ['agent_module_name'], + ['template_name'], ['action'], ['lastFired'], ['status'] @@ -359,7 +359,7 @@ if ($free_search != '') { ], 'drawCallback' => 'alerts_table_controls()', 'order' => [ - 'field' => 'module', + 'field' => 'module_name', 'direction' => 'asc', ], 'zeroRecords' => __('No alerts found'),