diff --git a/application/controllers/RedundancygroupController.php b/application/controllers/RedundancygroupController.php index c65d3e723..118a5c1cd 100644 --- a/application/controllers/RedundancygroupController.php +++ b/application/controllers/RedundancygroupController.php @@ -6,7 +6,6 @@ use Icinga\Exception\NotFoundError; use Icinga\Module\Icingadb\Common\CommandActions; -use Icinga\Module\Icingadb\Common\Links; use Icinga\Module\Icingadb\Data\DependencyNodes; use Icinga\Module\Icingadb\Model\DependencyNode; use Icinga\Module\Icingadb\Model\RedundancyGroup; @@ -14,7 +13,6 @@ use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions; use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher; use Icinga\Module\Icingadb\Web\Controller; -use Icinga\Module\Icingadb\Widget\DependencyNodeStatistics; use Icinga\Module\Icingadb\Widget\Detail\MultiselectQuickActions; use Icinga\Module\Icingadb\Widget\Detail\RedundancyGroupDetail; use Icinga\Module\Icingadb\Widget\ItemList\DependencyNodeList; @@ -46,34 +44,34 @@ public function init(): void } $this->groupId = $groupId; + } + /** + * Load the redundancy group + */ + protected function loadGroup(): void + { $query = RedundancyGroup::on($this->getDb()) ->with(['state']) ->filter(Filter::equal('id', $this->groupId)); - $this->applyRestrictions($query); + $this->filter($query); $this->group = $query->first(); if ($this->group === null) { - throw new NotFoundError(t('Redundancy Group not found')); + throw new NotFoundError($this->translate('Redundancy Group not found')); } $this->setTitleTab($this->getRequest()->getActionName()); $this->setTitle($this->group->display_name); $this->addControl(new HtmlElement('div', null, Text::create($this->group->display_name))); - $this->addFooter( - new DependencyNodeStatistics( - RedundancyGroupSummary::on($this->getDb()) - ->filter(Filter::equal('id', $this->groupId)) - ->first() - ) - ); } public function indexAction(): void { + $this->loadGroup(); $summary = RedundancyGroupSummary::on($this->getDb()) ->filter(Filter::equal('id', $this->groupId)); @@ -90,25 +88,19 @@ public function indexAction(): void $this->addContent(new RedundancyGroupDetail($this->group)); } - public function membersAction(): \Generator + public function membersAction(): void { + $this->loadGroup(); $nodesQuery = $this->fetchNodes(true); $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') - ] - ); + $sortControl = $this->createSortControl($nodesQuery); $viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl); - $searchBar = $this->createSearchBar($nodesQuery, - Links::redundancyGroupMembers($this->group), + $searchBar = $this->createSearchBar( + $nodesQuery, + Url::fromPath('icingadb/redundancygroup/members', ['id' => $this->groupId]), [ $limitControl->getLimitParam(), $sortControl->getSortParam(), @@ -131,8 +123,6 @@ public function membersAction(): \Generator $nodesQuery->filter($filter); - yield $this->export($nodesQuery); - $this->addControl($paginationControl); $this->addControl($sortControl); $this->addControl($limitControl); @@ -151,26 +141,19 @@ public function membersAction(): \Generator $this->setAutorefreshInterval(10); } - public function childrenAction() + public function childrenAction(): void { + $this->loadGroup(); $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') - ] - ); + $sortControl = $this->createSortControl($nodesQuery); $viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl); $searchBar = $this->createSearchBar( $nodesQuery, - Links::redundancyGroupChildren($this->group), + Url::fromPath('icingadb/redundancygroup/children', ['id' => $this->groupId]), [ $limitControl->getLimitParam(), $sortControl->getSortParam(), @@ -196,8 +179,6 @@ public function childrenAction() $nodesQuery->filter($filter); - yield $this->export($nodesQuery); - $this->addControl($paginationControl); $this->addControl($sortControl); $this->addControl($limitControl); @@ -233,10 +214,11 @@ public function searchEditorAction(): void { $isChildrenTab = $this->params->shift('isChildrenTab'); $redirectUrl = $isChildrenTab - ? Links::redundancyGroupChildren($this->group) - : Links::redundancyGroupMembers($this->group); + ? Url::fromPath('icingadb/redundancygroup/children', ['id' => $this->groupId]) + : Url::fromPath('icingadb/redundancygroup/members', ['id' => $this->groupId]); - $editor = $this->createSearchEditor(DependencyNode::on($this->getDb()), + $editor = $this->createSearchEditor( + DependencyNode::on($this->getDb()), $redirectUrl, [ LimitControl::DEFAULT_LIMIT_PARAM, @@ -251,23 +233,23 @@ public function searchEditorAction(): void } $this->getDocument()->add($editor); - $this->setTitle(t('Adjust Filter')); + $this->setTitle($this->translate('Adjust Filter')); } protected function createTabs(): Tabs { $tabs = $this->getTabs() ->add('index', [ - 'label' => t('Redundancy Group'), - 'url' => Links::redundancyGroup($this->group) + 'label' => $this->translate('Redundancy Group'), + 'url' => Url::fromPath('icingadb/redundancygroup', ['id' => $this->groupId]) ]) ->add('members', [ - 'label' => t('Members'), - 'url' => Links::redundancyGroupMembers($this->group) + 'label' => $this->translate('Members'), + 'url' => Url::fromPath('icingadb/redundancygroup/members', ['id' => $this->groupId]) ]) ->add('children', [ - 'label' => t('Children'), - 'url' => Links::redundancyGroupChildren($this->group) + 'label' => $this->translate('Children'), + 'url' => Url::fromPath('icingadb/redundancygroup/children', ['id' => $this->groupId]) ]); return $tabs; @@ -282,6 +264,25 @@ protected function setTitleTab(string $name): void } } + public function createSortControl(Query $query, array $columns = null): SortControl + { + $sortRules = [ + 'host.display_name, service.display_name, redundancy_group.display_name' => $this->translate('Name'), + 'service.state.severity desc, service.state.last_state_change desc, ' + . 'host.state.severity desc, host.state.last_state_change desc, ' + . 'redundancy_group.state.failed desc, redundancy_group.state.last_state_change desc' => $this->translate( + 'Severity' + ), + 'service.state.soft_state, host.state.soft_state, redundancy_group.state.failed' => $this->translate( + 'Current State' + ), + 'service.state.last_state_change desc, host.state.last_state_change desc, ' + . 'redundancy_group.state.last_state_change desc' => $this->translate('Last State Change') + ]; + + return parent::createSortControl($query, $sortRules); + } + /** * Fetch the nodes for the current group * @@ -333,7 +334,7 @@ protected function fetchCommandTargets() protected function getCommandTargetsUrl(): Url { - return Links::redundancyGroup($this->group); + return Url::fromPath('icingadb/redundancygroup', ['id' => $this->groupId]); } public function processCheckresultAction(): void