From 1492218962ee85af4e921398bf5f205e1fb18989 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 18 Aug 2015 14:18:48 +0200 Subject: [PATCH] Fix SortBox not usable w/o SortRules The SortBox assumes the first avaiable sort column as default column if the given Sortable does not implement the SortRules interface. When changing the direction of the default sort column, the sort box did not pass the column to Sortable::sort(). Thus the Sortable did not know by which column to sort. Now the SortBox passes the sort column even if the direction of the default column is changed. refs #9333 --- library/Icinga/Web/Widget/SortBox.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/library/Icinga/Web/Widget/SortBox.php b/library/Icinga/Web/Widget/SortBox.php index c9d38f2b7..862dad22c 100644 --- a/library/Icinga/Web/Widget/SortBox.php +++ b/library/Icinga/Web/Widget/SortBox.php @@ -118,12 +118,12 @@ class SortBox extends AbstractWidget if ($request === null) { $request = Icinga::app()->getRequest(); } - - if (($sort = $request->getParam('sort'))) { - $this->query->order($sort, $request->getParam('dir')); - } elseif (($dir = $request->getParam('dir'))) { - $this->query->order(null, $dir); + if (null === $sort = $request->getParam('sort')) { + list($sort, $dir) = $this->getSortDefaults(); + } else { + list($_, $dir) = $this->getSortDefaults($sort); } + $this->query->order($sort, $request->getParam('dir', $dir)); } return $this; @@ -148,8 +148,10 @@ class SortBox extends AbstractWidget if ($column !== null && isset($sortRules[$column]['order'])) { $direction = strtoupper($sortRules[$column]['order']) === Sortable::SORT_DESC ? 'desc' : 'asc'; } + } elseif ($column === null) { + reset($this->sortFields); + $column = key($this->sortFields); } - return array($column, $direction); }