icingadb-web/application/controllers/ServicegroupsController.php

138 lines
4.4 KiB
PHP
Raw Normal View History

2019-11-01 18:10:34 -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-11-01 18:10:34 -04:00
use GuzzleHttp\Psr7\ServerRequest;
use Icinga\Module\Icingadb\Model\Servicegroup;
2019-11-05 03:22:58 -05:00
use Icinga\Module\Icingadb\Model\ServicegroupSummary;
use Icinga\Module\Icingadb\View\ServicegroupGridRenderer;
use Icinga\Module\Icingadb\View\ServicegroupRenderer;
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\Web\Control\ViewModeSwitcher;
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;
use ipl\Html\Attributes;
use ipl\Web\Control\LimitControl;
use ipl\Web\Control\SortControl;
use ipl\Web\Url;
use ipl\Web\Widget\ItemList;
2019-11-01 18:10:34 -04:00
class ServicegroupsController extends Controller
{
public function init()
{
parent::init();
$this->assertRouteAccess();
}
public function indexAction()
{
$this->addTitleTab(t('Service Groups'));
$compact = $this->view->compact;
2019-11-01 18:10:34 -04:00
$db = $this->getDb();
2019-11-05 03:22:58 -05:00
$servicegroups = ServicegroupSummary::on($db);
2019-11-01 18:10:34 -04:00
$this->handleSearchRequest($servicegroups);
2019-11-01 18:10:34 -04:00
$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($servicegroups);
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
2019-12-11 07:57:13 -05:00
$sortControl = $this->createSortControl(
$servicegroups,
[
'display_name' => t('Name'),
'services_severity desc, display_name' => t('Severity'),
'services_total desc' => t('Total Services')
],
['services_severity DESC', 'display_name']
2019-12-11 07:57:13 -05:00
);
$searchBar = $this->createSearchBar($servicegroups, [
$limitControl->getLimitParam(),
$sortControl->getSortParam(),
$viewModeSwitcher->getViewModeParam()
]);
2019-11-01 18:10:34 -04:00
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
if ($searchBar->hasBeenSubmitted()) {
$filter = $this->getFilter();
} else {
$this->addControl($searchBar);
$this->sendMultipartUpdate();
return;
}
} else {
$filter = $searchBar->getFilter();
}
$this->filter($servicegroups, $filter);
2019-11-01 18:10:34 -04:00
$servicegroups->peekAhead($compact);
2019-11-01 18:10:34 -04:00
yield $this->export($servicegroups);
$this->addControl($paginationControl);
2019-12-11 07:57:13 -05:00
$this->addControl($sortControl);
2019-11-01 18:10:34 -04:00
$this->addControl($limitControl);
$this->addControl($viewModeSwitcher);
$this->addControl($searchBar);
2019-11-01 18:10:34 -04:00
$results = $servicegroups->execute();
if ($viewModeSwitcher->getViewMode() === 'grid') {
$content = new ObjectGrid($results, (new ServicegroupGridRenderer())->setBaseFilter($filter));
} else {
$content = new ObjectTable($results, (new ServicegroupRenderer())->setBaseFilter($filter));
}
$content->setEmptyStateMessage($paginationControl->getEmptyStateMessage());
$this->addContent($content);
if ($compact) {
$this->addContent(
(new ShowMore($results, Url::fromRequest()->without(['showCompact', 'limit', 'view'])))
->setBaseTarget('_next')
->setAttribute('title', sprintf(
t('Show all %d servicegroups'),
$servicegroups->count()
))
);
}
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
$this->sendMultipartUpdate();
}
$this->setAutorefreshInterval(30);
2019-11-01 18:10:34 -04:00
}
public function completeAction()
{
$suggestions = new ObjectSuggestions();
$suggestions->setModel(Servicegroup::class);
$suggestions->forRequest(ServerRequest::fromGlobals());
$this->getDocument()->add($suggestions);
}
public function searchEditorAction()
{
$editor = $this->createSearchEditor(ServicegroupSummary::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-11-01 18:10:34 -04:00
}