Merge branch 'bugfix/service-sort-by-display_name-8716'

fixes #8716
This commit is contained in:
Eric Lippmann 2015-03-13 17:16:05 +01:00
commit a932f9d7c9
4 changed files with 45 additions and 19 deletions

View File

@ -161,6 +161,26 @@ class SimpleQuery implements QueryInterface, Queryable
throw new IcingaException('This function does nothing and will be removed'); 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) * Sort result set by the given field (and direction)
* *
@ -177,13 +197,9 @@ class SimpleQuery implements QueryInterface, Queryable
public function order($field, $direction = null) public function order($field, $direction = null)
{ {
if ($direction === null) { if ($direction === null) {
$fieldAndDirection = explode(' ', $field, 2); list($field, $direction) = $this->splitOrder($field);
if (count($fieldAndDirection) === 1) { if ($direction === null) {
$direction = self::SORT_ASC; $direction = Sortable::SORT_ASC;
} else {
$field = $fieldAndDirection[0];
$direction = (strtoupper(trim($fieldAndDirection[1])) === 'DESC') ?
Sortable::SORT_DESC : Sortable::SORT_ASC;
} }
} else { } else {
switch (($direction = strtoupper($direction))) { switch (($direction = strtoupper($direction))) {

View File

@ -242,6 +242,7 @@ abstract class DataView implements Browsable, Countable, Filterable, Sortable
$order = (strtoupper($order) === static::SORT_ASC) ? 'ASC' : 'DESC'; $order = (strtoupper($order) === static::SORT_ASC) ? 'ASC' : 'DESC';
foreach ($sortColumns['columns'] as $column) { foreach ($sortColumns['columns'] as $column) {
list($column, $direction) = $this->query->splitOrder($column);
if (! $this->isValidFilterTarget($column)) { if (! $this->isValidFilterTarget($column)) {
throw new QueryException( throw new QueryException(
mt('monitoring', 'The sort column "%s" is not allowed in "%s".'), mt('monitoring', 'The sort column "%s" is not allowed in "%s".'),
@ -249,7 +250,7 @@ abstract class DataView implements Browsable, Countable, Filterable, Sortable
get_class($this) get_class($this)
); );
} }
$this->query->order($column, $order); $this->query->order($column, $direction !== null ? $direction : $order);
} }
$this->isSorted = true; $this->isSorted = true;
return $this; return $this;

View File

@ -92,10 +92,10 @@ class HostStatus extends DataView
return array( return array(
'host_severity' => array( 'host_severity' => array(
'columns' => array( 'columns' => array(
'host_severity', 'host_severity DESC',
'host_last_state_change', 'host_last_state_change DESC',
), 'host_display_name ASC'
'order' => self::SORT_DESC )
), ),
'host_display_name' => array( 'host_display_name' => array(
'order' => self::SORT_ASC 'order' => self::SORT_ASC

View File

@ -125,17 +125,26 @@ class ServiceStatus extends DataView
return array( return array(
'service_severity' => array( 'service_severity' => array(
'columns' => array( 'columns' => array(
'service_severity', 'service_severity DESC',
'service_last_state_change' 'service_last_state_change DESC',
'service_display_name ASC',
'host_display_name ASC'
)
),
'service_display_name' => array(
'columns' => array(
'service_display_name',
'host_display_name'
), ),
'order' => self::SORT_DESC 'order' => self::SORT_ASC
), ),
'host_severity' => array( 'host_severity' => array(
'columns' => array( 'columns' => array(
'host_severity', 'host_severity DESC',
'host_last_state_change', 'host_last_state_change DESC',
), 'host_display_name ASC',
'order' => self::SORT_ASC 'service_display_name ASC'
)
), ),
'host_display_name' => array( 'host_display_name' => array(
'columns' => array( 'columns' => array(