mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-05-28 04:36:06 -04:00
ObjectSuggestions: Allow to use a fixed set of columns
This commit is contained in:
parent
eb85337fc7
commit
e906b1d632
1 changed files with 20 additions and 2 deletions
|
|
@ -43,6 +43,9 @@ class ObjectSuggestions extends Suggestions
|
|||
/** @var array */
|
||||
protected $customVarSources;
|
||||
|
||||
/** @var ?array<string, string> */
|
||||
protected ?array $fixedColumns = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->customVarSources = [
|
||||
|
|
@ -154,7 +157,7 @@ class ObjectSuggestions extends Suggestions
|
|||
if (strpos($column, ' ') !== false) {
|
||||
// $column may be a label
|
||||
list($path, $_) = Seq::find(
|
||||
self::collectFilterColumns($query->getModel(), $query->getResolver()),
|
||||
$this->fixedColumns ?? self::collectFilterColumns($query->getModel(), $query->getResolver()),
|
||||
$column,
|
||||
false
|
||||
);
|
||||
|
|
@ -269,7 +272,8 @@ class ObjectSuggestions extends Suggestions
|
|||
// Ordinary columns comes after exact matches,
|
||||
// or if there ar no exact matches they come first
|
||||
$titleAdded = false;
|
||||
foreach (self::collectFilterColumns($model, $query->getResolver()) as $columnName => $columnMeta) {
|
||||
$columns = $this->fixedColumns ?? self::collectFilterColumns($query->getModel(), $query->getResolver());
|
||||
foreach ($columns as $columnName => $columnMeta) {
|
||||
if ($this->matchSuggestion($columnName, $columnMeta, $searchTerm)) {
|
||||
if ($titleAdded === false) {
|
||||
$this->addHtml(HtmlElement::create(
|
||||
|
|
@ -518,4 +522,18 @@ class ObjectSuggestions extends Suggestions
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide suggestions based on a fixed set of columns
|
||||
*
|
||||
* @param array<string, string> $columns
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withFixedColumns(array $columns): static
|
||||
{
|
||||
$this->fixedColumns = $columns;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue