mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 07:14:35 +02:00
parent
5c2619dcb5
commit
70a48643c1
54
library/Icinga/Application/Modules/DashboardContainer.php
Normal file
54
library/Icinga/Application/Modules/DashboardContainer.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ use Icinga\Application\ApplicationBootstrap;
|
|||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Application\Logger;
|
use Icinga\Application\Logger;
|
||||||
|
use Icinga\Application\Modules\DashboardContainer;
|
||||||
use Icinga\Application\Modules\MenuItemContainer;
|
use Icinga\Application\Modules\MenuItemContainer;
|
||||||
use Icinga\Exception\IcingaException;
|
use Icinga\Exception\IcingaException;
|
||||||
use Icinga\Exception\ProgrammingError;
|
use Icinga\Exception\ProgrammingError;
|
||||||
@ -21,7 +22,6 @@ use Icinga\Web\Controller\Dispatcher;
|
|||||||
use Icinga\Web\Hook;
|
use Icinga\Web\Hook;
|
||||||
use Icinga\Web\Navigation\Navigation;
|
use Icinga\Web\Navigation\Navigation;
|
||||||
use Icinga\Web\Widget;
|
use Icinga\Web\Widget;
|
||||||
use Icinga\Web\Widget\Dashboard\Pane;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module handling
|
* 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();
|
$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)
|
protected function dashboard($name)
|
||||||
{
|
{
|
||||||
$this->paneItems[$name] = new Pane($name);
|
$this->paneItems[$name] = new DashboardContainer($name);
|
||||||
return $this->paneItems[$name];
|
return $this->paneItems[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user