get adv search working in newlog view

This commit is contained in:
Andrew Bauer
2020-09-24 11:05:34 -05:00
parent 88f1dcca13
commit e4a1bacbbf
2 changed files with 36 additions and 21 deletions

View File

@@ -21,10 +21,11 @@ $columns = array('TimeKey', 'Component', 'ServerId', 'Pid', 'Code', 'Message', '
$col_alt = array('DateTime', 'Server');
// Search contains a user entered string to search on
$search = '';
if ( isset($_REQUEST['search']) ) {
$search = $_REQUEST['search'];
}
$search = isset($_REQUEST['search']) ? $_REQUEST['search'] : '';
// Advanced search contains an array of "column name" => "search text" pairs
// Bootstrap table sends json_ecoded array, which we must decode
$advsearch = isset($_REQUEST['filter']) ? json_decode($_REQUEST['filter'], JSON_OBJECT_AS_ARRAY) : array();
// Sort specifies the name of the column to sort on
$sort = 'TimeKey';
@@ -65,7 +66,26 @@ $data = array();
$query = array();
$query['values'] = array();
$likes = array();
if ( $search != '' ) {
$where = '';
// There are two search bars in the log view, normal and advanced
// Making an exuctive decision to ignore the normal search, when advanced search is in use
// Alternatively we could try to do both
if ( count($advsearch) ) {
foreach ( $advsearch as $col=>$text ) {
if ( !in_array($col, array_merge($columns, $col_alt)) ) {
ZM\Error("'$col' is not a sortable column name");
continue;
}
$text = '%' .$text. '%';
array_push($likes, $col.' LIKE ?');
array_push($query['values'], $text);
}
$wherevalues = $query['values'];
$where = ' WHERE (' .implode(' OR ', $likes). ')';
} else if ( $search != '' ) {
$search = '%' .$search. '%';
foreach ( $columns as $col ) {
array_push($likes, $col.' LIKE ?');
@@ -73,20 +93,18 @@ if ( $search != '' ) {
}
$wherevalues = $query['values'];
$where = ' WHERE (' .implode(' OR ', $likes). ')';
$query['sql'] = 'SELECT ' .$col_str. ' FROM `' .$table. '` ' .$where. ' ORDER BY ' .$sort. ' ' .$order. ' LIMIT ?, ?';
array_push($query['values'], $offset, $limit);
} else {
$query['sql'] = 'SELECT ' .$col_str. ' FROM `' .$table. '` ORDER BY ' .$sort. ' ' .$order. ' LIMIT ?, ?';
$query['values'] = array($offset, $limit);
}
}
$query['sql'] = 'SELECT ' .$col_str. ' FROM `' .$table. '` ' .$where. ' ORDER BY ' .$sort. ' ' .$order. ' LIMIT ?, ?';
array_push($query['values'], $offset, $limit);
//ZM\Warning('Calling the following sql query: ' .$query['sql']);
$data['totalNotFiltered'] = dbFetchOne('SELECT count(*) AS Total FROM ' .$table, 'Total');
if ( $search == '' ) {
$data['total'] = $data['totalNotFiltered'];
} else {
if ( $search != '' || count($advsearch) ) {
$data['total'] = dbFetchOne('SELECT count(*) AS Total FROM ' .$table.$where , 'Total', $wherevalues);
} else {
$data['total'] = $data['totalNotFiltered'];
}
if ( !$Servers )

View File

@@ -28,14 +28,11 @@ var params =
// Called by bootstrap-table to retrieve zm log data
function ajaxRequest(params) {
$j.getJSON(thisUrl + '?view=request&request=newlog&task=query', params.data)
.done(function(res) {
//console.log('total: ' + res.total);
//console.log('totalNotFiltered: ' + res.totalNotFiltered);
console.log(JSON.stringify(params));
.done(function(data) {
//console.log('Ajax parameters: ' + JSON.stringify(params));
// rearrange the result into what bootstrap-table expects
var data = {total: res.total, totalNotFiltered: res.totalNotFiltered, rows: res.rows};
params.success(data);
updateHeaderStats(res);
params.success({total: data.total, totalNotFiltered: data.totalNotFiltered, rows: data.rows});
updateHeaderStats(data);
})
.fail(logAjaxFail);
}