From ecaa12b0f4d9808d5a0db8a2906ef45efdff9835 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 21 Aug 2013 00:21:36 +0200 Subject: [PATCH] Improved default sort bevahior --- .../library/Monitoring/View/AbstractView.php | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/View/AbstractView.php b/modules/monitoring/library/Monitoring/View/AbstractView.php index 9fb536df6..6cceaaf12 100644 --- a/modules/monitoring/library/Monitoring/View/AbstractView.php +++ b/modules/monitoring/library/Monitoring/View/AbstractView.php @@ -100,6 +100,12 @@ class AbstractView extends AbstractQuery return in_array($column, $this->availableColumns); } + // TODO: Not sure about this yet + public function getDefaultColumns() + { + return $this->availableColumns; + } + /** * Get a list of all available column names * @@ -139,7 +145,7 @@ class AbstractView extends AbstractQuery return $this->order( // TODO: Use first sortDefaults entry if available, fall back to // column if not - $request->getParam('sort', $this->availableColumns[0]), + $request->getParam('sort', $this->getDefaultSortColumn()), $request->getParam('dir') ); } @@ -209,6 +215,25 @@ class AbstractView extends AbstractQuery return new Filter($this->filters); } + public function hasSingleSortColumn() + { + return count($this->order_columns) === 1; + } + + public function getFirstSortColumn() + { + return $this->order_columns[0]; + } + + protected function getDefaultSortColumn() + { + if (empty($this->sortDefaults)) { + return $this->availableColumns[0]; + } else { + return array_shift(array_keys($this->sortDefaults)); + } + } + /** * Default sort direction for given column, ASCending if not defined *