From dc09970353822a79e88273efc9e78f2bda3bae91 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Tue, 19 Nov 2024 14:19:43 +0100 Subject: [PATCH] Fix sort control --- .../controllers/RedundancygroupController.php | 39 +++++++++---------- library/Icingadb/Model/DependencyNode.php | 27 ++++++++++++- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/application/controllers/RedundancygroupController.php b/application/controllers/RedundancygroupController.php index d9ebc57ed..17db3bcb6 100644 --- a/application/controllers/RedundancygroupController.php +++ b/application/controllers/RedundancygroupController.php @@ -104,7 +104,15 @@ public function membersAction(): void $limitControl = $this->createLimitControl(); $paginationControl = $this->createPaginationControl($nodesQuery); - $sortControl = $this->createSortControl($nodesQuery); + $sortControl = $this->createSortControl( + $nodesQuery, + [ + 'name' => $this->translate('Name'), + 'severity desc, last_state_change desc' => $this->translate('Severity'), + 'state' => $this->translate('Current State'), + 'last_state_change desc' => $this->translate('Last State Change') + ] + ); $viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl); $searchBar = $this->createSearchBar( @@ -156,7 +164,15 @@ public function childrenAction(): void $limitControl = $this->createLimitControl(); $paginationControl = $this->createPaginationControl($nodesQuery); - $sortControl = $this->createSortControl($nodesQuery); + $sortControl = $this->createSortControl( + $nodesQuery, + [ + 'name' => $this->translate('Name'), + 'severity desc, last_state_change desc' => $this->translate('Severity'), + 'state' => $this->translate('Current State'), + 'last_state_change desc' => $this->translate('Last State Change') + ] + ); $viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl); $searchBar = $this->createSearchBar( @@ -271,25 +287,6 @@ 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 * diff --git a/library/Icingadb/Model/DependencyNode.php b/library/Icingadb/Model/DependencyNode.php index 635d3a834..a63ec56c8 100644 --- a/library/Icingadb/Model/DependencyNode.php +++ b/library/Icingadb/Model/DependencyNode.php @@ -10,6 +10,7 @@ use ipl\Orm\Model; use ipl\Orm\Query; use ipl\Orm\Relations; +use ipl\Sql\Expression; /** * Dependency node model. @@ -18,6 +19,10 @@ * @property ?string $host_id * @property ?string $service_id * @property ?string $redundancy_group_id + * @property string $name + * @property string $severity + * @property string $state + * @property string $last_state_change * * @property (?Host)|Query $host * @property (?Service)|Query $service @@ -43,7 +48,27 @@ public function getColumns(): array 'id', 'host_id', 'service_id', - 'redundancy_group_id' + 'redundancy_group_id', + 'name' => new Expression( + 'COALESCE(%s, %s, %s)', + ['service.display_name', 'host.display_name', 'redundancy_group.display_name'] + ), + 'severity' => new Expression( + 'COALESCE(%s, %s, %s)', + ['service.state.severity', 'host.state.severity', 'redundancy_group.state.failed'] + ), + 'state' => new Expression( + 'COALESCE(%s, %s, %s)', + ['service.state.soft_state', 'host.state.soft_state', 'redundancy_group.state.failed'] + ), + 'last_state_change' => new Expression( + 'COALESCE(%s, %s, %s)', + [ + 'service.state.last_state_change', + 'host.state.last_state_change', + 'redundancy_group.state.last_state_change' + ] + ), ]; }