Skip to content

Commit

Permalink
Utilize ipl\Web\Url::setFilter() where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Sep 5, 2023
1 parent 808a275 commit 9b24317
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 66 deletions.
5 changes: 2 additions & 3 deletions application/controllers/CommentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
));

Expand All @@ -170,7 +169,7 @@ public function detailsAction()
->setObjects($comments)
->setAction(
Links::commentsDelete()
->setQueryString(QueryString::render($this->getFilter()))
->setFilter($this->getFilter())
->getAbsoluteUrl()
)
);
Expand Down
5 changes: 2 additions & 3 deletions application/controllers/DowntimesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
));

Expand All @@ -176,7 +175,7 @@ public function detailsAction()
->setObjects($downtimes)
->setAction(
Links::downtimesDelete()
->setQueryString(QueryString::render($this->getFilter()))
->setFilter($this->getFilter())
->getAbsoluteUrl()
)
);
Expand Down
6 changes: 3 additions & 3 deletions application/controllers/HistoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
5 changes: 2 additions & 3 deletions application/controllers/HostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/MigrateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
5 changes: 3 additions & 2 deletions application/controllers/NotificationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
17 changes: 4 additions & 13 deletions application/controllers/ServicesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(),
Expand All @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions library/Icingadb/Common/StateBadges.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Compat/UrlMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
5 changes: 1 addition & 4 deletions library/Icingadb/Web/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/Detail/CommentDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/Detail/DowntimeDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/Detail/HostStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/Detail/MultiselectQuickActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
9 changes: 4 additions & 5 deletions library/Icingadb/Widget/Detail/ObjectsDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.'));
Expand All @@ -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.'));
Expand All @@ -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()
);
}
Expand Down
3 changes: 1 addition & 2 deletions library/Icingadb/Widget/Detail/ServiceStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/HostSummaryDonut.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions library/Icingadb/Widget/ItemTable/HostgroupGridCell.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Loading

0 comments on commit 9b24317

Please sign in to comment.