From 215d9df111800acc1fcdaad1669fcf1cbc6a2330 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 4 Mar 2014 11:18:28 +0000 Subject: [PATCH] Add Dashboard::getActivePane() and complain when asking for invalid one --- library/Icinga/Web/Widget/Dashboard.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/library/Icinga/Web/Widget/Dashboard.php b/library/Icinga/Web/Widget/Dashboard.php index 8016c8882..086bb69c3 100644 --- a/library/Icinga/Web/Widget/Dashboard.php +++ b/library/Icinga/Web/Widget/Dashboard.php @@ -33,6 +33,7 @@ use Icinga\Application\Icinga; use Icinga\Application\Config as IcingaConfig; use Icinga\Logger\Logger; use Icinga\Exception\ConfigurationError; +use Icinga\Exception\ProgrammingError; use Icinga\Web\Widget\AbstractWidget; use Icinga\Web\Widget\Dashboard\Pane; use Icinga\Web\Widget\Dashboard\Component as DashboardComponent; @@ -279,16 +280,19 @@ class Dashboard extends AbstractWidget } /** - * Return the pane with the provided name or null if it doesn't exit + * Return the pane with the provided name * * @param string $name The name of the pane to return * - * @return null|Pane The pane or null if no pane with the given name exists + * @return Pane The pane or null if no pane with the given name exists + * @throws ProgrammingError */ public function getPane($name) { - if (!isset($this->panes[$name])) { - return null; + if (! array_key_exists($name, $this->panes)) { + throw new ProgrammingError( + sprintf('Trying to retrieve invalid dashboard pane "%s"', $name) + ); } return $this->panes[$name]; } @@ -317,6 +321,14 @@ class Dashboard extends AbstractWidget return $active; } + public function getActivePane() + { + if ($active = $this->getTabs()->getActiveName()) { + return $this->getPane($active); + } + return $this->determineActivePane(); + } + /** * Determine the active pane either by the selected tab or the current request *