mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-05-28 04:36:06 -04:00
Preserve filters after clicking Load More
Currently, the load more urls are fixed and hence the filters are not preserved after clicking on load more. In this fix load more url has been changed dynamically upon applying filters for history or notifications and hence preserving the filters.
This commit is contained in:
parent
fab35aed00
commit
3c90c2d3e5
2 changed files with 22 additions and 12 deletions
|
|
@ -13,6 +13,7 @@ use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher;
|
|||
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
|
||||
|
|
@ -22,6 +23,12 @@ class HistoryController extends Controller
|
|||
$this->addTitleTab(t('History'));
|
||||
$compact = $this->view->compact; // TODO: Find a less-legacy way..
|
||||
|
||||
$preserveParams = [
|
||||
LimitControl::DEFAULT_LIMIT_PARAM,
|
||||
SortControl::DEFAULT_SORT_PARAM,
|
||||
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM
|
||||
];
|
||||
|
||||
$db = $this->getDb();
|
||||
|
||||
$history = History::on($db)->with([
|
||||
|
|
@ -38,7 +45,6 @@ class HistoryController extends Controller
|
|||
]);
|
||||
|
||||
$before = $this->params->shift('before', time());
|
||||
$url = Url::fromPath('icingadb/history')->setParams(clone $this->params);
|
||||
|
||||
$limitControl = $this->createLimitControl();
|
||||
$paginationControl = $this->createPaginationControl($history);
|
||||
|
|
@ -49,11 +55,7 @@ class HistoryController extends Controller
|
|||
]
|
||||
);
|
||||
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl, true);
|
||||
$searchBar = $this->createSearchBar($history, [
|
||||
$limitControl->getLimitParam(),
|
||||
$sortControl->getSortParam(),
|
||||
$viewModeSwitcher->getViewModeParam()
|
||||
]);
|
||||
$searchBar = $this->createSearchBar($history, $preserveParams);
|
||||
|
||||
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
|
||||
if ($searchBar->hasBeenSubmitted()) {
|
||||
|
|
@ -92,6 +94,9 @@ class HistoryController extends Controller
|
|||
$this->addControl($viewModeSwitcher);
|
||||
$this->addControl($searchBar);
|
||||
|
||||
$url = Url::fromRequest()->onlyWith($preserveParams);
|
||||
$url->setQueryString(QueryString::render($filter) . '&' . $url->getParams()->toString());
|
||||
|
||||
$historyList = (new HistoryList($history->execute()))
|
||||
->setPageSize($limitControl->getLimit())
|
||||
->setViewMode($viewModeSwitcher->getViewMode())
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ use ipl\Sql\Sql;
|
|||
use ipl\Stdlib\Filter;
|
||||
use ipl\Web\Control\LimitControl;
|
||||
use ipl\Web\Control\SortControl;
|
||||
use ipl\Web\Filter\QueryString;
|
||||
use ipl\Web\Url;
|
||||
|
||||
class NotificationsController extends Controller
|
||||
|
|
@ -23,6 +24,12 @@ class NotificationsController extends Controller
|
|||
$this->addTitleTab(t('Notifications'));
|
||||
$compact = $this->view->compact;
|
||||
|
||||
$preserveParams = [
|
||||
LimitControl::DEFAULT_LIMIT_PARAM,
|
||||
SortControl::DEFAULT_SORT_PARAM,
|
||||
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM
|
||||
];
|
||||
|
||||
$db = $this->getDb();
|
||||
|
||||
$notifications = NotificationHistory::on($db)->with([
|
||||
|
|
@ -35,7 +42,6 @@ class NotificationsController extends Controller
|
|||
|
||||
$this->handleSearchRequest($notifications);
|
||||
$before = $this->params->shift('before', time());
|
||||
$url = Url::fromPath('icingadb/notifications')->setParams(clone $this->params);
|
||||
|
||||
$limitControl = $this->createLimitControl();
|
||||
$paginationControl = $this->createPaginationControl($notifications);
|
||||
|
|
@ -46,11 +52,7 @@ class NotificationsController extends Controller
|
|||
]
|
||||
);
|
||||
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl, true);
|
||||
$searchBar = $this->createSearchBar($notifications, [
|
||||
$limitControl->getLimitParam(),
|
||||
$sortControl->getSortParam(),
|
||||
$viewModeSwitcher->getViewModeParam()
|
||||
]);
|
||||
$searchBar = $this->createSearchBar($notifications, $preserveParams);
|
||||
|
||||
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
|
||||
if ($searchBar->hasBeenSubmitted()) {
|
||||
|
|
@ -87,6 +89,9 @@ class NotificationsController extends Controller
|
|||
$this->addControl($viewModeSwitcher);
|
||||
$this->addControl($searchBar);
|
||||
|
||||
$url = Url::fromRequest()->onlyWith($preserveParams);
|
||||
$url->setQueryString(QueryString::render($filter) . '&' . $url->getParams()->toString());
|
||||
|
||||
$notificationList = (new NotificationList($notifications->execute()))
|
||||
->setPageSize($limitControl->getLimit())
|
||||
->setViewMode($viewModeSwitcher->getViewMode())
|
||||
|
|
|
|||
Loading…
Reference in a new issue