Skip to content

Commit

Permalink
Fix sort control
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Nov 19, 2024
1 parent aa0754d commit 46f7097
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
39 changes: 18 additions & 21 deletions application/controllers/RedundancygroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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(
Expand Down Expand Up @@ -155,7 +163,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(
Expand Down Expand Up @@ -270,25 +286,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
*
Expand Down
27 changes: 26 additions & 1 deletion library/Icingadb/Model/DependencyNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use ipl\Orm\Model;
use ipl\Orm\Query;
use ipl\Orm\Relations;
use ipl\Sql\Expression;

/**
* Dependency node model.
Expand All @@ -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
Expand All @@ -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'
]
),
];
}

Expand Down

0 comments on commit 46f7097

Please sign in to comment.