Add Dashboard::getActivePane() and complain when asking for invalid one
This commit is contained in:
parent
6d3db4732a
commit
215d9df111
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue