diff --git a/library/Icinga/Data/SimpleQuery.php b/library/Icinga/Data/SimpleQuery.php index 8860303950..704a6ff8a9 100644 --- a/library/Icinga/Data/SimpleQuery.php +++ b/library/Icinga/Data/SimpleQuery.php @@ -161,6 +161,26 @@ public function setOrderColumns(array $orderColumns) throw new IcingaException('This function does nothing and will be removed'); } + /** + * Split order field into its field and sort direction + * + * @param string $field + * + * @return array + */ + public function splitOrder($field) + { + $fieldAndDirection = explode(' ', $field, 2); + if (count($fieldAndDirection) === 1) { + $direction = null; + } else { + $field = $fieldAndDirection[0]; + $direction = (strtoupper(trim($fieldAndDirection[1])) === 'DESC') ? + Sortable::SORT_DESC : Sortable::SORT_ASC; + } + return array($field, $direction); + } + /** * Sort result set by the given field (and direction) * @@ -177,13 +197,9 @@ public function setOrderColumns(array $orderColumns) public function order($field, $direction = null) { if ($direction === null) { - $fieldAndDirection = explode(' ', $field, 2); - if (count($fieldAndDirection) === 1) { - $direction = self::SORT_ASC; - } else { - $field = $fieldAndDirection[0]; - $direction = (strtoupper(trim($fieldAndDirection[1])) === 'DESC') ? - Sortable::SORT_DESC : Sortable::SORT_ASC; + list($field, $direction) = $this->splitOrder($field); + if ($direction === null) { + $direction = Sortable::SORT_ASC; } } else { switch (($direction = strtoupper($direction))) { diff --git a/modules/monitoring/library/Monitoring/DataView/DataView.php b/modules/monitoring/library/Monitoring/DataView/DataView.php index 9683c468f5..c9537eff83 100644 --- a/modules/monitoring/library/Monitoring/DataView/DataView.php +++ b/modules/monitoring/library/Monitoring/DataView/DataView.php @@ -242,6 +242,7 @@ public function sort($column = null, $order = null) $order = (strtoupper($order) === static::SORT_ASC) ? 'ASC' : 'DESC'; foreach ($sortColumns['columns'] as $column) { + list($column, $direction) = $this->query->splitOrder($column); if (! $this->isValidFilterTarget($column)) { throw new QueryException( mt('monitoring', 'The sort column "%s" is not allowed in "%s".'), @@ -249,7 +250,7 @@ public function sort($column = null, $order = null) get_class($this) ); } - $this->query->order($column, $order); + $this->query->order($column, $direction !== null ? $direction : $order); } $this->isSorted = true; return $this; diff --git a/modules/monitoring/library/Monitoring/DataView/HostStatus.php b/modules/monitoring/library/Monitoring/DataView/HostStatus.php index a78e4b143e..7a7c28b0ca 100644 --- a/modules/monitoring/library/Monitoring/DataView/HostStatus.php +++ b/modules/monitoring/library/Monitoring/DataView/HostStatus.php @@ -92,10 +92,10 @@ public function getSortRules() return array( 'host_severity' => array( 'columns' => array( - 'host_severity', - 'host_last_state_change', - ), - 'order' => self::SORT_DESC + 'host_severity DESC', + 'host_last_state_change DESC', + 'host_display_name ASC' + ) ), 'host_display_name' => array( 'order' => self::SORT_ASC diff --git a/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php b/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php index 5c37e45eed..3e3a1c6168 100644 --- a/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php +++ b/modules/monitoring/library/Monitoring/DataView/ServiceStatus.php @@ -125,18 +125,27 @@ public function getSortRules() return array( 'service_severity' => array( 'columns' => array( - 'service_severity', - 'service_last_state_change' - ), - 'order' => self::SORT_DESC + 'service_severity DESC', + 'service_last_state_change DESC', + 'service_display_name ASC', + 'host_display_name ASC' + ) ), - 'host_severity' => array( + 'service_display_name' => array( 'columns' => array( - 'host_severity', - 'host_last_state_change', + 'service_display_name', + 'host_display_name' ), 'order' => self::SORT_ASC ), + 'host_severity' => array( + 'columns' => array( + 'host_severity DESC', + 'host_last_state_change DESC', + 'host_display_name ASC', + 'service_display_name ASC' + ) + ), 'host_display_name' => array( 'columns' => array( 'host_display_name',