Adjust customVarSources and minor improvements

This commit is contained in:
Bastian Lederer 2026-04-09 07:54:22 +02:00
parent 47f4c4c562
commit 0e6d03f3da
4 changed files with 18 additions and 36 deletions

View file

@ -213,17 +213,8 @@ class HostsController extends Controller
public function suggestColumnsAction()
{
$this->suggestColumns(Host::class, [
'checkcommand' => t('Checkcommand %s', '..<customvar-name>'),
'eventcommand' => t('Eventcommand %s', '..<customvar-name>'),
'host' => t('Host %s', '..<customvar-name>'),
'hostgroup' => t('Hostgroup %s', '..<customvar-name>'),
'notification' => t('Notification %s', '..<customvar-name>'),
'notificationcommand' => t('Notificationcommand %s', '..<customvar-name>'),
'service' => t('Service %s', '..<customvar-name>'),
'servicegroup' => t('Servicegroup %s', '..<customvar-name>'),
'timeperiod' => t('Timeperiod %s', '..<customvar-name>'),
'user' => t('Contact %s', '..<customvar-name>'),
'usergroup' => t('Contactgroup %s', '..<customvar-name>')
'service' => t('Service %s', '..<customvar-name>')
]);
}

View file

@ -230,17 +230,8 @@ class ServicesController extends Controller
public function suggestColumnsAction()
{
$this->suggestColumns(Service::class, [
'checkcommand' => t('Checkcommand %s', '..<customvar-name>'),
'eventcommand' => t('Eventcommand %s', '..<customvar-name>'),
'host' => t('Host %s', '..<customvar-name>'),
'hostgroup' => t('Hostgroup %s', '..<customvar-name>'),
'notification' => t('Notification %s', '..<customvar-name>'),
'notificationcommand' => t('Notificationcommand %s', '..<customvar-name>'),
'service' => t('Service %s', '..<customvar-name>'),
'servicegroup' => t('Servicegroup %s', '..<customvar-name>'),
'timeperiod' => t('Timeperiod %s', '..<customvar-name>'),
'user' => t('Contact %s', '..<customvar-name>'),
'usergroup' => t('Contactgroup %s', '..<customvar-name>')
'service' => t('Service %s', '..<customvar-name>')
]);
}

View file

@ -105,6 +105,20 @@ class QueryColumnsProvider implements IteratorAggregate
return $this;
}
/**
* Set columns to exclude from the suggestions
*
* @param array $columns
*
* @return $this
*/
public function setExcludedColumns(array $columns): static
{
$this->excludedColumns = $columns;
return $this;
}
public function getIterator(): Generator
{
$exactVarSearches = [];
@ -175,7 +189,7 @@ class QueryColumnsProvider implements IteratorAggregate
);
foreach ($columns as $columnName => $columnMeta) {
if (
! in_array($columnName, $this->excludedColumns)
! in_array($columnName, $this->excludedColumns, true)
&& $this->matchSuggestion($columnName, $columnMeta, $this->searchTerm)
) {
yield [
@ -429,20 +443,6 @@ class QueryColumnsProvider implements IteratorAggregate
return $this;
}
/**
* Set columns to exclude from the suggestions
*
* @param array $columns
*
* @return $this
*/
public function setExcludedColumns(array $columns): static
{
$this->excludedColumns = $columns;
return $this;
}
/**
* Check whether the given column path and label match the search term
*

View file

@ -514,7 +514,7 @@ class Controller extends CompatController
$query = $model::on($this->getDb());
$provider = (new QueryColumnsProvider($query))->setCustomVarSources($customVarSources);
$suggestions = new SearchSuggestions($provider);
$suggestions->forRequest(ServerRequest::fromGlobals());
$suggestions->forRequest($this->getServerRequest());
$provider->forSuggestions($suggestions);
$this->getDocument()->addHtml($suggestions);
}