Add ExistsInFileSystem support in Filters. This also includes limiting operators to IS/IS NOT

This commit is contained in:
Isaac Connor 2020-08-16 13:07:21 -04:00
parent 303154c690
commit 77f9f4bffb
2 changed files with 57 additions and 18 deletions

View File

@ -25,6 +25,7 @@ if ( !canView('Events') ) {
require_once('includes/Object.php');
require_once('includes/Storage.php');
require_once('includes/Filter.php');
require_once('includes/FilterTerm.php');
require_once('includes/Monitor.php');
require_once('includes/Zone.php');
require_once('includes/User.php');
@ -53,7 +54,7 @@ if ( isset($_REQUEST['filter']) ) {
#$filter->set($_REQUEST['filter']);
}
$conjunctionTypes = getFilterQueryConjunctionTypes();
$conjunctionTypes = ZM\getFilterQueryConjunctionTypes();
$obracketTypes = array();
$cbracketTypes = array();
@ -83,6 +84,7 @@ $attrTypes = array(
'EndDate' => translate('AttrEndDate'),
'EndTime' => translate('AttrEndTime'),
'EndWeekday' => translate('AttrEndWeekday'),
'ExistsInFileSystem' => translate('ExistsInFileSystem'),
'FilterServerId' => translate('AttrFilterServer'),
'Frames' => translate('AttrFrames'),
'Id' => translate('AttrId'),
@ -122,11 +124,20 @@ $opTypes = array(
'LIKE' => translate('OpLike'),
'NOT LIKE' => translate('OpNotLike'),
);
$is_isnot_opTypes = array(
'IS' => translate('OpIs'),
'IS NOT' => translate('OpIsNot'),
);
$archiveTypes = array(
'0' => translate('ArchUnarchived'),
'1' => translate('ArchArchived')
);
'0' => translate('ArchUnarchived'),
'1' => translate('ArchArchived')
);
$booleanValues = array(
'false' => translate('False'),
'true' => translate('True')
);
$focusWindow = true;
@ -275,6 +286,11 @@ for ( $i=0; $i < count($terms); $i++ ) {
<input type="text" name="filter[Query][terms][<?php echo $i ?>][val]" id="filter[Query][terms][<?php echo $i ?>][val]" value="<?php echo isset($term['val'])?validHtmlStr(str_replace('T', ' ', $term['val'])):'' ?>"/>
<script nonce="<?php echo $cspNonce;?>">$j("[name$='\\[<?php echo $i ?>\\]\\[val\\]']").timepicker({timeFormat: "HH:mm:ss", constrainInput: false}); </script>
</td>
<?php
} elseif ( $term['attr'] == 'ExistsInFileSystem' ) {
?>
<td><?php echo htmlSelect("filter[Query][terms][$i][op]", $is_isnot_opTypes, $term['op']); ?></td>
<td><?php echo htmlSelect("filter[Query][terms][$i][val]", $booleanValues, $term['val']); ?></td>
<?php
} elseif ( $term['attr'] == 'StateId' ) {
?>
@ -459,7 +475,7 @@ if ( ZM_OPT_MESSAGE ) {
</div>
<hr/>
<div id="contentButtons">
<button type="submit" data-on-click-this="submitToEvents"><?php echo translate('ListMatches') ?></button>
<button type="button" data-on-click-this="submitToEvents"><?php echo translate('ListMatches') ?></button>
<button type="button" data-on-click-this="submitToMontageReview"><?php echo translate('ViewMatches') ?></button>
<button type="button" data-on-click-this="submitToExport"><?php echo translate('ExportMatches') ?></button>
<button type="button" name="executeButton" id="executeButton" data-on-click-this="executeFilter"><?php echo translate('Execute') ?></button>

View File

@ -2,12 +2,12 @@ function selectFilter(element) {
element.form.submit();
}
function validateForm( form ) {
function validateForm(form) {
var rows = $j(form).find('tbody').eq(0).find('tr');
var obrCount = 0;
var cbrCount = 0;
for ( var i = 0; i < rows.length; i++ ) {
if (rows.length > 2) {
if ( rows.length > 2 ) {
obrCount += parseInt(form.elements['filter[Query][terms][' + i + '][obr]'].value);
cbrCount += parseInt(form.elements['filter[Query][terms][' + i + '][cbr]'].value);
}
@ -108,10 +108,14 @@ function resetFilter( element ) {
$j('#contentForm')[0].reset();
}
function submitToEvents( element ) {
function submitToEvents(element) {
var form = element.form;
form.action = thisUrl + '?view=events';
history.replaceState(null, null, '?view=filter&' + $j(form).serialize());
//form.action = '?view=events';
//form.submit();
//console.log(form);
//console.log($j(form).serialize());
//history.replaceState(null, null, '?view=filter&' + $j(form).serialize());
window.location.assign('?view=events&'+$j(form).serialize());
}
function submitToMontageReview(element) {
@ -254,6 +258,15 @@ function parseRows(rows) {
}
var monitorVal = inputTds.eq(4).children().val();
inputTds.eq(4).html(monitorSelect).children().val(monitorVal);
} else if ( attr == 'ExistsInFileSystem' ) {
var select = $j('<select></select>').attr('name', queryPrefix + rowNum + '][val]').attr('id', queryPrefix + rowNum + '][val]');
for ( var booleanVal in booleanValues ) {
select.append('<option value="' + booleanVal + '">' + escapeHTML(booleanValues[booleanVal]) + '</option>');
}
var val = inputTds.eq(4).children().val();
if ( ! val ) val = 'false'; // default to the first option false
inputTds.eq(4).html(select).children().val(val);
} else { // Reset to regular text field and operator for everything that isn't special
var textInput = $j('<input></input>').attr('type', 'text').attr('name', queryPrefix + rowNum + '][val]').attr('id', queryPrefix + rowNum + '][val]');
var textVal = inputTds.eq(4).children().val();
@ -263,13 +276,23 @@ function parseRows(rows) {
// Validate the operator
var opSelect = $j('<select></select>').attr('name', queryPrefix + rowNum + '][op]').attr('id', queryPrefix + rowNum + '][op]');
var opVal = inputTds.eq(3).children().val();
if ( ! opVal ) {
// Default to equals so that something gets selected
console.log("No value for operator. Defaulting to =");
opVal = '=';
}
for ( var key in opTypes ) {
opSelect.append('<option value="' + key + '"'+(key == opVal ? ' selected="selected"' : '')+'>' + opTypes[key] + '</option>');
if ( attr == 'ExistsInFileSystem' ) {
if ( ! opVal ) {
// Default to equals so that something gets selected
opVal = 'IS';
}
for ( var key of ['IS', 'IS NOT'] ) {
opSelect.append('<option value="' + key + '"'+(key == opVal ? ' selected="selected"' : '')+'>' + opTypes[key] + '</option>');
}
} else {
if ( ! opVal ) {
// Default to equals so that something gets selected
console.log("No value for operator. Defaulting to =");
opVal = '=';
}
for ( var key in opTypes ) {
opSelect.append('<option value="' + key + '"'+(key == opVal ? ' selected="selected"' : '')+'>' + opTypes[key] + '</option>');
}
}
inputTds.eq(3).html(opSelect).children().val(opVal).chosen({width: "101%"});
if ( attr.endsWith('DateTime') ) { //Start/End DateTime
@ -289,7 +312,7 @@ function parseRows(rows) {
inputTds.eq(2).children().eq(0).attr('id', 'filter'+stringFilter(term));
} //End for each term/row
history.replaceState(null, null, '?view=filter&' + $j('#contentForm').serialize());
}
} // parseRows
function stringFilter(term) {
var termString = '';