Fix alerts metaconsole datatable order

This commit is contained in:
Calvo 2022-09-15 18:01:16 +02:00
parent 544497d2ba
commit 56c5f324b0
2 changed files with 42 additions and 39 deletions

View File

@ -885,37 +885,7 @@ if ($get_agent_alerts_datatable === true) {
} }
} }
$data = []; // Order and pagination metacosole.
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) {
// Transforms array of arrays $data into an array
// of objects, making a post-process of certain fields.
$tmp = new stdClass();
// Standby.
$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->action = $row[6];
$tmp->lastFired = $row[7];
$tmp->status = $row[8];
$tmp->validate = $row[9];
$carry[] = $tmp;
return $carry;
}
);
}
if (is_metaconsole() === true) { if (is_metaconsole() === true) {
@ -929,26 +899,59 @@ if ($get_agent_alerts_datatable === true) {
{ {
return function ($a, $b) use ($sort, $sortField) { return function ($a, $b) use ($sort, $sortField) {
if ($sort === 'asc') { if ($sort === 'asc') {
if (is_string($a->$sortField) === true) { if (is_string($a[$sortField]) === true) {
return strnatcmp($a->$sortField, $b->$sortField); return strnatcmp($a[$sortField], $b[$sortField]);
} else { } else {
return ($a->$sortField - $b->$sortField); return ($a[$sortField] - $b[$sortField]);
} }
} else { } else {
if (is_string($a->$sortField) === true) { if (is_string($a[$sortField]) === true) {
return strnatcmp($b->$sortField, $a->$sortField); return strnatcmp($b[$sortField], $a[$sortField]);
} else { } else {
return ($a->$sortField + $b->$sortField); return ($a[$sortField] + $b[$sortField]);
} }
} }
}; };
} }
usort($data, arrayOutputSorting($sort, $sortField)); usort($alerts['alerts_simple'], arrayOutputSorting($sort, $sortField));
$data = array_slice($data, $start, $length); $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) {
// Transforms array of arrays $data into an array
// of objects, making a post-process of certain fields.
$tmp = new stdClass();
// Standby.
$tmp->policy = $row[0];
$tmp->standby = $row[1];
$tmp->force = $row[2];
$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];
$tmp->validate = $row[9];
$carry[] = $tmp;
return $carry;
}
);
}
// Datatables format: RecordsTotal && recordsfiltered. // Datatables format: RecordsTotal && recordsfiltered.
echo json_encode( echo json_encode(
[ [

View File

@ -294,7 +294,7 @@ if ($free_search != '') {
$columns = array_merge( $columns = array_merge(
$columns, $columns,
['agent'] ['agent_name']
); );
} }
@ -309,8 +309,8 @@ if ($free_search != '') {
$columns = array_merge( $columns = array_merge(
$columns, $columns,
['module'], ['agent_module_name'],
['template'], ['template_name'],
['action'], ['action'],
['lastFired'], ['lastFired'],
['status'] ['status']
@ -359,7 +359,7 @@ if ($free_search != '') {
], ],
'drawCallback' => 'alerts_table_controls()', 'drawCallback' => 'alerts_table_controls()',
'order' => [ 'order' => [
'field' => 'module', 'field' => 'module_name',
'direction' => 'asc', 'direction' => 'asc',
], ],
'zeroRecords' => __('No alerts found'), 'zeroRecords' => __('No alerts found'),