mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-02-20 00:10:09 -05:00
Use GridViewModeSwitcher for host and service groups
host and service groups need `GridViewModeSwitcher` to toggle between list and grid view.
This commit is contained in:
parent
9a409f0f87
commit
cc02853f54
3 changed files with 72 additions and 101 deletions
|
|
@ -29,67 +29,32 @@ class HostgroupsController extends Controller
|
|||
public function indexAction()
|
||||
{
|
||||
$this->addTitleTab(t('Host Groups'));
|
||||
$compact = $this->view->compact;
|
||||
|
||||
$db = $this->getDb();
|
||||
|
||||
$hostgroups = Hostgroupsummary::on($db);
|
||||
|
||||
yield from $this->renderHostGroups($hostgroups);
|
||||
}
|
||||
|
||||
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'));
|
||||
}
|
||||
|
||||
public function gridAction()
|
||||
{
|
||||
$this->addTitleTab(t('Host Group Grid'));
|
||||
|
||||
$db = $this->getDb();
|
||||
|
||||
$hostgroups = Hostgroupsummary::on($db)->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',
|
||||
]);
|
||||
|
||||
yield from $this->renderHostGroups($hostgroups);
|
||||
}
|
||||
|
||||
protected function renderHostGroups(Query $hostgroups)
|
||||
{
|
||||
$compact = $this->view->compact;
|
||||
$this->handleSearchRequest($hostgroups);
|
||||
|
||||
$limitControl = $this->createLimitControl();
|
||||
$paginationControl = $this->createPaginationControl($hostgroups);
|
||||
|
||||
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
|
||||
|
||||
$defaultSort = null;
|
||||
if ($viewModeSwitcher->getViewMode() === 'minimal') {
|
||||
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',
|
||||
]);
|
||||
|
||||
$defaultSort = ['hosts_severity DESC', 'display_name'];
|
||||
}
|
||||
|
||||
|
|
@ -156,4 +121,24 @@ class HostgroupsController extends Controller
|
|||
|
||||
$this->setAutorefreshInterval(30);
|
||||
}
|
||||
|
||||
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'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,39 +28,6 @@ class ServicegroupsController extends Controller
|
|||
public function indexAction()
|
||||
{
|
||||
$this->addTitleTab(t('Service Groups'));
|
||||
|
||||
yield from $this->renderServiceGroups();
|
||||
}
|
||||
|
||||
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'));
|
||||
}
|
||||
|
||||
public function gridAction()
|
||||
{
|
||||
$this->addTitleTab(t('Service Group Grid'));
|
||||
|
||||
yield from $this->renderServiceGroups();
|
||||
}
|
||||
|
||||
protected function renderServiceGroups()
|
||||
{
|
||||
$compact = $this->view->compact;
|
||||
|
||||
$db = $this->getDb();
|
||||
|
|
@ -71,11 +38,10 @@ class ServicegroupsController extends Controller
|
|||
|
||||
$limitControl = $this->createLimitControl();
|
||||
$paginationControl = $this->createPaginationControl($servicegroups);
|
||||
|
||||
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
|
||||
|
||||
$defaultSort = null;
|
||||
if ($viewModeSwitcher->getViewMode() === 'minimal') {
|
||||
if ($viewModeSwitcher->getViewMode() === 'grid') {
|
||||
$defaultSort = ['services_severity DESC', 'display_name'];
|
||||
}
|
||||
|
||||
|
|
@ -89,8 +55,6 @@ class ServicegroupsController extends Controller
|
|||
$defaultSort
|
||||
);
|
||||
|
||||
$this->params->shift($sortControl->getSortParam());
|
||||
|
||||
$searchBar = $this->createSearchBar($servicegroups, [
|
||||
$limitControl->getLimitParam(),
|
||||
$sortControl->getSortParam(),
|
||||
|
|
@ -144,4 +108,24 @@ class ServicegroupsController extends Controller
|
|||
|
||||
$this->setAutorefreshInterval(30);
|
||||
}
|
||||
|
||||
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'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ use Icinga\Module\Icingadb\Common\BaseItemList;
|
|||
use Icinga\Module\Icingadb\Common\SearchControls;
|
||||
use Icinga\Module\Icingadb\Data\CsvResultSet;
|
||||
use Icinga\Module\Icingadb\Data\JsonResultSet;
|
||||
use Icinga\Module\Icingadb\Web\Control\GridViewModeSwitcher;
|
||||
use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher;
|
||||
use Icinga\Module\Icingadb\Widget\ItemTable\StateItemTable;
|
||||
use Icinga\Module\Pdfexport\PrintableHtmlDocument;
|
||||
|
|
@ -106,14 +107,21 @@ class Controller extends CompatController
|
|||
* @param LimitControl $limitControl
|
||||
* @param bool $verticalPagination
|
||||
*
|
||||
* @return ViewModeSwitcher
|
||||
* @return ViewModeSwitcher|GridViewModeSwitcher
|
||||
*/
|
||||
public function createViewModeSwitcher(
|
||||
PaginationControl $paginationControl,
|
||||
LimitControl $limitControl,
|
||||
bool $verticalPagination = false
|
||||
): ViewModeSwitcher {
|
||||
$viewModeSwitcher = new ViewModeSwitcher();
|
||||
$controllerName = $this->getRequest()->getControllerName();
|
||||
|
||||
if ($controllerName === 'hostgroups' || $controllerName === 'servicegroups') {
|
||||
$viewModeSwitcher = new GridViewModeSwitcher();
|
||||
} else {
|
||||
$viewModeSwitcher = new ViewModeSwitcher();
|
||||
}
|
||||
|
||||
$viewModeSwitcher->setIdProtector([$this->getRequest(), 'protectId']);
|
||||
|
||||
$user = $this->Auth()->getUser();
|
||||
|
|
@ -156,16 +164,6 @@ class Controller extends CompatController
|
|||
$viewMode = $viewModeSwitcher->getValue($viewModeSwitcher->getViewModeParam());
|
||||
$requestUrl = Url::fromRequest();
|
||||
|
||||
if ($viewMode === 'minimal' && $requestUrl->getPath() === 'icingadb/hostgroups') {
|
||||
$requestUrl = Url::fromPath('icingadb/hostgroups/grid')->setParams($requestUrl->getParams());
|
||||
} elseif ($viewMode !== 'minimal' && $requestUrl->getPath() === 'icingadb/hostgroups/grid') {
|
||||
$requestUrl = Url::fromPath('icingadb/hostgroups')->setParams($requestUrl->getParams());
|
||||
} elseif ($viewMode === 'minimal' && $requestUrl->getPath() === 'icingadb/servicegroups') {
|
||||
$requestUrl = Url::fromPath('icingadb/servicegroups/grid')->setParams($requestUrl->getParams());
|
||||
} elseif ($viewMode !== 'minimal' && $requestUrl->getPath() === 'icingadb/servicegroups/grid') {
|
||||
$requestUrl = Url::fromPath('icingadb/servicegroups')->setParams($requestUrl->getParams());
|
||||
}
|
||||
|
||||
$preferredModes[$requestUrl->getPath()] = $viewMode;
|
||||
$user->setAdditional('icingadb.view_modes', $preferredModes);
|
||||
|
||||
|
|
@ -191,7 +189,7 @@ class Controller extends CompatController
|
|||
|
||||
$requestUrl->setParam($viewModeSwitcher->getViewModeParam(), $viewMode);
|
||||
if (! $requestUrl->hasParam($limitParam)) {
|
||||
if ($viewMode === 'minimal') {
|
||||
if ($viewMode === 'minimal' || $viewMode === 'grid') {
|
||||
$session->set('previous_page', $currentPage);
|
||||
$session->set('request_path', $requestUrl->getPath());
|
||||
|
||||
|
|
@ -204,7 +202,10 @@ class Controller extends CompatController
|
|||
}
|
||||
|
||||
$session->set('current_page', $currentPage);
|
||||
} elseif ($viewModeSwitcher->getDefaultViewMode() === 'minimal') {
|
||||
} elseif (
|
||||
$viewModeSwitcher->getDefaultViewMode() === 'minimal'
|
||||
|| $viewModeSwitcher->getDefaultViewMode() === 'grid'
|
||||
) {
|
||||
$limit = $paginationControl->getLimit();
|
||||
if ($currentPage === $session->get('current_page')) {
|
||||
// No other page numbers have been selected, i.e the user only
|
||||
|
|
@ -230,7 +231,8 @@ class Controller extends CompatController
|
|||
}
|
||||
)->handleRequest(ServerRequest::fromGlobals());
|
||||
|
||||
if ($viewModeSwitcher->getViewMode() === 'minimal') {
|
||||
$viewMode = $viewModeSwitcher->getViewMode();
|
||||
if ($viewMode === 'minimal' || $viewMode === 'grid') {
|
||||
$hasLimitParam = Url::fromRequest()->hasParam($limitControl->getLimitParam());
|
||||
|
||||
if ($paginationControl->getDefaultPageSize() <= LimitControl::DEFAULT_LIMIT && ! $hasLimitParam) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue