icingadb-web/application/controllers/NotificationsController.php

66 lines
1.9 KiB
PHP
Raw Normal View History

2019-10-23 06:30:00 -04:00
<?php
2019-11-04 19:07:30 -05:00
namespace Icinga\Module\Icingadb\Controllers;
2019-10-23 06:30:00 -04:00
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Model\NotificationHistory;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\ItemList\NotificationList;
use Icinga\Module\Icingadb\Widget\ShowMore;
use ipl\Web\Url;
2019-10-23 06:30:00 -04:00
class NotificationsController extends Controller
{
public function indexAction()
{
$this->setTitle($this->translate('Notifications'));
$compact = $this->view->compact;
2019-10-23 06:30:00 -04:00
$db = $this->getDb();
$notifications = NotificationHistory::on($db)->with([
'host',
'host.state',
'service',
'service.state'
]);
$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($notifications);
2019-12-11 07:56:14 -05:00
$sortControl = $this->createSortControl(
$notifications,
[
2019-12-11 14:39:26 -05:00
'notification_history.send_time desc' => $this->translate('Send Time')
2019-12-11 07:56:14 -05:00
]
);
2019-10-23 06:30:00 -04:00
$filterControl = $this->createFilterControl($notifications);
$this->filter($notifications);
$notifications->peekAhead($compact);
2019-10-23 06:30:00 -04:00
yield $this->export($notifications);
$this->addControl($paginationControl);
2019-12-11 07:56:14 -05:00
$this->addControl($sortControl);
2019-10-23 06:30:00 -04:00
$this->addControl($limitControl);
$this->addControl($filterControl);
$results = $notifications->execute();
$this->addContent(new NotificationList($results));
if ($compact) {
$this->addContent(
(new ShowMore($results, Url::fromRequest()->without(['view', 'limit'])))
->setAttribute('data-base-target', '_next')
->setAttribute('title', sprintf(
$this->translate('Show all %d notifications'),
$notifications->count()
))
);
}
$this->setAutorefreshInterval(10);
2019-10-23 06:30:00 -04:00
}
}