Merge branch 'ent-12789-busqueda-por-regex-funciona-mal' into 'develop'

Ent 12789 Búsqueda por regex funciona mal

See merge request artica/pandorafms!6889
This commit is contained in:
Rafael Ameijeiras 2024-01-30 13:52:57 +00:00
commit 35b5644f9c
2 changed files with 44 additions and 25 deletions

View File

@ -1,3 +1,5 @@
/* global $ */
var dt = dt;
var config = config;
@ -141,6 +143,8 @@ if (dt.no_move_elements_to_action === true) {
noMoveElementsToAction = true;
}
var showAlwaysPagination = false;
$(document).ready(function() {
function checkPages() {
if (dt_table.page.info().pages > 1) {
@ -253,7 +257,11 @@ $(document).ready(function() {
$("div.pagination-child-div").hide();
$("div.dataTables_info").hide();
$(`#${dt.id}_wrapper`).hide();
$(`.action_buttons_right_content .pagination-child-div`).hide();
if (showAlwaysPagination) {
$(`.action_buttons_right_content .pagination-child-div`).show();
} else {
$(`.action_buttons_right_content .pagination-child-div`).hide();
}
} else {
$(`.datatable-msg-info-${dt.id}`).hide();
$(`table#${dt.id}`).show();
@ -283,6 +291,12 @@ $(document).ready(function() {
$(`#${dt.form_id}_loading`).remove();
}
if (json.showAlwaysPagination) {
showAlwaysPagination = true;
} else {
showAlwaysPagination = false;
}
if (json.error) {
console.error(json.error);
$(`#error-${dt.id}`).html(json.error);

View File

@ -1229,46 +1229,51 @@ if (is_ajax() === true) {
}
}
$no_return = false;
$regex_validation = false;
if (empty($tmp) === false && $regex !== '') {
$regex_validation = false;
foreach (json_decode(json_encode($tmp), true) as $key => $field) {
if ($key === 'b64') {
continue;
}
$field = strip_tags($field);
if (preg_match('/'.$regex.'/', $field)) {
$regex_validation = true;
}
}
if ($regex_validation === false) {
$no_return = true;
if ($regex_validation === true) {
$carry[] = $tmp;
}
} else {
$carry[] = $tmp;
}
if ($no_return === false) {
$carry[] = $tmp;
return $carry;
} else {
return;
}
return $carry;
}
);
}
$data = array_values(
array_filter(
($data ?? []),
function ($item) {
return (bool) (array) $item;
}
)
);
$count = count($data);
if ($regex !== '') {
$data = array_values(
array_filter(
($data ?? []),
function ($item) {
return (bool) (array) $item;
}
)
);
}
// RecordsTotal && recordsfiltered resultados totales.
echo json_encode(
[
'data' => ($data ?? []),
'buffers' => $buffers,
'recordsTotal' => $count,
'recordsFiltered' => $count,
'data' => ($data ?? []),
'buffers' => $buffers,
'recordsTotal' => $count,
'recordsFiltered' => $count,
'showAlwaysPagination' => (empty($regex) === false) ? true : false,
]
);
} catch (Exception $e) {
@ -2115,7 +2120,7 @@ $in .= $data.'</div>';
$inputs[] = $in;
// REGEX search datatable.
$in = '<div class="filter_input"><label>'.__('Regex search').ui_print_help_tip(__('Regular expresion to filter.'), true).'</label>';
$in = '<div class="filter_input"><label>'.__('Regex search').ui_print_help_tip(__('Filter the results of the current page with regular expressions. It works on Agent name, Event name, Extra ID, Source, Custom data and Comment fields.'), true).'</label>';
$in .= html_print_input_text('regex', $regex, '', '', 255, true);
$in .= '</div>';
$inputs[] = $in;