icingadb-web/application/controllers/HostgroupsController.php

88 lines
2.6 KiB
PHP
Raw Normal View History

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;
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;
use Icinga\Module\Icingadb\Widget\ItemList\HostgroupList;
use Icinga\Module\Icingadb\Widget\ShowMore;
use ipl\Web\Url;
2019-10-31 11:17:29 -04:00
class HostgroupsController extends Controller
{
public function indexAction()
{
$this->setTitle(t('Host Groups'));
$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);
2019-12-11 07:54:11 -05:00
$sortControl = $this->createSortControl(
$hostgroups,
[
'display_name' => t('Name'),
'hosts_severity desc' => t('Severity'),
'hosts_total desc' => t('Total Hosts'),
'services_total desc' => t('Total Services')
2019-12-11 07:54:11 -05:00
]
);
2020-11-02 08:30:34 -05:00
$searchBar = $this->createSearchBar($hostgroups, [
$limitControl->getLimitParam(),
$sortControl->getSortParam()
]);
2019-10-31 11:17:29 -04:00
2020-11-02 08:30:34 -05:00
$this->filter($hostgroups, $searchBar->getFilter());
2019-10-31 11:17:29 -04: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);
2020-11-02 08:30:34 -05:00
$this->addControl($searchBar);
2019-10-31 11:17:29 -04:00
$results = $hostgroups->execute();
$this->addContent(
(new HostgroupList($results))->setBaseFilter($this->getFilter())
);
if ($compact) {
$this->addContent(
(new ShowMore($results, Url::fromRequest()->without(['showCompact', 'limit'])))
->setAttribute('data-base-target', '_next')
->setAttribute('title', sprintf(
t('Show all %d hostgroups'),
$hostgroups->count()
))
);
}
2020-11-02 08:30:34 -05:00
if ($searchBar->hasBeenSent()) {
$this->sendMultipartUpdate();
}
$this->setAutorefreshInterval(30);
2019-10-31 11:17:29 -04:00
}
2020-11-02 08:30:34 -05:00
public function completeAction()
{
$suggestions = new ObjectSuggestions();
$suggestions->setModel(Hostgroup::class);
$suggestions->forRequest(ServerRequest::fromGlobals());
$this->getDocument()->add($suggestions);
}
2019-10-31 11:17:29 -04:00
}