From 70a48643c188ae565573b221994421e7a6370d39 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 4 Sep 2015 15:25:19 +0200 Subject: [PATCH] Add class DashboardContainer refs #5600 --- .../Modules/DashboardContainer.php | 54 +++++++++++++++++++ library/Icinga/Application/Modules/Module.php | 45 ++++++++++++---- 2 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 library/Icinga/Application/Modules/DashboardContainer.php diff --git a/library/Icinga/Application/Modules/DashboardContainer.php b/library/Icinga/Application/Modules/DashboardContainer.php new file mode 100644 index 000000000..dac3b3ba5 --- /dev/null +++ b/library/Icinga/Application/Modules/DashboardContainer.php @@ -0,0 +1,54 @@ +dashlets = $dashlets; + return $this; + } + + /** + * Return this dashboard's dashlets + * + * @return array + */ + public function getDashlets() + { + return $this->dashlets ?: array(); + } + + /** + * Add a new dashlet + * + * @param string $name + * @param string $url + * + * @return $this + */ + public function add($name, $url) + { + $this->dashlets[$name] = $url; + return $this; + } +} diff --git a/library/Icinga/Application/Modules/Module.php b/library/Icinga/Application/Modules/Module.php index ef5d90a4f..fc3c1fcc0 100644 --- a/library/Icinga/Application/Modules/Module.php +++ b/library/Icinga/Application/Modules/Module.php @@ -11,6 +11,7 @@ use Icinga\Application\ApplicationBootstrap; use Icinga\Application\Config; use Icinga\Application\Icinga; use Icinga\Application\Logger; +use Icinga\Application\Modules\DashboardContainer; use Icinga\Application\Modules\MenuItemContainer; use Icinga\Exception\IcingaException; use Icinga\Exception\ProgrammingError; @@ -21,7 +22,6 @@ use Icinga\Web\Controller\Dispatcher; use Icinga\Web\Hook; use Icinga\Web\Navigation\Navigation; use Icinga\Web\Widget; -use Icinga\Web\Widget\Dashboard\Pane; /** * Module handling @@ -277,26 +277,53 @@ class Module } /** - * Get all pane items + * Return this module's dashboard * - * @return array + * @return Navigation */ - public function getPaneItems() + public function getDashboard() { $this->launchConfigScript(); - return $this->paneItems; + return $this->createDashboard($this->paneItems); } /** - * Add a pane to dashboard + * Create and return a new navigation for the given dashboard panes * - * @param string $name + * @param DashboardContainer[] $panes * - * @return Pane + * @return Navigation + */ + public function createDashboard(array $panes) + { + $navigation = new Navigation(); + foreach ($panes as $pane) { + /** @var DashboardContainer $pane */ + foreach ($pane->getDashlets() as $dashletName => $dashletUrl) { + $navigation->addItem( + $dashletName, + array( + 'type' => 'dashlet', + 'dashboard' => $pane->getName(), + 'url' => $dashletUrl + ) + ); + } + } + + return $navigation; + } + + /** + * Add or get a dashboard pane + * + * @param string $name + * + * @return DashboardContainer */ protected function dashboard($name) { - $this->paneItems[$name] = new Pane($name); + $this->paneItems[$name] = new DashboardContainer($name); return $this->paneItems[$name]; }