From b18bc644404e02b57635bfcc8258e85abb141146 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:44:46 +0200 Subject: Adding upstream version 1.1.1. Signed-off-by: Daniel Baumann --- application/controllers/HostgroupsController.php | 145 +++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 application/controllers/HostgroupsController.php (limited to 'application/controllers/HostgroupsController.php') diff --git a/application/controllers/HostgroupsController.php b/application/controllers/HostgroupsController.php new file mode 100644 index 0000000..700c6fd --- /dev/null +++ b/application/controllers/HostgroupsController.php @@ -0,0 +1,145 @@ +assertRouteAccess(); + } + + public function indexAction() + { + $this->addTitleTab(t('Host Groups')); + $compact = $this->view->compact; + + $db = $this->getDb(); + + $hostgroups = Hostgroupsummary::on($db); + + $this->handleSearchRequest($hostgroups); + + $limitControl = $this->createLimitControl(); + $paginationControl = $this->createPaginationControl($hostgroups); + $viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl); + + $defaultSort = null; + 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']; + } + + $sortControl = $this->createSortControl( + $hostgroups, + [ + 'display_name' => t('Name'), + 'hosts_severity desc, display_name' => t('Severity'), + 'hosts_total desc' => t('Total Hosts'), + ], + $defaultSort + ); + + $searchBar = $this->createSearchBar($hostgroups, [ + $limitControl->getLimitParam(), + $sortControl->getSortParam(), + $viewModeSwitcher->getViewModeParam() + ]); + + if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { + if ($searchBar->hasBeenSubmitted()) { + $filter = $this->getFilter(); + } else { + $this->addControl($searchBar); + $this->sendMultipartUpdate(); + return; + } + } else { + $filter = $searchBar->getFilter(); + } + + $this->filter($hostgroups, $filter); + + $hostgroups->peekAhead($compact); + + yield $this->export($hostgroups); + + $this->addControl($paginationControl); + $this->addControl($sortControl); + $this->addControl($limitControl); + $this->addControl($viewModeSwitcher); + $this->addControl($searchBar); + + $results = $hostgroups->execute(); + + $this->addContent( + (new HostgroupTable($results)) + ->setBaseFilter($filter) + ->setViewMode($viewModeSwitcher->getViewMode()) + ); + + if ($compact) { + $this->addContent( + (new ShowMore($results, Url::fromRequest()->without(['showCompact', 'limit', 'view']))) + ->setBaseTarget('_next') + ->setAttribute('title', sprintf( + t('Show all %d hostgroups'), + $hostgroups->count() + )) + ); + } + + if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { + $this->sendMultipartUpdate(); + } + + $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')); + } +} -- cgit v1.2.3