Fix(tags): "No Tag" filter now works properly.

This commit is contained in:
Simpler1
2025-12-08 15:09:01 -05:00
parent 43f281c005
commit 3a0d8d7c8f
5 changed files with 21 additions and 22 deletions

View File

@@ -346,7 +346,7 @@ sub Sql {
$self->{Sql} .= ' LIKE '.$value;
} elsif ( $term->{op} eq 'NOT LIKE' ) {
$self->{Sql} .= ' NOT LIKE '.$value;
} elsif ( $term->{attr} eq 'Tags' and ($term->{op} eq 'LIKE' or $term->{op} eq 'IS') and $term->{val} eq '') {
} elsif ( $term->{attr} eq 'Tags' and ($term->{op} eq 'LIKE' or $term->{op} eq 'IS') and $term->{val} eq 0) {
$self->{Sql} .= 'NOT EXISTS (SELECT NULL FROM `Events_Tags` AS ET WHERE ET.EventId = E.Id)';
} else {
$self->{Sql} .= ' '.$term->{op}.' '.$value;

View File

@@ -46,7 +46,7 @@ if (!empty($_REQUEST['MonitorId'])) {
$filter->addTerm(array('cnj'=>'and', 'attr'=>'MonitorId', 'op'=> '=', 'val'=>$_REQUEST['MonitorId']));
}
if (!empty($_REQUEST['Tag'])) {
$filter->addTerm(array('cnj'=>'and', 'attr'=>'Tag', 'op'=>'=', 'val'=>''));
$filter->addTerm(array('cnj'=>'and', 'attr'=>'Tag', 'op'=>'=', 'val'=>$_REQUEST['Tag']));
}
// Search contains a user entered string to search on

View File

@@ -924,6 +924,9 @@ class Filter extends ZM_Object {
return self::$archiveTypes;
}
//
// This displays filters from the filters page.
//
public function widget() {
$html = '<table id="fieldsTable" class="filterTable"><tbody>';
$opTypes = $this->opTypes();
@@ -976,7 +979,7 @@ class Filter extends ZM_Object {
}
}
}
$availableTags = array(''=>translate('No Tag'));
$availableTags = array(translate('No Tag'));
foreach ( dbFetchAll('SELECT Id, Name FROM Tags ORDER BY lower(`Name`) ASC') AS $tag ) {
$availableTags[$tag['Id']] = validHtmlStr($tag['Name']);
}
@@ -1011,14 +1014,11 @@ class Filter extends ZM_Object {
$html .= '<td>'.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op'], ['class'=>'chosen chosen-full-width']).'</td>'.PHP_EOL;
$options = ['class'=>'chosen chosen-full-width', 'multiple'=>'multiple'];
$selected = explode(',', $term['val']);
if (count($selected) == 1 and !$selected[0]) {
$selected = null;
}
$html .= '<td>'.htmlSelect("filter[Query][terms][$i][val]", $availableTags, $selected, $options).'</td>'.PHP_EOL;
// ZM\Debug('$availableTags: '.$availableTags);
// ZM\Debug('$selected: '.$selected);
// These echo statements print these variables at the top of the view for debugging.
// echo '<div style="background-color:orange"><pre>availableTags: '; print_r($availableTags); echo '</pre></div>';
// echo '<div style="background-color:lightblue"><pre>selected: '; print_r($selected); echo '</pre></div>';
// echo '<div style="background-color:green"><pre>options: '; print_r($options); echo '</pre></div>';
} else if ( $term['attr'] == 'DateTime' || $term['attr'] == 'StartDateTime' || $term['attr'] == 'EndDateTime') {
$html .= '<td>'.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op'], ['class'=>'chosen chosen-full-width']).'</td>'.PHP_EOL;
@@ -1088,6 +1088,9 @@ class Filter extends ZM_Object {
return $html;
} # end function widget()
//
// This displays filters from the events page.
//
public function simple_widget() {
$html = '<div id="fieldsTable" class="filterTable">';
$terms = $this->terms();
@@ -1112,7 +1115,7 @@ class Filter extends ZM_Object {
for ( $i = 0; $i < 7; $i++ ) {
$weekdays[$i] = date('D', mktime(12, 0, 0, 1, $i+1, 2001));
}
$availableTags = array(''=>translate('No Tag'));
$availableTags = array(translate('No Tag'));
foreach ( dbFetchAll('SELECT Id, Name FROM Tags ORDER BY lower(`Name`) ASC') AS $tag ) {
$availableTags[$tag['Id']] = validHtmlStr($tag['Name']);
}
@@ -1146,11 +1149,7 @@ class Filter extends ZM_Object {
$html .= htmlSelect("filter[Query][terms][$i][val]", $archiveTypes, $term['val'],['id'=>'filterArchived', 'class'=>'chosen chosen-auto-width']).PHP_EOL;
$html .= '</span>';
} else if ( $term['attr'] == 'Tags' ) {
$selected = empty($term['val']) ? [] : json_decode($term['val']);
// echo '<pre>selected: '; print_r($selected); echo '</pre>';
if (count($selected) == 1 and !$selected[0]) {
$selected = null;
}
$selected = explode(',', $term['val']);
$options = ['id'=>'filterTags', 'class'=>'chosen chosen-auto-width', 'multiple'=>'multiple', 'data-placeholder'=>translate('All Tags')];
if (isset($term['cookie'])) {
$options['data-cookie'] = $term['cookie'];
@@ -1158,10 +1157,10 @@ class Filter extends ZM_Object {
if (!$selected and isset($_COOKIE[$term['cookie']]) and $_COOKIE[$term['cookie']])
$selected = json_decode($_COOKIE[$term['cookie']]);
}
// These echo statements print these variables at the top of the view.
// echo '<pre>availableTags: '; print_r($availableTags); echo '</pre>';
// echo '<pre>selected: '; print_r($selected); echo '</pre>';
// echo '<pre>options: '; print_r($options); echo '</pre>';
// These echo statements print these variables at the top of the view for debugging.
// echo '<div style="background-color:orange"><pre>availableTags: '; print_r($availableTags); echo '</pre></div>';
// echo '<div style="background-color:lightblue"><pre>selected: '; print_r($selected); echo '</pre></div>';
// echo '<div style="background-color:green"><pre>options: '; print_r($options); echo '</pre></div>';
$html .= '<span class="term-value-wrapper">';
$html .= htmlSelect("filter[Query][terms][$i][val]", $availableTags, $selected, $options).PHP_EOL;

View File

@@ -343,7 +343,7 @@ class FilterTerm {
$subterms[] = $subterm;
}
$sql .= '('.implode(' OR ', $subterms).')';
} elseif (($this->attr === 'Tags') && ($values[0] === '')) {
} elseif (($this->attr === 'Tags') && ($values[0] === "'0'")) {
$sql .= 'NOT EXISTS (SELECT NULL FROM Events_Tags AS ET WHERE ET.EventId = E.Id)';
} else {
$sql .= $this->sql_attr();

View File

@@ -132,7 +132,7 @@ foreach (ZM\Zone::find([], ['order'=>'lower(`Name`) ASC']) as $zone ) {
}
}
$availableTags = array(''=>translate('No Tag'));
$availableTags = array(translate('No Tag'));
foreach ( dbFetchAll('SELECT Id, Name FROM Tags ORDER BY LastAssignedDate DESC') AS $tag ) {
$availableTags[$tag['Id']] = validHtmlStr($tag['Name']);
}