From b469a88428e3bbb7fece7a9281054337a320fbfd Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 6 Nov 2020 15:51:00 +0100 Subject: [PATCH] Handle search bar validity in all controllers --- application/controllers/CommentsController.php | 17 +++++++++++++++-- application/controllers/DowntimesController.php | 17 +++++++++++++++-- application/controllers/HistoryController.php | 17 +++++++++++++++-- .../controllers/HostgroupsController.php | 17 +++++++++++++++-- application/controllers/HostsController.php | 14 ++++++++++++-- .../controllers/NotificationsController.php | 17 +++++++++++++++-- .../controllers/ServicegroupsController.php | 17 +++++++++++++++-- application/controllers/ServicesController.php | 14 ++++++++++++-- application/controllers/TacticalController.php | 15 ++++++++++++--- .../controllers/UsergroupsController.php | 17 +++++++++++++++-- application/controllers/UsersController.php | 17 +++++++++++++++-- 11 files changed, 156 insertions(+), 23 deletions(-) diff --git a/application/controllers/CommentsController.php b/application/controllers/CommentsController.php index 0e1d3263..397ef06c 100644 --- a/application/controllers/CommentsController.php +++ b/application/controllers/CommentsController.php @@ -15,6 +15,7 @@ use Icinga\Module\Icingadb\Widget\ShowMore; use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentsCommandForm; use ipl\Html\HtmlDocument; use ipl\Html\HtmlString; +use ipl\Web\Filter\QueryString; use ipl\Web\Url; use ipl\Web\Widget\ActionLink; use ipl\Web\Widget\Icon; @@ -58,7 +59,19 @@ class CommentsController extends Controller $viewModeSwitcher->getViewModeParam() ]); - $this->filter($comments, $searchBar->getFilter()); + if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { + if ($searchBar->hasBeenSubmitted()) { + $filter = QueryString::parse($this->getFilter()->toQueryString()); + } else { + $this->addControl($searchBar); + $this->sendMultipartUpdate(); + return; + } + } else { + $filter = $searchBar->getFilter(); + } + + $this->filter($comments, $filter); $comments->peekAhead($compact); @@ -86,7 +99,7 @@ class CommentsController extends Controller ); } - if ($searchBar->hasBeenSent()) { + if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { $viewModeSwitcher->setUrl($searchBar->getRedirectUrl()); $this->sendMultipartUpdate($viewModeSwitcher); } diff --git a/application/controllers/DowntimesController.php b/application/controllers/DowntimesController.php index 467df39f..f6ea54f2 100644 --- a/application/controllers/DowntimesController.php +++ b/application/controllers/DowntimesController.php @@ -15,6 +15,7 @@ use Icinga\Module\Icingadb\Widget\ShowMore; use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimesCommandForm; use ipl\Html\HtmlDocument; use ipl\Html\HtmlString; +use ipl\Web\Filter\QueryString; use ipl\Web\Url; use ipl\Web\Widget\ActionLink; use ipl\Web\Widget\Icon; @@ -63,7 +64,19 @@ class DowntimesController extends Controller $viewModeSwitcher->getViewModeParam() ]); - $this->filter($downtimes, $searchBar->getFilter()); + if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { + if ($searchBar->hasBeenSubmitted()) { + $filter = QueryString::parse($this->getFilter()->toQueryString()); + } else { + $this->addControl($searchBar); + $this->sendMultipartUpdate(); + return; + } + } else { + $filter = $searchBar->getFilter(); + } + + $this->filter($downtimes, $filter); $downtimes->peekAhead($compact); @@ -91,7 +104,7 @@ class DowntimesController extends Controller ); } - if ($searchBar->hasBeenSent()) { + if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { $viewModeSwitcher->setUrl($searchBar->getRedirectUrl()); $this->sendMultipartUpdate($viewModeSwitcher); } diff --git a/application/controllers/HistoryController.php b/application/controllers/HistoryController.php index 0c9cab6c..6d48fe86 100644 --- a/application/controllers/HistoryController.php +++ b/application/controllers/HistoryController.php @@ -11,6 +11,7 @@ use Icinga\Module\Icingadb\Web\Controller; use Icinga\Module\Icingadb\Widget\ItemList\HistoryList; use Icinga\Module\Icingadb\Widget\ShowMore; use ipl\Sql\Sql; +use ipl\Web\Filter\QueryString; use ipl\Web\Url; class HistoryController extends Controller @@ -52,6 +53,18 @@ class HistoryController extends Controller $sortControl->getSortParam() ]); + if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { + if ($searchBar->hasBeenSubmitted()) { + $filter = QueryString::parse($this->getFilter()->toQueryString()); + } else { + $this->addControl($searchBar); + $this->sendMultipartUpdate(); + return; + } + } else { + $filter = $searchBar->getFilter(); + } + $history->peekAhead(); $history->limit($limitControl->getLimit()); if ($page > 1) { @@ -62,7 +75,7 @@ class HistoryController extends Controller } } - $this->filter($history, $searchBar->getFilter()); + $this->filter($history, $filter); $history->getSelectBase() // Make sure we'll fetch service history entries only for services which still exist ->where(['history.service_id IS NULL', 'history_service.id IS NOT NULL'], Sql::ANY); @@ -97,7 +110,7 @@ class HistoryController extends Controller $this->addContent($historyList); } - if ($searchBar->hasBeenSent()) { + if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { $this->sendMultipartUpdate(); } } diff --git a/application/controllers/HostgroupsController.php b/application/controllers/HostgroupsController.php index d7bec417..20cbbe8a 100644 --- a/application/controllers/HostgroupsController.php +++ b/application/controllers/HostgroupsController.php @@ -11,6 +11,7 @@ use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions; use Icinga\Module\Icingadb\Web\Controller; use Icinga\Module\Icingadb\Widget\ItemList\HostgroupList; use Icinga\Module\Icingadb\Widget\ShowMore; +use ipl\Web\Filter\QueryString; use ipl\Web\Url; class HostgroupsController extends Controller @@ -42,7 +43,19 @@ class HostgroupsController extends Controller $sortControl->getSortParam() ]); - $this->filter($hostgroups, $searchBar->getFilter()); + if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { + if ($searchBar->hasBeenSubmitted()) { + $filter = QueryString::parse($this->getFilter()->toQueryString()); + } else { + $this->addControl($searchBar); + $this->sendMultipartUpdate(); + return; + } + } else { + $filter = $searchBar->getFilter(); + } + + $this->filter($hostgroups, $filter); $hostgroups->peekAhead($compact); @@ -70,7 +83,7 @@ class HostgroupsController extends Controller ); } - if ($searchBar->hasBeenSent()) { + if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { $this->sendMultipartUpdate(); } diff --git a/application/controllers/HostsController.php b/application/controllers/HostsController.php index 89e15a1b..5f02d7d0 100644 --- a/application/controllers/HostsController.php +++ b/application/controllers/HostsController.php @@ -62,7 +62,17 @@ class HostsController extends Controller $viewModeSwitcher->getViewModeParam() ]); - $filter = $searchBar->getFilter(); + if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { + if ($searchBar->hasBeenSubmitted()) { + $filter = QueryString::parse($this->getFilter()->toQueryString()); + } else { + $this->addControl($searchBar); + $this->sendMultipartUpdate(); + return; + } + } else { + $filter = $searchBar->getFilter(); + } $hosts->peekAhead($compact); @@ -104,7 +114,7 @@ class HostsController extends Controller ); } - if ($searchBar->hasBeenSent()) { + if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { $viewModeSwitcher->setUrl($searchBar->getRedirectUrl()); $this->sendMultipartUpdate($viewModeSwitcher); } diff --git a/application/controllers/NotificationsController.php b/application/controllers/NotificationsController.php index b502951a..71642f7c 100644 --- a/application/controllers/NotificationsController.php +++ b/application/controllers/NotificationsController.php @@ -11,6 +11,7 @@ use Icinga\Module\Icingadb\Web\Controller; use Icinga\Module\Icingadb\Widget\ItemList\NotificationList; use Icinga\Module\Icingadb\Widget\ShowMore; use ipl\Sql\Sql; +use ipl\Web\Filter\QueryString; use ipl\Web\Url; class NotificationsController extends Controller @@ -44,7 +45,19 @@ class NotificationsController extends Controller $sortControl->getSortParam() ]); - $this->filter($notifications, $searchBar->getFilter()); + if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { + if ($searchBar->hasBeenSubmitted()) { + $filter = QueryString::parse($this->getFilter()->toQueryString()); + } else { + $this->addControl($searchBar); + $this->sendMultipartUpdate(); + return; + } + } else { + $filter = $searchBar->getFilter(); + } + + $this->filter($notifications, $filter); $notifications->getSelectBase() // Make sure we'll fetch service history entries only for services which still exist ->where([ @@ -76,7 +89,7 @@ class NotificationsController extends Controller ); } - if ($searchBar->hasBeenSent()) { + if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { $this->sendMultipartUpdate(); } diff --git a/application/controllers/ServicegroupsController.php b/application/controllers/ServicegroupsController.php index d320c664..900c750f 100644 --- a/application/controllers/ServicegroupsController.php +++ b/application/controllers/ServicegroupsController.php @@ -11,6 +11,7 @@ use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions; use Icinga\Module\Icingadb\Web\Controller; use Icinga\Module\Icingadb\Widget\ItemList\ServicegroupList; use Icinga\Module\Icingadb\Widget\ShowMore; +use ipl\Web\Filter\QueryString; use ipl\Web\Url; class ServicegroupsController extends Controller @@ -41,7 +42,19 @@ class ServicegroupsController extends Controller $sortControl->getSortParam() ]); - $this->filter($servicegroups, $searchBar->getFilter()); + if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { + if ($searchBar->hasBeenSubmitted()) { + $filter = QueryString::parse($this->getFilter()->toQueryString()); + } else { + $this->addControl($searchBar); + $this->sendMultipartUpdate(); + return; + } + } else { + $filter = $searchBar->getFilter(); + } + + $this->filter($servicegroups, $filter); $servicegroups->peekAhead($compact); @@ -69,7 +82,7 @@ class ServicegroupsController extends Controller ); } - if ($searchBar->hasBeenSent()) { + if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { $this->sendMultipartUpdate(); } diff --git a/application/controllers/ServicesController.php b/application/controllers/ServicesController.php index 0c2bba4d..0ecad659 100644 --- a/application/controllers/ServicesController.php +++ b/application/controllers/ServicesController.php @@ -67,7 +67,17 @@ class ServicesController extends Controller $viewModeSwitcher->getViewModeParam() ]); - $filter = $searchBar->getFilter(); + if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { + if ($searchBar->hasBeenSubmitted()) { + $filter = QueryString::parse($this->getFilter()->toQueryString()); + } else { + $this->addControl($searchBar); + $this->sendMultipartUpdate(); + return; + } + } else { + $filter = $searchBar->getFilter(); + } $services->peekAhead($compact); @@ -109,7 +119,7 @@ class ServicesController extends Controller ); } - if ($searchBar->hasBeenSent()) { + if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { $viewModeSwitcher->setUrl($searchBar->getRedirectUrl()); $this->sendMultipartUpdate($viewModeSwitcher); } diff --git a/application/controllers/TacticalController.php b/application/controllers/TacticalController.php index 321b41f4..2540319e 100644 --- a/application/controllers/TacticalController.php +++ b/application/controllers/TacticalController.php @@ -29,8 +29,17 @@ class TacticalController extends Controller $this->handleSearchRequest($servicestateSummary); $searchBar = $this->createSearchBar($servicestateSummary); - - $filter = $searchBar->getFilter(); + if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { + if ($searchBar->hasBeenSubmitted()) { + $filter = QueryString::parse($this->getFilter()->toQueryString()); + } else { + $this->addControl($searchBar); + $this->sendMultipartUpdate(); + return; + } + } else { + $filter = $searchBar->getFilter(); + } $this->filter($hoststateSummary, $filter); $this->filter($servicestateSummary, $filter); @@ -49,7 +58,7 @@ class TacticalController extends Controller ->setBaseFilter(Filter::fromQueryString(QueryString::render($filter))) ); - if ($searchBar->hasBeenSent()) { + if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { $this->sendMultipartUpdate(); } diff --git a/application/controllers/UsergroupsController.php b/application/controllers/UsergroupsController.php index 2a6bc01e..cca5cca3 100644 --- a/application/controllers/UsergroupsController.php +++ b/application/controllers/UsergroupsController.php @@ -10,6 +10,7 @@ use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions; use Icinga\Module\Icingadb\Web\Controller; use Icinga\Module\Icingadb\Widget\ItemList\UsergroupList; use Icinga\Security\SecurityException; +use ipl\Web\Filter\QueryString; class UsergroupsController extends Controller { @@ -45,7 +46,19 @@ class UsergroupsController extends Controller $sortControl->getSortParam() ]); - $this->filter($usergroups, $searchBar->getFilter()); + if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { + if ($searchBar->hasBeenSubmitted()) { + $filter = QueryString::parse($this->getFilter()->toQueryString()); + } else { + $this->addControl($searchBar); + $this->sendMultipartUpdate(); + return; + } + } else { + $filter = $searchBar->getFilter(); + } + + $this->filter($usergroups, $filter); yield $this->export($usergroups); @@ -56,7 +69,7 @@ class UsergroupsController extends Controller $this->addContent(new UsergroupList($usergroups)); - if ($searchBar->hasBeenSent()) { + if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { $this->sendMultipartUpdate(); } diff --git a/application/controllers/UsersController.php b/application/controllers/UsersController.php index 954ce617..f3362512 100644 --- a/application/controllers/UsersController.php +++ b/application/controllers/UsersController.php @@ -10,6 +10,7 @@ use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions; use Icinga\Module\Icingadb\Web\Controller; use Icinga\Module\Icingadb\Widget\ItemList\UserList; use Icinga\Security\SecurityException; +use ipl\Web\Filter\QueryString; class UsersController extends Controller { @@ -47,7 +48,19 @@ class UsersController extends Controller $sortControl->getSortParam() ]); - $this->filter($users, $searchBar->getFilter()); + if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { + if ($searchBar->hasBeenSubmitted()) { + $filter = QueryString::parse($this->getFilter()->toQueryString()); + } else { + $this->addControl($searchBar); + $this->sendMultipartUpdate(); + return; + } + } else { + $filter = $searchBar->getFilter(); + } + + $this->filter($users, $filter); yield $this->export($users); @@ -58,7 +71,7 @@ class UsersController extends Controller $this->addContent(new UserList($users)); - if ($searchBar->hasBeenSent()) { + if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { $this->sendMultipartUpdate(); }