Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilize enhanced search constraints #611

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion library/Icingadb/Model/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Icinga\Module\Icingadb\Model\Behavior\ReRoute;
use Icinga\Module\Icingadb\Model\Behavior\Timestamp;
use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behavior\NonTextMatch;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;
use ipl\Orm\Relations;
Expand Down Expand Up @@ -57,7 +58,14 @@ public function getColumnDefinitions()
'name' => t('Comment Name'),
'author' => t('Comment Author'),
'text' => t('Comment Text'),
'entry_type' => t('Comment Type'),
'entry_type' => [
'label' => t('Comment Type'),
'type' => 'enum',
'allowed_values' => [
'comment' => t('Comment'),
'ack' => t('Acknowledgement')
]
],
'entry_time' => t('Comment Entry Time'),
'is_persistent' => t('Comment Is Persistent'),
'is_sticky' => t('Comment Is Sticky'),
Expand Down Expand Up @@ -102,6 +110,8 @@ public function createBehaviors(Behaviors $behaviors)
'properties_checksum',
'zone_id'
]));

$behaviors->add(new NonTextMatch());
}

public function createRelations(Relations $relations)
Expand Down
14 changes: 12 additions & 2 deletions library/Icingadb/Model/ServiceState.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ public function getColumnDefinitions()
{
return [
'environment_id' => t('Environment Id'),
'state_type' => t('Service State Type'),
'state_type' => [
'label' => t('Service State Type'),
'type' => 'enum',
'allowed_values' => [
'hard' => t('Hard'),
'soft' => t('Soft')
]
],
'soft_state' => t('Service Soft State'),
'hard_state' => t('Service Hard State'),
'previous_soft_state' => t('Service Previous Soft State'),
'previous_hard_state' => t('Service Previous Hard State'),
'check_attempt' => t('Service Check Attempt No.'),
'check_attempt' => [
'label' => t('Service Check Attempt No.'),
'type' => 'number'
],
'severity' => t('Service State Severity'),
'output' => t('Service Output'),
'long_output' => t('Service Long Output'),
Expand Down
3 changes: 3 additions & 0 deletions library/Icingadb/Model/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Icinga\Module\Icingadb\Model\Behavior\BoolCast;
use Icinga\Module\Icingadb\Model\Behavior\Timestamp;
use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behavior\NonTextMatch;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;

Expand Down Expand Up @@ -79,5 +80,7 @@ public function createBehaviors(Behaviors $behaviors)
'acknowledgement_comment_id',
'last_comment_id'
]));

$behaviors->add(new NonTextMatch());
}
}
17 changes: 15 additions & 2 deletions library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ipl\Orm\Exception\InvalidColumnException;
use ipl\Orm\Exception\InvalidRelationException;
use ipl\Orm\Model;
use ipl\Orm\Query;
use ipl\Orm\Relation;
use ipl\Orm\Relation\BelongsToMany;
use ipl\Orm\Relation\HasOne;
Expand All @@ -37,6 +38,9 @@ class ObjectSuggestions extends Suggestions
/** @var Model */
protected $model;

/** @var Query */
protected $query;

/** @var array */
protected $customVarSources;

Expand Down Expand Up @@ -91,6 +95,15 @@ public function getModel(): Model
return $this->model;
}

public function getQuery(): Query
{
if ($this->query === null) {
$this->query = ($this->getModel())::on($this->getDb());
}

return $this->query;
}

protected function shouldShowRelationFor(string $column): bool
{
if (strpos($column, '.vars.') !== false) {
Expand Down Expand Up @@ -131,7 +144,7 @@ protected function createQuickSearchFilter($searchTerm)
protected function fetchValueSuggestions($column, $searchTerm, Filter\Chain $searchFilter)
{
$model = $this->getModel();
$query = $model::on($this->getDb());
$query = $this->getQuery();
$query->limit(static::DEFAULT_LIMIT);

if (strpos($column, ' ') !== false) {
Expand Down Expand Up @@ -202,7 +215,7 @@ protected function fetchValueSuggestions($column, $searchTerm, Filter\Chain $sea
protected function fetchColumnSuggestions($searchTerm)
{
$model = $this->getModel();
$query = $model::on($this->getDb());
$query = $this->getQuery();

// Ordinary columns first
foreach (self::collectFilterColumns($model, $query->getResolver()) as $columnName => $columnMeta) {
Expand Down