2019-10-31 11:17:29 -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-31 11:17:29 -04:00
|
|
|
|
2020-11-02 08:30:34 -05:00
|
|
|
use GuzzleHttp\Psr7\ServerRequest;
|
|
|
|
|
use Icinga\Module\Icingadb\Model\Hostgroup;
|
2019-11-04 19:07:30 -05:00
|
|
|
use Icinga\Module\Icingadb\Model\Hostgroupsummary;
|
2025-03-25 06:31:29 -04:00
|
|
|
use Icinga\Module\Icingadb\View\HostgroupGridRenderer;
|
|
|
|
|
use Icinga\Module\Icingadb\View\HostgroupRenderer;
|
2020-11-02 08:30:34 -05:00
|
|
|
use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions;
|
2019-11-04 19:07:30 -05:00
|
|
|
use Icinga\Module\Icingadb\Web\Controller;
|
2021-08-20 11:23:29 -04:00
|
|
|
use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher;
|
2025-03-25 09:48:57 -04:00
|
|
|
use Icinga\Module\Icingadb\Widget\ItemTable\ObjectGrid;
|
|
|
|
|
use Icinga\Module\Icingadb\Widget\ItemTable\ObjectTable;
|
2023-08-09 08:25:44 -04:00
|
|
|
use Icinga\Module\Icingadb\Widget\ShowMore;
|
2021-03-05 07:45:36 -05:00
|
|
|
use ipl\Web\Control\LimitControl;
|
|
|
|
|
use ipl\Web\Control\SortControl;
|
2020-01-31 09:57:11 -05:00
|
|
|
use ipl\Web\Url;
|
2019-10-31 11:17:29 -04:00
|
|
|
|
|
|
|
|
class HostgroupsController extends Controller
|
|
|
|
|
{
|
2021-04-07 06:33:53 -04:00
|
|
|
public function init()
|
|
|
|
|
{
|
|
|
|
|
parent::init();
|
|
|
|
|
|
|
|
|
|
$this->assertRouteAccess();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-17 10:33:35 -05:00
|
|
|
public function indexAction()
|
|
|
|
|
{
|
2022-03-16 11:06:00 -04:00
|
|
|
$this->addTitleTab(t('Host Groups'));
|
2023-06-05 07:27:27 -04:00
|
|
|
$compact = $this->view->compact;
|
2019-10-31 11:17:29 -04:00
|
|
|
|
|
|
|
|
$db = $this->getDb();
|
|
|
|
|
|
|
|
|
|
$hostgroups = Hostgroupsummary::on($db);
|
|
|
|
|
|
2020-11-02 08:30:34 -05:00
|
|
|
$this->handleSearchRequest($hostgroups);
|
|
|
|
|
|
2019-10-31 11:17:29 -04:00
|
|
|
$limitControl = $this->createLimitControl();
|
|
|
|
|
$paginationControl = $this->createPaginationControl($hostgroups);
|
2023-06-02 07:48:27 -04:00
|
|
|
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
|
|
|
|
|
|
2023-06-05 07:27:27 -04:00
|
|
|
if ($viewModeSwitcher->getViewMode() === 'grid') {
|
|
|
|
|
$hostgroups->without([
|
|
|
|
|
'services_critical_handled',
|
|
|
|
|
'services_critical_unhandled',
|
|
|
|
|
'services_ok',
|
|
|
|
|
'services_pending',
|
|
|
|
|
'services_total',
|
|
|
|
|
'services_unknown_handled',
|
|
|
|
|
'services_unknown_unhandled',
|
|
|
|
|
'services_warning_handled',
|
|
|
|
|
'services_warning_unhandled',
|
|
|
|
|
]);
|
2023-06-02 07:48:27 -04:00
|
|
|
}
|
|
|
|
|
|
2019-12-11 07:54:11 -05:00
|
|
|
$sortControl = $this->createSortControl(
|
|
|
|
|
$hostgroups,
|
|
|
|
|
[
|
2023-06-02 07:48:27 -04:00
|
|
|
'display_name' => t('Name'),
|
|
|
|
|
'hosts_severity desc, display_name' => t('Severity'),
|
|
|
|
|
'hosts_total desc' => t('Total Hosts'),
|
|
|
|
|
],
|
2025-01-09 09:47:55 -05:00
|
|
|
['hosts_severity DESC', 'display_name']
|
2019-12-11 07:54:11 -05:00
|
|
|
);
|
2023-06-02 07:48:27 -04:00
|
|
|
|
2020-11-02 08:30:34 -05:00
|
|
|
$searchBar = $this->createSearchBar($hostgroups, [
|
2020-05-19 06:34:08 -04:00
|
|
|
$limitControl->getLimitParam(),
|
2021-09-16 09:09:30 -04:00
|
|
|
$sortControl->getSortParam(),
|
|
|
|
|
$viewModeSwitcher->getViewModeParam()
|
2020-05-19 06:34:08 -04:00
|
|
|
]);
|
2019-10-31 11:17:29 -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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->filter($hostgroups, $filter);
|
2019-10-31 11:17:29 -04:00
|
|
|
|
2020-01-31 09:57:11 -05:00
|
|
|
$hostgroups->peekAhead($compact);
|
|
|
|
|
|
2019-10-31 11:17:29 -04:00
|
|
|
yield $this->export($hostgroups);
|
|
|
|
|
|
|
|
|
|
$this->addControl($paginationControl);
|
2019-12-11 07:54:11 -05:00
|
|
|
$this->addControl($sortControl);
|
2019-10-31 11:17:29 -04:00
|
|
|
$this->addControl($limitControl);
|
2021-09-16 09:09:30 -04:00
|
|
|
$this->addControl($viewModeSwitcher);
|
2020-11-02 08:30:34 -05:00
|
|
|
$this->addControl($searchBar);
|
2019-10-31 11:17:29 -04:00
|
|
|
|
2020-01-31 09:57:11 -05:00
|
|
|
$results = $hostgroups->execute();
|
|
|
|
|
|
2025-03-25 06:31:29 -04:00
|
|
|
if ($viewModeSwitcher->getViewMode() === 'grid') {
|
2025-03-25 09:48:57 -04:00
|
|
|
$content = new ObjectGrid($results, (new HostgroupGridRenderer())->setBaseFilter($filter));
|
2025-03-25 06:31:29 -04:00
|
|
|
} else {
|
2025-03-25 09:48:57 -04:00
|
|
|
$content = new ObjectTable($results, (new HostgroupRenderer())->setBaseFilter($filter));
|
2025-03-25 06:31:29 -04:00
|
|
|
}
|
|
|
|
|
|
2025-05-06 05:17:39 -04:00
|
|
|
$content->setEmptyStateMessage($paginationControl->getEmptyStateMessage());
|
|
|
|
|
|
2025-03-25 09:48:57 -04:00
|
|
|
$this->addContent($content);
|
2019-12-11 02:59:30 -05:00
|
|
|
|
2020-01-31 09:57:11 -05:00
|
|
|
if ($compact) {
|
|
|
|
|
$this->addContent(
|
2022-08-04 10:07:28 -04:00
|
|
|
(new ShowMore($results, Url::fromRequest()->without(['showCompact', 'limit', 'view'])))
|
2021-08-02 10:02:05 -04:00
|
|
|
->setBaseTarget('_next')
|
2020-01-31 09:57:11 -05:00
|
|
|
->setAttribute('title', sprintf(
|
2020-04-24 08:36:37 -04:00
|
|
|
t('Show all %d hostgroups'),
|
2020-01-31 09:57:11 -05:00
|
|
|
$hostgroups->count()
|
|
|
|
|
))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-06 09:51:00 -05:00
|
|
|
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
|
2020-11-02 08:30:34 -05:00
|
|
|
$this->sendMultipartUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 02:59:30 -05:00
|
|
|
$this->setAutorefreshInterval(30);
|
2019-10-31 11:17:29 -04:00
|
|
|
}
|
2023-06-05 07:27:27 -04:00
|
|
|
|
|
|
|
|
public function completeAction()
|
|
|
|
|
{
|
|
|
|
|
$suggestions = new ObjectSuggestions();
|
|
|
|
|
$suggestions->setModel(Hostgroup::class);
|
|
|
|
|
$suggestions->forRequest(ServerRequest::fromGlobals());
|
|
|
|
|
$this->getDocument()->add($suggestions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function searchEditorAction()
|
|
|
|
|
{
|
|
|
|
|
$editor = $this->createSearchEditor(Hostgroupsummary::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-31 11:17:29 -04:00
|
|
|
}
|