From 77f9f4bffb03956871dbe9f7a0da66312cf763bf Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 16 Aug 2020 13:07:21 -0400 Subject: [PATCH] Add ExistsInFileSystem support in Filters. This also includes limiting operators to IS/IS NOT --- web/skins/classic/views/filter.php | 26 ++++++++++++--- web/skins/classic/views/js/filter.js | 49 ++++++++++++++++++++-------- 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/web/skins/classic/views/filter.php b/web/skins/classic/views/filter.php index f7fd5444d..5d18364f5 100644 --- a/web/skins/classic/views/filter.php +++ b/web/skins/classic/views/filter.php @@ -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++ ) { + + + @@ -459,7 +475,7 @@ if ( ZM_OPT_MESSAGE ) {
- + diff --git a/web/skins/classic/views/js/filter.js b/web/skins/classic/views/js/filter.js index bcf67c00b..b09e2233b 100644 --- a/web/skins/classic/views/js/filter.js +++ b/web/skins/classic/views/js/filter.js @@ -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('').attr('name', queryPrefix + rowNum + '][val]').attr('id', queryPrefix + rowNum + '][val]'); + for ( var booleanVal in booleanValues ) { + select.append(''); + } + 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('').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('').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(''); + if ( attr == 'ExistsInFileSystem' ) { + if ( ! opVal ) { + // Default to equals so that something gets selected + opVal = 'IS'; + } + for ( var key of ['IS', 'IS NOT'] ) { + opSelect.append(''); + } + } 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(''); + } } 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 = '';