diff --git a/application/controllers/RedundancygroupController.php b/application/controllers/RedundancygroupController.php index 6713e4799..03b0556f5 100644 --- a/application/controllers/RedundancygroupController.php +++ b/application/controllers/RedundancygroupController.php @@ -19,6 +19,7 @@ use Icinga\Module\Icingadb\Widget\Detail\ObjectHeader; use Icinga\Module\Icingadb\Widget\Detail\RedundancyGroupDetail; use Icinga\Module\Icingadb\Widget\ItemList\DependencyNodeList; +use ipl\Orm\Query; use ipl\Stdlib\Filter; use ipl\Web\Control\LimitControl; use ipl\Web\Control\SortControl; @@ -51,10 +52,18 @@ public function init(): void throw new NotFoundError(t('Redundancy Group not found')); } - $this->addControl(new ObjectHeader($this->group)); - $this->setTitleTab($this->getRequest()->getActionName()); $this->setTitle($this->group->display_name); + + $this->addControl(new ObjectHeader($this->group)); + + $this->addFooter( + new DependencyNodeStatistics( + RedundancyGroupSummary::on($this->getDb()) + ->filter(Filter::equal('id', $this->groupId)) + ->first() + ) + ); } public function indexAction() @@ -75,21 +84,12 @@ public function indexAction() public function membersAction() { - $membersQuery = DependencyNode::on($this->getDb()) - ->with([ - 'host', - 'host.state', - 'service', - 'service.state', - 'service.host', - 'service.host.state' - ]) - ->filter(Filter::equal('child.redundancy_group.id', $this->groupId)); + $nodesQuery = $this->fetchNodes(true); $limitControl = $this->createLimitControl(); - $paginationControl = $this->createPaginationControl($membersQuery); + $paginationControl = $this->createPaginationControl($nodesQuery); $sortControl = $this->createSortControl( - $membersQuery, + $nodesQuery, [ 'name' => t('Name'), 'severity desc, last_state_change desc' => t('Severity'), @@ -99,7 +99,7 @@ public function membersAction() ); $viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl); - $searchBar = $this->createSearchBar($membersQuery, + $searchBar = $this->createSearchBar($nodesQuery, Links::redundancyGroupMembers($this->group), [ $limitControl->getLimitParam(), @@ -123,9 +123,9 @@ public function membersAction() $filter = $searchBar->getFilter(); } - $membersQuery->filter($filter); + $nodesQuery->filter($filter); - yield $this->export($membersQuery); + yield $this->export($nodesQuery); $this->addControl(new HtmlElement('div', null, Text::create($this->group->display_name))); @@ -136,18 +136,74 @@ public function membersAction() $this->addControl($searchBar); $this->addContent( - (new DependencyNodeList($membersQuery->execute())) + (new DependencyNodeList($nodesQuery->execute())) ->setViewMode($viewModeSwitcher->getViewMode()) ); - $this->addFooter( - new DependencyNodeStatistics( - RedundancyGroupSummary::on($this->getDb()) - ->filter(Filter::equal('id', $this->groupId)) - ->first() - ) + if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { + $this->sendMultipartUpdate(); + } + + $this->setAutorefreshInterval(10); + } + + public function childrenAction() + { + $nodesQuery = $this->fetchNodes(); + + $limitControl = $this->createLimitControl(); + $paginationControl = $this->createPaginationControl($nodesQuery); + $sortControl = $this->createSortControl( + $nodesQuery, + [ + 'name' => t('Name'), + 'severity desc, last_state_change desc' => t('Severity'), + 'state' => t('Current State'), + 'last_state_change desc' => t('Last State Change') + ] + ); + $viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl); + + $searchBar = $this->createSearchBar($nodesQuery, + Links::redundancyGroupMembers($this->group), + [ + $limitControl->getLimitParam(), + $sortControl->getSortParam(), + $viewModeSwitcher->getViewModeParam(), + 'id' + ] ); + $searchBar->getSuggestionUrl()->addParams(['id' => $this->groupId]); + + if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { + if ($searchBar->hasBeenSubmitted()) { + $filter = $this->getFilter(); + } else { + $this->addControl($searchBar); + $this->sendMultipartUpdate(); + return; + } + } else { + $filter = $searchBar->getFilter(); + } + + $nodesQuery->filter($filter); + + yield $this->export($nodesQuery); + + $this->addControl($paginationControl); + $this->addControl($sortControl); + $this->addControl($limitControl); + $this->addControl($viewModeSwitcher); + $this->addControl($searchBar); + + $this->addContent( + (new DependencyNodeList($nodesQuery->execute())) + ->setViewMode($viewModeSwitcher->getViewMode()) + ); + + if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) { $this->sendMultipartUpdate(); } @@ -195,6 +251,10 @@ protected function createTabs(): Tabs ->add('members', [ 'label' => t('Members'), 'url' => Links::redundancyGroupMembers($this->group) + ]) + ->add('children', [ + 'label' => t('Children'), + 'url' => Links::redundancyGroupChildren($this->group) ]); return $tabs; @@ -238,4 +298,30 @@ protected function getCommandTargetsUrl(): Url { return Links::redundancyGroup($this->group); } + + /** + * Fetch the nodes for the current group + * + * @param bool $fetchParents Whether to fetch the parents or the children + * + * @return Query + */ + private function fetchNodes(bool $fetchParents = false): Query + { + $filterColumn = sprintf( + '%s.redundancy_group.id', + $fetchParents ? 'child' : 'parent' + ); + + return DependencyNode::on($this->getDb()) + ->with([ + 'host', + 'host.state', + 'service', + 'service.state', + 'service.host', + 'service.host.state' + ]) + ->filter(Filter::equal($filterColumn, $this->groupId)); + } } \ No newline at end of file diff --git a/library/Icingadb/Common/Links.php b/library/Icingadb/Common/Links.php index 26151c2b8..c0ec54954 100644 --- a/library/Icingadb/Common/Links.php +++ b/library/Icingadb/Common/Links.php @@ -117,6 +117,11 @@ public static function redundancyGroupMembers(RedundancyGroup $group): Url return Url::fromPath('icingadb/redundancygroup/members', ['id' => bin2hex($group->id)]); } + public static function redundancyGroupChildren(RedundancyGroup $group): Url + { + return Url::fromPath('icingadb/redundancygroup/children', ['id' => bin2hex($group->id)]); + } + public static function toggleHostsFeatures(): Url { return Url::fromPath('icingadb/hosts/toggle-features');