2019-10-23 06:30:00 -04:00
|
|
|
<?php
|
|
|
|
|
|
2020-03-13 03:38:01 -04:00
|
|
|
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
|
|
|
|
|
|
2019-11-04 19:07:30 -05:00
|
|
|
namespace Icinga\Module\Icingadb\Controllers;
|
2019-10-23 06:30:00 -04:00
|
|
|
|
2020-11-02 08:31:20 -05:00
|
|
|
use GuzzleHttp\Psr7\ServerRequest;
|
2019-11-04 19:07:30 -05:00
|
|
|
use Icinga\Module\Icingadb\Model\NotificationHistory;
|
2020-11-02 08:31:20 -05:00
|
|
|
use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions;
|
2019-11-04 19:07:30 -05:00
|
|
|
use Icinga\Module\Icingadb\Web\Controller;
|
2025-03-24 08:02:27 -04:00
|
|
|
use Icinga\Module\Icingadb\Widget\ItemList\LoadMoreObjectList;
|
2021-08-20 11:23:29 -04:00
|
|
|
use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher;
|
2021-08-19 09:14:06 -04:00
|
|
|
use ipl\Stdlib\Filter;
|
2021-03-05 07:45:36 -05:00
|
|
|
use ipl\Web\Control\LimitControl;
|
|
|
|
|
use ipl\Web\Control\SortControl;
|
2020-01-31 09:51:44 -05:00
|
|
|
use ipl\Web\Url;
|
2019-10-23 06:30:00 -04:00
|
|
|
|
|
|
|
|
class NotificationsController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function indexAction()
|
|
|
|
|
{
|
2022-03-16 11:06:00 -04:00
|
|
|
$this->addTitleTab(t('Notifications'));
|
2020-01-31 09:51:44 -05:00
|
|
|
$compact = $this->view->compact;
|
2019-10-23 06:30:00 -04:00
|
|
|
|
2022-07-19 10:31:30 -04:00
|
|
|
$preserveParams = [
|
|
|
|
|
LimitControl::DEFAULT_LIMIT_PARAM,
|
|
|
|
|
SortControl::DEFAULT_SORT_PARAM,
|
|
|
|
|
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM
|
|
|
|
|
];
|
|
|
|
|
|
2019-10-23 06:30:00 -04:00
|
|
|
$db = $this->getDb();
|
|
|
|
|
|
|
|
|
|
$notifications = NotificationHistory::on($db)->with([
|
2021-06-08 07:40:17 -04:00
|
|
|
'history',
|
2019-10-23 06:30:00 -04:00
|
|
|
'host',
|
|
|
|
|
'host.state',
|
|
|
|
|
'service',
|
|
|
|
|
'service.state'
|
|
|
|
|
]);
|
|
|
|
|
|
2020-11-02 08:31:20 -05:00
|
|
|
$this->handleSearchRequest($notifications);
|
2021-08-19 09:14:06 -04:00
|
|
|
$before = $this->params->shift('before', time());
|
2020-11-02 08:31:20 -05:00
|
|
|
|
2019-10-23 06:30:00 -04:00
|
|
|
$limitControl = $this->createLimitControl();
|
2021-08-23 09:23:34 -04:00
|
|
|
$paginationControl = $this->createPaginationControl($notifications);
|
2019-12-11 07:56:14 -05:00
|
|
|
$sortControl = $this->createSortControl(
|
|
|
|
|
$notifications,
|
|
|
|
|
[
|
2020-04-24 08:36:37 -04:00
|
|
|
'notification_history.send_time desc' => t('Send Time')
|
2019-12-11 07:56:14 -05:00
|
|
|
]
|
|
|
|
|
);
|
2021-09-08 05:08:36 -04:00
|
|
|
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl, true);
|
2022-07-19 10:31:30 -04:00
|
|
|
$searchBar = $this->createSearchBar($notifications, $preserveParams);
|
2019-10-23 06:30:00 -04:00
|
|
|
|
2020-11-06 09:51:00 -05:00
|
|
|
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
|
|
|
|
|
if ($searchBar->hasBeenSubmitted()) {
|
2020-12-03 11:05:51 -05:00
|
|
|
$filter = $this->getFilter();
|
2020-11-06 09:51:00 -05:00
|
|
|
} else {
|
|
|
|
|
$this->addControl($searchBar);
|
|
|
|
|
$this->sendMultipartUpdate();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$filter = $searchBar->getFilter();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 09:14:06 -04:00
|
|
|
$notifications->peekAhead();
|
|
|
|
|
|
2021-08-23 09:23:34 -04:00
|
|
|
$page = $paginationControl->getCurrentPageNumber();
|
|
|
|
|
|
|
|
|
|
if ($page > 1 && ! $compact) {
|
2023-03-28 10:34:43 -04:00
|
|
|
$notifications->resetOffset();
|
2021-08-23 09:23:34 -04:00
|
|
|
$notifications->limit($page * $limitControl->getLimit());
|
2021-08-19 09:14:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$notifications->filter(Filter::lessThanOrEqual('send_time', $before));
|
2020-11-06 09:51:00 -05:00
|
|
|
$this->filter($notifications, $filter);
|
2022-05-20 02:55:57 -04:00
|
|
|
$notifications->filter(Filter::any(
|
2020-03-10 04:26:28 -04:00
|
|
|
// Make sure we'll fetch service history entries only for services which still exist
|
2022-05-20 02:55:57 -04:00
|
|
|
Filter::unlike('service_id', '*'),
|
|
|
|
|
Filter::like('history.service.id', '*')
|
|
|
|
|
));
|
2019-10-23 06:30:00 -04:00
|
|
|
|
|
|
|
|
yield $this->export($notifications);
|
|
|
|
|
|
2019-12-11 07:56:14 -05:00
|
|
|
$this->addControl($sortControl);
|
2019-10-23 06:30:00 -04:00
|
|
|
$this->addControl($limitControl);
|
2021-08-04 04:11:49 -04:00
|
|
|
$this->addControl($viewModeSwitcher);
|
2020-11-02 08:31:20 -05:00
|
|
|
$this->addControl($searchBar);
|
2019-10-23 06:30:00 -04:00
|
|
|
|
2023-09-01 07:53:02 -04:00
|
|
|
$url = Url::fromRequest()
|
|
|
|
|
->onlyWith($preserveParams)
|
|
|
|
|
->setFilter($filter);
|
2022-07-19 10:31:30 -04:00
|
|
|
|
2025-03-24 08:02:27 -04:00
|
|
|
$notificationList = (new LoadMoreObjectList($notifications->execute()))
|
2021-08-19 09:14:06 -04:00
|
|
|
->setPageSize($limitControl->getLimit())
|
|
|
|
|
->setViewMode($viewModeSwitcher->getViewMode())
|
|
|
|
|
->setLoadMoreUrl($url->setParam('before', $before));
|
2020-01-31 09:51:44 -05:00
|
|
|
|
|
|
|
|
if ($compact) {
|
2021-08-19 09:14:06 -04:00
|
|
|
$notificationList->setPageNumber($page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($compact && $page > 1) {
|
|
|
|
|
$this->document->addFrom($notificationList);
|
|
|
|
|
} else {
|
|
|
|
|
$this->addContent($notificationList);
|
2020-01-31 09:51:44 -05:00
|
|
|
}
|
2019-12-11 02:59:30 -05:00
|
|
|
|
2020-11-06 09:51:00 -05:00
|
|
|
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
|
2020-11-02 08:31:20 -05:00
|
|
|
$this->sendMultipartUpdate();
|
|
|
|
|
}
|
2019-10-23 06:30:00 -04:00
|
|
|
}
|
2020-11-02 08:31:20 -05:00
|
|
|
|
|
|
|
|
public function completeAction()
|
|
|
|
|
{
|
|
|
|
|
$suggestions = new ObjectSuggestions();
|
|
|
|
|
$suggestions->setModel(NotificationHistory::class);
|
|
|
|
|
$suggestions->forRequest(ServerRequest::fromGlobals());
|
|
|
|
|
$this->getDocument()->add($suggestions);
|
|
|
|
|
}
|
2021-03-05 07:45:36 -05:00
|
|
|
|
|
|
|
|
public function searchEditorAction()
|
|
|
|
|
{
|
|
|
|
|
$editor = $this->createSearchEditor(NotificationHistory::on($this->getDb()), [
|
|
|
|
|
LimitControl::DEFAULT_LIMIT_PARAM,
|
|
|
|
|
SortControl::DEFAULT_SORT_PARAM,
|
|
|
|
|
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->getDocument()->add($editor);
|
|
|
|
|
$this->setTitle(t('Adjust Filter'));
|
|
|
|
|
}
|
2019-10-23 06:30:00 -04:00
|
|
|
}
|