From 87b66b11f032df91048996684eb2851cb1f88919 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 13 Jul 2022 15:13:30 +0200 Subject: [PATCH] ObjectSuggestions: Implement method `shouldShowRelationFor()` --- .../Control/SearchBar/ObjectSuggestions.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php b/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php index 87a42179..23c64cdf 100644 --- a/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php +++ b/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php @@ -91,6 +91,29 @@ class ObjectSuggestions extends Suggestions return $this->model; } + protected function shouldShowRelationFor(string $column): bool + { + if (strpos($column, '.vars.') !== false) { + return false; + } + + $tableName = $this->getModel()->getTableName(); + $columnPath = explode('.', $column); + + switch (count($columnPath)) { + case 3: + if ($columnPath[1] !== 'state' || ! in_array($tableName, ['host', 'service'])) { + return true; + } + + // For host/service state relation columns apply the same rules + case 2: + return $columnPath[0] !== $tableName; + default: + return true; + } + } + protected function createQuickSearchFilter($searchTerm) { $model = $this->getModel();