Add class DashboardContainer

refs #5600
This commit is contained in:
Johannes Meyer 2015-09-04 15:25:19 +02:00
parent 5c2619dcb5
commit 70a48643c1
2 changed files with 90 additions and 9 deletions

View File

@ -0,0 +1,54 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Application\Modules;
/**
* Container for module dashboards
*/
class DashboardContainer extends NavigationItemContainer
{
/**
* This dashboard's dashlets
*
* @var array
*/
protected $dashlets;
/**
* Set this dashboard's dashlets
*
* @param array $dashlets
*
* @return $this
*/
public function setDashlets(array $dashlets)
{
$this->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;
}
}

View File

@ -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];
}