mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-05-28 04:36:06 -04:00
SearchControls: Don't validate custom variables anymore
It's obsolete since `FlattenedObjectVars` provides column definitions for custom variables.
This commit is contained in:
parent
1f6c95565b
commit
be8e7124c2
1 changed files with 0 additions and 72 deletions
|
|
@ -4,15 +4,10 @@
|
|||
|
||||
namespace Icinga\Module\Icingadb\Common;
|
||||
|
||||
use GuzzleHttp\Psr7\ServerRequest;
|
||||
use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions;
|
||||
use ipl\Html\Html;
|
||||
use ipl\Orm\Exception\InvalidRelationException;
|
||||
use ipl\Orm\Query;
|
||||
use ipl\Orm\UnionQuery;
|
||||
use ipl\Stdlib\Filter;
|
||||
use ipl\Web\Control\SearchBar;
|
||||
use ipl\Web\Control\SearchEditor;
|
||||
use ipl\Web\Url;
|
||||
use ipl\Web\Widget\ContinueWith;
|
||||
|
||||
|
|
@ -20,7 +15,6 @@ trait SearchControls
|
|||
{
|
||||
use \ipl\Web\Compat\SearchControls {
|
||||
\ipl\Web\Compat\SearchControls::createSearchBar as private webCreateSearchBar;
|
||||
\ipl\Web\Compat\SearchControls::createSearchEditor as private webCreateSearchEditor;
|
||||
}
|
||||
|
||||
public function fetchFilterColumns(Query $query): array
|
||||
|
|
@ -28,11 +22,6 @@ trait SearchControls
|
|||
return iterator_to_array(ObjectSuggestions::collectFilterColumns($query->getModel(), $query->getResolver()));
|
||||
}
|
||||
|
||||
private function callHandleRequest(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return the SearchBar
|
||||
*
|
||||
|
|
@ -46,72 +35,11 @@ trait SearchControls
|
|||
{
|
||||
$searchBar = $this->webCreateSearchBar($query, ...$params);
|
||||
|
||||
$columnValidator = function (SearchBar\ValidatedColumn $column) use ($query) {
|
||||
$columnPath = $column->getSearchValue();
|
||||
if (($pos = strpos($columnPath, '.vars.')) !== false) {
|
||||
$column->setMessage(null); // webCreateSearchBar will have set one
|
||||
|
||||
try {
|
||||
if ($query instanceof UnionQuery) {
|
||||
// TODO: This can't be right. Finally solve this god-damn union-query-model structure!!!1
|
||||
$queries = $query->getUnions();
|
||||
$query = end($queries);
|
||||
}
|
||||
|
||||
$relationPath = $query->getResolver()->qualifyPath(
|
||||
substr($columnPath, 0, $pos + 5),
|
||||
$query->getModel()->getTableName()
|
||||
);
|
||||
$query->getResolver()->resolveRelation($relationPath);
|
||||
} catch (InvalidRelationException $e) {
|
||||
$column->setMessage(sprintf(
|
||||
t('"%s" is not a valid relation'),
|
||||
substr($e->getRelation(), 0, $pos)
|
||||
));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$searchBar->on(SearchBar::ON_ADD, $columnValidator)
|
||||
->on(SearchBar::ON_INSERT, $columnValidator)
|
||||
->on(SearchBar::ON_SAVE, $columnValidator)
|
||||
->handleRequest(ServerRequest::fromGlobals());
|
||||
|
||||
Html::tag('div', ['class' => 'filter'])->wrap($searchBar);
|
||||
|
||||
return $searchBar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return the SearchEditor
|
||||
*
|
||||
* @param Query $query The query being filtered
|
||||
* @param Url $redirectUrl Url to redirect to upon success
|
||||
* @param array $preserveParams Query params to preserve when redirecting
|
||||
*
|
||||
* @return SearchEditor
|
||||
*/
|
||||
public function createSearchEditor(Query $query, ...$params): SearchEditor
|
||||
{
|
||||
$editor = $this->webCreateSearchEditor($query, ...$params);
|
||||
|
||||
$editor->on(SearchEditor::ON_VALIDATE_COLUMN, function (Filter\Condition $condition) use ($query) {
|
||||
$column = $condition->getColumn();
|
||||
if (($pos = strpos($column, '.vars.')) !== false) {
|
||||
try {
|
||||
$query->getResolver()->resolveRelation(substr($column, 0, $pos + 5));
|
||||
} catch (InvalidRelationException $e) {
|
||||
throw new SearchBar\SearchException(sprintf(
|
||||
t('"%s" is not a valid relation'),
|
||||
substr($e->getRelation(), 0, $pos)
|
||||
));
|
||||
}
|
||||
}
|
||||
})->handleRequest(ServerRequest::fromGlobals());
|
||||
|
||||
return $editor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return a ContinueWith
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue