diff --git a/application/controllers/CommentsController.php b/application/controllers/CommentsController.php index 1f841971b..773ab6419 100644 --- a/application/controllers/CommentsController.php +++ b/application/controllers/CommentsController.php @@ -15,7 +15,6 @@ use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher; use ipl\Web\Control\LimitControl; use ipl\Web\Control\SortControl; -use ipl\Web\Filter\QueryString; use ipl\Web\Url; class CommentsController extends Controller @@ -161,7 +160,7 @@ public function detailsAction() $this->addControl(new ShowMore( $rs, - Links::comments()->setQueryString(QueryString::render($this->getFilter())), + Links::comments()->setFilter($this->getFilter()), sprintf(t('Show all %d comments'), $comments->count()) )); @@ -170,7 +169,7 @@ public function detailsAction() ->setObjects($comments) ->setAction( Links::commentsDelete() - ->setQueryString(QueryString::render($this->getFilter())) + ->setFilter($this->getFilter()) ->getAbsoluteUrl() ) ); diff --git a/application/controllers/DowntimesController.php b/application/controllers/DowntimesController.php index f2b87888d..48af66238 100644 --- a/application/controllers/DowntimesController.php +++ b/application/controllers/DowntimesController.php @@ -15,7 +15,6 @@ use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher; use ipl\Web\Control\LimitControl; use ipl\Web\Control\SortControl; -use ipl\Web\Filter\QueryString; use ipl\Web\Url; class DowntimesController extends Controller @@ -167,7 +166,7 @@ public function detailsAction() $this->addControl(new ShowMore( $rs, - Links::downtimes()->setQueryString(QueryString::render($this->getFilter())), + Links::downtimes()->setFilter($this->getFilter()), sprintf(t('Show all %d downtimes'), $downtimes->count()) )); @@ -176,7 +175,7 @@ public function detailsAction() ->setObjects($downtimes) ->setAction( Links::downtimesDelete() - ->setQueryString(QueryString::render($this->getFilter())) + ->setFilter($this->getFilter()) ->getAbsoluteUrl() ) ); diff --git a/application/controllers/HistoryController.php b/application/controllers/HistoryController.php index f2331e6a5..a1b873b2a 100644 --- a/application/controllers/HistoryController.php +++ b/application/controllers/HistoryController.php @@ -13,7 +13,6 @@ use ipl\Stdlib\Filter; use ipl\Web\Control\LimitControl; use ipl\Web\Control\SortControl; -use ipl\Web\Filter\QueryString; use ipl\Web\Url; class HistoryController extends Controller @@ -95,8 +94,9 @@ public function indexAction() $this->addControl($viewModeSwitcher); $this->addControl($searchBar); - $url = Url::fromRequest()->onlyWith($preserveParams); - $url->setQueryString(QueryString::render($filter) . '&' . $url->getParams()->toString()); + $url = Url::fromRequest() + ->onlyWith($preserveParams) + ->setFilter($filter); $historyList = (new HistoryList($history->execute())) ->setPageSize($limitControl->getLimit()) diff --git a/application/controllers/HostsController.php b/application/controllers/HostsController.php index 90da1e646..286af559b 100644 --- a/application/controllers/HostsController.php +++ b/application/controllers/HostsController.php @@ -24,7 +24,6 @@ use ipl\Stdlib\Filter; use ipl\Web\Control\LimitControl; use ipl\Web\Control\SortControl; -use ipl\Web\Filter\QueryString; use ipl\Web\Url; class HostsController extends Controller @@ -170,7 +169,7 @@ public function detailsAction() ); $this->addControl(new ShowMore( $results, - Links::hosts()->setQueryString(QueryString::render($this->getFilter())), + Links::hosts()->setFilter($this->getFilter()), sprintf(t('Show all %d hosts'), $hosts->count()) )); $this->addControl( @@ -227,7 +226,7 @@ protected function fetchCommandTargets(): Query protected function getCommandTargetsUrl(): Url { - return Links::hostsDetails()->setQueryString(QueryString::render($this->getFilter())); + return Links::hostsDetails()->setFilter($this->getFilter()); } protected function getFeatureStatus() diff --git a/application/controllers/MigrateController.php b/application/controllers/MigrateController.php index cdc71d8a5..2b2bf0179 100644 --- a/application/controllers/MigrateController.php +++ b/application/controllers/MigrateController.php @@ -110,7 +110,7 @@ public function searchUrlAction() $newFilter = $traverseFilter($filter); if ($newFilter !== null) { - $result[] = rawurldecode($url->setQueryString(QueryString::render($newFilter))->getAbsoluteUrl()); + $result[] = rawurldecode($url->setFilter($newFilter)->getAbsoluteUrl()); } else { $result[] = $url->getAbsoluteUrl(); } diff --git a/application/controllers/NotificationsController.php b/application/controllers/NotificationsController.php index b93ccfbc5..2d23604c3 100644 --- a/application/controllers/NotificationsController.php +++ b/application/controllers/NotificationsController.php @@ -90,8 +90,9 @@ public function indexAction() $this->addControl($viewModeSwitcher); $this->addControl($searchBar); - $url = Url::fromRequest()->onlyWith($preserveParams); - $url->setQueryString(QueryString::render($filter) . '&' . $url->getParams()->toString()); + $url = Url::fromRequest() + ->onlyWith($preserveParams) + ->setFilter($filter); $notificationList = (new NotificationList($notifications->execute())) ->setPageSize($limitControl->getLimit()) diff --git a/application/controllers/ServicesController.php b/application/controllers/ServicesController.php index 40503b4a7..6ced0de44 100644 --- a/application/controllers/ServicesController.php +++ b/application/controllers/ServicesController.php @@ -28,7 +28,6 @@ use ipl\Stdlib\Filter; use ipl\Web\Control\LimitControl; use ipl\Web\Control\SortControl; -use ipl\Web\Filter\QueryString; use ipl\Web\Url; class ServicesController extends Controller @@ -186,7 +185,7 @@ public function detailsAction() ); $this->addControl(new ShowMore( $results, - Links::services()->setQueryString(QueryString::render($this->getFilter())), + Links::services()->setFilter($this->getFilter()), sprintf(t('Show all %d services'), $services->count()) )); $this->addControl( @@ -309,7 +308,7 @@ public function gridAction() $this->view->pivotHeader = $pivotHeader; /** Preserve filter and params in view links (the `BaseFilter` implementation for view scripts -.-) */ - $this->view->baseUrl = $this->getRequest()->getUrl() + $this->view->baseUrl = Url::fromRequest() ->onlyWith([ LimitControl::DEFAULT_LIMIT_PARAM, $sortControl->getSortParam(), @@ -318,15 +317,7 @@ public function gridAction() 'problems' ]); $preservedParams = $this->view->baseUrl->getParams(); - $this->view->baseUrl->setQueryString(QueryString::render($filter)); - foreach ($preservedParams->toArray(false) as $name => $value) { - if (is_int($name)) { - $name = $value; - $value = true; - } - - $this->view->baseUrl->getParams()->addEncoded($name, $value); - } + $this->view->baseUrl->setFilter($filter); $searchBar->setEditorUrl(Url::fromPath( "icingadb/services/grid-search-editor" @@ -400,7 +391,7 @@ protected function fetchCommandTargets(): Query protected function getCommandTargetsUrl(): Url { - return Links::servicesDetails()->setQueryString(QueryString::render($this->getFilter())); + return Links::servicesDetails()->setFilter($this->getFilter()); } protected function getFeatureStatus() diff --git a/library/Icingadb/Common/StateBadges.php b/library/Icingadb/Common/StateBadges.php index 2659d890d..c9c5c89f7 100644 --- a/library/Icingadb/Common/StateBadges.php +++ b/library/Icingadb/Common/StateBadges.php @@ -122,9 +122,7 @@ public function createLink($content, Filter\Rule $filter = null): Link } if (! $urlFilter->isEmpty()) { - $urlParams = $url->getParams()->toArray(false); - $url->setQueryString(QueryString::render($urlFilter)) - ->addParams($urlParams); + $url->setFilter($urlFilter); } return new Link($content, $url); diff --git a/library/Icingadb/Compat/UrlMigrator.php b/library/Icingadb/Compat/UrlMigrator.php index 1a5968077..ffee88986 100644 --- a/library/Icingadb/Compat/UrlMigrator.php +++ b/library/Icingadb/Compat/UrlMigrator.php @@ -67,7 +67,7 @@ public static function transformUrl(Url $url): Url $filter = QueryString::parse((string) $url->getParams()); $filter = self::transformFilter($filter, $queryTransformer); if ($filter) { - $url->setQueryString(QueryString::render($filter)); + $url->setFilter($filter); } } diff --git a/library/Icingadb/Web/Controller.php b/library/Icingadb/Web/Controller.php index 546d3da95..0bdcbc1b1 100644 --- a/library/Icingadb/Web/Controller.php +++ b/library/Icingadb/Web/Controller.php @@ -288,10 +288,7 @@ public function handleSearchRequest(Query $query, array $additionalColumns = []) $this->prepareSearchFilter($query, $q, $filter, $additionalColumns); $redirectUrl = Url::fromRequest(); - $redirectUrl->setQueryString(QueryString::render($filter)); - foreach ($this->params->toArray(false) as $name => $value) { - $redirectUrl->getParams()->addEncoded($name, $value); - } + $redirectUrl->setFilter($filter); $this->getResponse()->redirectAndExit($redirectUrl); } diff --git a/library/Icingadb/Widget/Detail/CommentDetail.php b/library/Icingadb/Widget/Detail/CommentDetail.php index 2071f95a2..5b0923e43 100644 --- a/library/Icingadb/Widget/Detail/CommentDetail.php +++ b/library/Icingadb/Widget/Detail/CommentDetail.php @@ -110,7 +110,7 @@ protected function createRemoveCommentForm() } $action = Links::commentsDelete(); - $action->setQueryString(QueryString::render(Filter::equal('name', $this->comment->name))); + $action->setFilter(Filter::equal('name', $this->comment->name)); return (new DeleteCommentForm()) ->setObjects([$this->comment]) diff --git a/library/Icingadb/Widget/Detail/DowntimeDetail.php b/library/Icingadb/Widget/Detail/DowntimeDetail.php index 291c06a44..206636f6c 100644 --- a/library/Icingadb/Widget/Detail/DowntimeDetail.php +++ b/library/Icingadb/Widget/Detail/DowntimeDetail.php @@ -54,7 +54,7 @@ public function __construct(Downtime $downtime) protected function createCancelDowntimeForm() { $action = Links::downtimesDelete(); - $action->setQueryString(QueryString::render(Filter::equal('name', $this->downtime->name))); + $action->setFilter(Filter::equal('name', $this->downtime->name)); return (new DeleteDowntimeForm()) ->setObjects([$this->downtime]) diff --git a/library/Icingadb/Widget/Detail/HostStatistics.php b/library/Icingadb/Widget/Detail/HostStatistics.php index 18b0f400c..bcfc3f818 100644 --- a/library/Icingadb/Widget/Detail/HostStatistics.php +++ b/library/Icingadb/Widget/Detail/HostStatistics.php @@ -37,7 +37,7 @@ protected function createTotal(): ValidHtml { $url = Links::hosts(); if ($this->hasBaseFilter()) { - $url->setQueryString(QueryString::render($this->getBaseFilter())); + $url->setFilter($this->getBaseFilter()); } return new Link( diff --git a/library/Icingadb/Widget/Detail/MultiselectQuickActions.php b/library/Icingadb/Widget/Detail/MultiselectQuickActions.php index ae7970e7c..f398d80e5 100644 --- a/library/Icingadb/Widget/Detail/MultiselectQuickActions.php +++ b/library/Icingadb/Widget/Detail/MultiselectQuickActions.php @@ -188,7 +188,7 @@ protected function assembleAction(string $action, string $label, string $icon, s protected function getLink(string $action): string { return Url::fromPath("icingadb/{$this->type}s/$action") - ->setQueryString(QueryString::render($this->getBaseFilter())) + ->setFilter($this->getBaseFilter()) ->getAbsoluteUrl(); } } diff --git a/library/Icingadb/Widget/Detail/ObjectsDetail.php b/library/Icingadb/Widget/Detail/ObjectsDetail.php index 2a3e670da..ff2613fc9 100644 --- a/library/Icingadb/Widget/Detail/ObjectsDetail.php +++ b/library/Icingadb/Widget/Detail/ObjectsDetail.php @@ -21,7 +21,6 @@ use ipl\Html\BaseHtmlElement; use ipl\Html\Html; use ipl\Html\HtmlString; -use ipl\Web\Filter\QueryString; use ipl\Web\Widget\ActionLink; class ObjectsDetail extends BaseHtmlElement @@ -111,7 +110,7 @@ protected function createComments(): array tp('Show %d comment', 'Show %d comments', $this->summary->comments_total), $this->summary->comments_total ), - Links::comments()->setQueryString(QueryString::render($this->getBaseFilter())) + Links::comments()->setFilter($this->getBaseFilter()) ); } else { $content[] = new EmptyState(t('No comments created.')); @@ -130,7 +129,7 @@ protected function createDowntimes(): array tp('Show %d downtime', 'Show %d downtimes', $this->summary->downtimes_total), $this->summary->downtimes_total ), - Links::downtimes()->setQueryString(QueryString::render($this->getBaseFilter())) + Links::downtimes()->setFilter($this->getBaseFilter()) ); } else { $content[] = new EmptyState(t('No downtimes scheduled.')); @@ -146,13 +145,13 @@ protected function createFeatureToggles(): array if ($this->type === 'host') { $form->setAction( Links::toggleHostsFeatures() - ->setQueryString(QueryString::render($this->getBaseFilter())) + ->setFilter($this->getBaseFilter()) ->getAbsoluteUrl() ); } else { $form->setAction( Links::toggleServicesFeatures() - ->setQueryString(QueryString::render($this->getBaseFilter())) + ->setFilter($this->getBaseFilter()) ->getAbsoluteUrl() ); } diff --git a/library/Icingadb/Widget/Detail/ServiceStatistics.php b/library/Icingadb/Widget/Detail/ServiceStatistics.php index 9f0cbdf67..51aced122 100644 --- a/library/Icingadb/Widget/Detail/ServiceStatistics.php +++ b/library/Icingadb/Widget/Detail/ServiceStatistics.php @@ -10,7 +10,6 @@ use ipl\Html\ValidHtml; use ipl\Web\Widget\VerticalKeyValue; use ipl\Html\HtmlString; -use ipl\Web\Filter\QueryString; use ipl\Web\Widget\Link; class ServiceStatistics extends ObjectStatistics @@ -41,7 +40,7 @@ protected function createTotal(): ValidHtml { $url = Links::services(); if ($this->hasBaseFilter()) { - $url->setQueryString(QueryString::render($this->getBaseFilter())); + $url->setFilter($this->getBaseFilter()); } return new Link( diff --git a/library/Icingadb/Widget/HostSummaryDonut.php b/library/Icingadb/Widget/HostSummaryDonut.php index 86d1707fe..db5fef8c5 100644 --- a/library/Icingadb/Widget/HostSummaryDonut.php +++ b/library/Icingadb/Widget/HostSummaryDonut.php @@ -48,7 +48,7 @@ protected function assembleBody(BaseHtmlElement $body) ->addSlice($this->summary->hosts_down_unhandled, ['class' => 'slice-state-critical']) ->addSlice($this->summary->hosts_pending, ['class' => 'slice-state-pending']) ->setLabelBig($this->summary->hosts_down_unhandled) - ->setLabelBigUrl(Links::hosts()->setQueryString(QueryString::render($labelBigUrlFilter))->addParams([ + ->setLabelBigUrl(Links::hosts()->setFilter($labelBigUrlFilter)->addParams([ 'sort' => 'host.state.last_state_change' ])) ->setLabelBigEyeCatching($this->summary->hosts_down_unhandled > 0) diff --git a/library/Icingadb/Widget/ItemTable/HostgroupGridCell.php b/library/Icingadb/Widget/ItemTable/HostgroupGridCell.php index f9202051e..539674752 100644 --- a/library/Icingadb/Widget/ItemTable/HostgroupGridCell.php +++ b/library/Icingadb/Widget/ItemTable/HostgroupGridCell.php @@ -5,7 +5,6 @@ namespace Icinga\Module\Icingadb\Widget\ItemTable; use ipl\Stdlib\Filter; -use ipl\Web\Filter\QueryString; use ipl\Web\Url; use ipl\Web\Widget\Link; use ipl\Web\Widget\StateBadge; @@ -28,7 +27,7 @@ protected function createGroupBadge(): Link return new Link( new StateBadge($this->item->hosts_down_unhandled, 'down'), - $url->setQueryString(QueryString::render($urlFilter)), + $url->setFilter($urlFilter), [ 'title' => sprintf( $this->translatePlural( @@ -50,7 +49,7 @@ protected function createGroupBadge(): Link return new Link( new StateBadge($this->item->hosts_down_handled, 'down', true), - $url->setQueryString(QueryString::render($urlFilter)), + $url->setFilter($urlFilter), [ 'title' => sprintf( $this->translatePlural( @@ -68,7 +67,7 @@ protected function createGroupBadge(): Link return new Link( new StateBadge($this->item->hosts_pending, 'pending'), - $url->setQueryString(QueryString::render($urlFilter)), + $url->setFilter($urlFilter), [ 'title' => sprintf( $this->translatePlural( @@ -86,7 +85,7 @@ protected function createGroupBadge(): Link return new Link( new StateBadge($this->item->hosts_up, 'up'), - $url->setQueryString(QueryString::render($urlFilter)), + $url->setFilter($urlFilter), [ 'title' => sprintf( $this->translatePlural( diff --git a/library/Icingadb/Widget/ItemTable/ServicegroupGridCell.php b/library/Icingadb/Widget/ItemTable/ServicegroupGridCell.php index fa90d4f54..16e50e19b 100644 --- a/library/Icingadb/Widget/ItemTable/ServicegroupGridCell.php +++ b/library/Icingadb/Widget/ItemTable/ServicegroupGridCell.php @@ -5,7 +5,6 @@ namespace Icinga\Module\Icingadb\Widget\ItemTable; use ipl\Stdlib\Filter; -use ipl\Web\Filter\QueryString; use ipl\Web\Url; use ipl\Web\Widget\Link; use ipl\Web\Widget\StateBadge; @@ -28,7 +27,7 @@ protected function createGroupBadge(): Link return new Link( new StateBadge($this->item->services_critical_unhandled, 'critical'), - $url->setQueryString(QueryString::render($urlFilter)), + $url->setFilter($urlFilter), [ 'title' => sprintf( $this->translatePlural( @@ -50,7 +49,7 @@ protected function createGroupBadge(): Link return new Link( new StateBadge($this->item->services_critical_handled, 'critical', true), - $url->setQueryString(QueryString::render($urlFilter)), + $url->setFilter($urlFilter), [ 'title' => sprintf( $this->translatePlural( @@ -72,7 +71,7 @@ protected function createGroupBadge(): Link return new Link( new StateBadge($this->item->services_warning_unhandled, 'warning'), - $url->setQueryString(QueryString::render($urlFilter)), + $url->setFilter($urlFilter), [ 'title' => sprintf( $this->translatePlural( @@ -94,7 +93,7 @@ protected function createGroupBadge(): Link return new Link( new StateBadge($this->item->services_warning_handled, 'warning', true), - $url->setQueryString(QueryString::render($urlFilter)), + $url->setFilter($urlFilter), [ 'title' => sprintf( $this->translatePlural( @@ -116,7 +115,7 @@ protected function createGroupBadge(): Link return new Link( new StateBadge($this->item->services_unknown_unhandled, 'unknown'), - $url->setQueryString(QueryString::render($urlFilter)), + $url->setFilter($urlFilter), [ 'title' => sprintf( $this->translatePlural( @@ -138,7 +137,7 @@ protected function createGroupBadge(): Link return new Link( new StateBadge($this->item->services_unknown_handled, 'unknown', true), - $url->setQueryString(QueryString::render($urlFilter)), + $url->setFilter($urlFilter), [ 'title' => sprintf( $this->translatePlural( @@ -158,7 +157,7 @@ protected function createGroupBadge(): Link return new Link( new StateBadge($this->item->services_pending, 'pending'), - $url->setQueryString(QueryString::render($urlFilter)), + $url->setFilter($urlFilter), [ 'title' => sprintf( $this->translatePlural( @@ -176,7 +175,7 @@ protected function createGroupBadge(): Link return new Link( new StateBadge($this->item->services_ok, 'ok'), - $url->setQueryString(QueryString::render($urlFilter)), + $url->setFilter($urlFilter), [ 'title' => sprintf( $this->translatePlural( diff --git a/library/Icingadb/Widget/ServiceSummaryDonut.php b/library/Icingadb/Widget/ServiceSummaryDonut.php index 71eb78107..e806fba0f 100644 --- a/library/Icingadb/Widget/ServiceSummaryDonut.php +++ b/library/Icingadb/Widget/ServiceSummaryDonut.php @@ -16,7 +16,6 @@ use ipl\Stdlib\BaseFilter; use ipl\Stdlib\Filter; use ipl\Web\Common\Card; -use ipl\Web\Filter\QueryString; class ServiceSummaryDonut extends Card { @@ -52,7 +51,7 @@ protected function assembleBody(BaseHtmlElement $body) ->addSlice($this->summary->services_unknown_unhandled, ['class' => 'slice-state-unknown']) ->addSlice($this->summary->services_pending, ['class' => 'slice-state-pending']) ->setLabelBig($this->summary->services_critical_unhandled) - ->setLabelBigUrl(Links::services()->setQueryString(QueryString::render($labelBigUrlFilter))->addParams([ + ->setLabelBigUrl(Links::services()->setFilter($labelBigUrlFilter)->addParams([ 'sort' => 'service.state.last_state_change' ])) ->setLabelBigEyeCatching($this->summary->services_critical_unhandled > 0) diff --git a/test/php/library/Icingadb/Common/StateBadgesTest.php b/test/php/library/Icingadb/Common/StateBadgesTest.php index 2a2e9c394..b535e655e 100644 --- a/test/php/library/Icingadb/Common/StateBadgesTest.php +++ b/test/php/library/Icingadb/Common/StateBadgesTest.php @@ -7,6 +7,7 @@ use Icinga\Module\Icingadb\Common\StateBadges; use Icinga\Web\UrlParams; use ipl\Stdlib\Filter; +use ipl\Web\Filter\QueryString; use ipl\Web\Url; use PHPUnit\Framework\TestCase; @@ -38,9 +39,9 @@ private function createStateBadges() 'toArray' => [] ]) ]); - $urlMock->method('setQueryString')->willReturnCallback( + $urlMock->method('setFilter')->willReturnCallback( function ($qs) use ($urlMock, &$queryString) { - $queryString = $qs; + $queryString = QueryString::render($qs); return $urlMock; }