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
|
|
|
|
2020-11-02 08:31:47 -05: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;
|
2025-03-25 06:31:29 -04:00
|
|
|
use Icinga\Module\Icingadb\View\ServicegroupGridRenderer;
|
|
|
|
|
use Icinga\Module\Icingadb\View\ServicegroupRenderer;
|
2020-11-02 08:31:47 -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;
|
2025-03-25 06:31:29 -04:00
|
|
|
use ipl\Html\Attributes;
|
2021-03-05 07:45:36 -05:00
|
|
|
use ipl\Web\Control\LimitControl;
|
|
|
|
|
use ipl\Web\Control\SortControl;
|
2020-01-31 09:57:28 -05:00
|
|
|
use ipl\Web\Url;
|
2025-03-25 06:31:29 -04:00
|
|
|
use ipl\Web\Widget\ItemList;
|
2019-11-01 18:10:34 -04:00
|
|
|
|
|
|
|
|
class ServicegroupsController extends Controller
|
|
|
|
|
{
|
2021-04-07 06:34:09 -04:00
|
|
|
public function init()
|
|
|
|
|
{
|
|
|
|
|
parent::init();
|
|
|
|
|
|
|
|
|
|
$this->assertRouteAccess();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-17 10:34:16 -05:00
|
|
|
public function indexAction()
|
|
|
|
|
{
|
2022-03-16 11:06:00 -04:00
|
|
|
$this->addTitleTab(t('Service Groups'));
|
2020-01-31 09:57:28 -05:00
|
|
|
$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
|
|
|
|
2020-11-02 08:31:47 -05:00
|
|
|
$this->handleSearchRequest($servicegroups);
|
|
|
|
|
|
2019-11-01 18:10:34 -04:00
|
|
|
$limitControl = $this->createLimitControl();
|
|
|
|
|
$paginationControl = $this->createPaginationControl($servicegroups);
|
2023-06-02 07:48:27 -04:00
|
|
|
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
|
|
|
|
|
|
2019-12-11 07:57:13 -05:00
|
|
|
$sortControl = $this->createSortControl(
|
|
|
|
|
$servicegroups,
|
|
|
|
|
[
|
2023-06-02 07:48:27 -04:00
|
|
|
'display_name' => t('Name'),
|
|
|
|
|
'services_severity desc, display_name' => t('Severity'),
|
|
|
|
|
'services_total desc' => t('Total Services')
|
|
|
|
|
],
|
2025-01-09 09:47:55 -05:00
|
|
|
['services_severity DESC', 'display_name']
|
2019-12-11 07:57:13 -05:00
|
|
|
);
|
2023-06-02 07:48:27 -04:00
|
|
|
|
2020-11-02 08:31:47 -05:00
|
|
|
$searchBar = $this->createSearchBar($servicegroups, [
|
2020-05-19 06:34:24 -04:00
|
|
|
$limitControl->getLimitParam(),
|
2021-09-16 09:09:30 -04:00
|
|
|
$sortControl->getSortParam(),
|
|
|
|
|
$viewModeSwitcher->getViewModeParam()
|
2020-05-19 06:34:24 -04:00
|
|
|
]);
|
2019-11-01 18:10:34 -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($servicegroups, $filter);
|
2019-11-01 18:10:34 -04:00
|
|
|
|
2020-01-31 09:57:28 -05: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);
|
2021-09-16 09:09:30 -04:00
|
|
|
$this->addControl($viewModeSwitcher);
|
2020-11-02 08:31:47 -05:00
|
|
|
$this->addControl($searchBar);
|
2019-11-01 18:10:34 -04:00
|
|
|
|
2020-01-31 09:57:28 -05:00
|
|
|
$results = $servicegroups->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 ServicegroupGridRenderer())->setBaseFilter($filter));
|
2025-03-25 06:31:29 -04:00
|
|
|
} else {
|
2025-03-25 09:48:57 -04:00
|
|
|
$content = new ObjectTable($results, (new ServicegroupRenderer())->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:28 -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:28 -05:00
|
|
|
->setAttribute('title', sprintf(
|
2020-04-24 08:36:37 -04:00
|
|
|
t('Show all %d servicegroups'),
|
2020-01-31 09:57:28 -05:00
|
|
|
$servicegroups->count()
|
|
|
|
|
))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-06 09:51:00 -05:00
|
|
|
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
|
2020-11-02 08:31:47 -05:00
|
|
|
$this->sendMultipartUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 02:59:30 -05:00
|
|
|
$this->setAutorefreshInterval(30);
|
2019-11-01 18:10:34 -04:00
|
|
|
}
|
2023-06-05 07:27:27 -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
|
|
|
}
|