mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-24 06:14:25 +02:00
parent
2471314616
commit
e600dc8adb
@ -5,7 +5,7 @@
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Forms\ConfirmRemovalForm;
|
||||
use Icinga\Forms\Dashboard\ComponentForm;
|
||||
use Icinga\Forms\Dashboard\DashletForm;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Notification;
|
||||
use Icinga\Web\Controller\ActionController;
|
||||
@ -15,7 +15,7 @@ use Icinga\Web\Widget\Dashboard;
|
||||
use Icinga\Web\Widget\Tabextension\DashboardSettings;
|
||||
|
||||
/**
|
||||
* Handle creation, removal and displaying of dashboards, panes and components
|
||||
* Handle creation, removal and displaying of dashboards, panes and dashlets
|
||||
*
|
||||
* @see Icinga\Web\Widget\Dashboard for more information about dashboards
|
||||
*/
|
||||
@ -33,9 +33,9 @@ class DashboardController extends ActionController
|
||||
$this->dashboard->load();
|
||||
}
|
||||
|
||||
public function newComponentAction()
|
||||
public function newDashletAction()
|
||||
{
|
||||
$form = new ComponentForm();
|
||||
$form = new DashletForm();
|
||||
$this->createTabs();
|
||||
$dashboard = $this->dashboard;
|
||||
$form->setDashboard($dashboard);
|
||||
@ -53,9 +53,9 @@ class DashboardController extends ActionController
|
||||
$pane->setUserWidget();
|
||||
$dashboard->addPane($pane);
|
||||
}
|
||||
$component = new Dashboard\Component($form->getValue('component'), $form->getValue('url'), $pane);
|
||||
$component->setUserWidget();
|
||||
$pane->addComponent($component);
|
||||
$dashlet = new Dashboard\Dashlet($form->getValue('dashlet'), $form->getValue('url'), $pane);
|
||||
$dashlet->setUserWidget();
|
||||
$pane->addDashlet($dashlet);
|
||||
try {
|
||||
$dashboard->write();
|
||||
} catch (\Zend_Config_Exception $e) {
|
||||
@ -64,7 +64,7 @@ class DashboardController extends ActionController
|
||||
$action->render('error');
|
||||
return false;
|
||||
}
|
||||
Notification::success(t('Component created'));
|
||||
Notification::success(t('Dashlet created'));
|
||||
return true;
|
||||
});
|
||||
$form->setRedirectUrl('dashboard');
|
||||
@ -72,11 +72,11 @@ class DashboardController extends ActionController
|
||||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
public function updateComponentAction()
|
||||
public function updateDashletAction()
|
||||
{
|
||||
$this->createTabs();
|
||||
$dashboard = $this->dashboard;
|
||||
$form = new ComponentForm();
|
||||
$form = new DashletForm();
|
||||
$form->setDashboard($dashboard);
|
||||
$form->setSubmitLabel(t('Update Dashlet'));
|
||||
if (! $this->_request->getParam('pane')) {
|
||||
@ -85,9 +85,9 @@ class DashboardController extends ActionController
|
||||
400
|
||||
);
|
||||
}
|
||||
if (! $this->_request->getParam('component')) {
|
||||
if (! $this->_request->getParam('dashlet')) {
|
||||
throw new Zend_Controller_Action_Exception(
|
||||
'Missing parameter "component"',
|
||||
'Missing parameter "dashlet"',
|
||||
400
|
||||
);
|
||||
}
|
||||
@ -101,21 +101,21 @@ class DashboardController extends ActionController
|
||||
$dashboard->addPane($pane);
|
||||
}
|
||||
try {
|
||||
$component = $pane->getComponent($form->getValue('component'));
|
||||
$component->setUrl($form->getValue('url'));
|
||||
$dashlet = $pane->getDashlet($form->getValue('dashlet'));
|
||||
$dashlet->setUrl($form->getValue('url'));
|
||||
} catch (ProgrammingError $e) {
|
||||
$component = new Dashboard\Component($form->getValue('component'), $form->getValue('url'), $pane);
|
||||
$pane->addComponent($component);
|
||||
$dashlet = new Dashboard\Dashlet($form->getValue('dashlet'), $form->getValue('url'), $pane);
|
||||
$pane->addDashlet($dashlet);
|
||||
}
|
||||
$component->setUserWidget();
|
||||
// Rename component
|
||||
if ($form->getValue('org_component') && $form->getValue('org_component') !== $component->getTitle()) {
|
||||
$pane->removeComponent($form->getValue('org_component'));
|
||||
$dashlet->setUserWidget();
|
||||
// Rename dashlet
|
||||
if ($form->getValue('org_dashlet') && $form->getValue('org_dashlet') !== $dashlet->getTitle()) {
|
||||
$pane->removeDashlet($form->getValue('org_dashlet'));
|
||||
}
|
||||
// Move
|
||||
if ($form->getValue('org_pane') && $form->getValue('org_pane') !== $pane->getTitle()) {
|
||||
$oldPane = $dashboard->getPane($form->getValue('org_pane'));
|
||||
$oldPane->removeComponent($component->getTitle());
|
||||
$oldPane->removeDashlet($dashlet->getTitle());
|
||||
}
|
||||
try {
|
||||
$dashboard->write();
|
||||
@ -131,13 +131,13 @@ class DashboardController extends ActionController
|
||||
$form->setRedirectUrl('dashboard/settings');
|
||||
$form->handleRequest();
|
||||
$pane = $dashboard->getPane($this->getParam('pane'));
|
||||
$component = $pane->getComponent($this->getParam('component'));
|
||||
$form->load($component);
|
||||
$dashlet = $pane->getDashlet($this->getParam('dashlet'));
|
||||
$form->load($dashlet);
|
||||
|
||||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
public function removeComponentAction()
|
||||
public function removeDashletAction()
|
||||
{
|
||||
$form = new ConfirmRemovalForm();
|
||||
$this->createTabs();
|
||||
@ -148,19 +148,19 @@ class DashboardController extends ActionController
|
||||
400
|
||||
);
|
||||
}
|
||||
if (! $this->_request->getParam('component')) {
|
||||
if (! $this->_request->getParam('dashlet')) {
|
||||
throw new Zend_Controller_Action_Exception(
|
||||
'Missing parameter "component"',
|
||||
'Missing parameter "dashlet"',
|
||||
400
|
||||
);
|
||||
}
|
||||
$pane = $this->_request->getParam('pane');
|
||||
$component = $this->_request->getParam('component');
|
||||
$dashlet = $this->_request->getParam('dashlet');
|
||||
$action = $this;
|
||||
$form->setOnSuccess(function (Form $form) use ($dashboard, $component, $pane, $action) {
|
||||
$form->setOnSuccess(function (Form $form) use ($dashboard, $dashlet, $pane, $action) {
|
||||
try {
|
||||
$pane = $dashboard->getPane($pane);
|
||||
$pane->removeComponent($component);
|
||||
$pane->removeDashlet($dashlet);
|
||||
$dashboard->write();
|
||||
Notification::success(t('Dashlet has been removed from') . ' ' . $pane->getTitle());
|
||||
return true;
|
||||
@ -178,7 +178,7 @@ class DashboardController extends ActionController
|
||||
$form->setRedirectUrl('dashboard/settings');
|
||||
$form->handleRequest();
|
||||
$this->view->pane = $pane;
|
||||
$this->view->component = $component;
|
||||
$this->view->dashlet = $dashlet;
|
||||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ class DashboardController extends ActionController
|
||||
} else {
|
||||
$this->view->title = $this->dashboard->getActivePane()->getTitle() . ' :: Dashboard';
|
||||
if ($this->hasParam('remove')) {
|
||||
$this->dashboard->getActivePane()->removeComponent($this->getParam('remove'));
|
||||
$this->dashboard->getActivePane()->removeDashlet($this->getParam('remove'));
|
||||
$this->dashboard->write();
|
||||
$this->redirectNow(URL::fromRequest()->remove('remove'));
|
||||
}
|
||||
@ -248,7 +248,7 @@ class DashboardController extends ActionController
|
||||
'Add',
|
||||
array(
|
||||
'title' => '+',
|
||||
'url' => Url::fromPath('dashboard/new-component')
|
||||
'url' => Url::fromPath('dashboard/new-dashlet')
|
||||
)
|
||||
);
|
||||
$this->view->dashboard = $this->dashboard;
|
||||
|
@ -7,12 +7,12 @@ namespace Icinga\Forms\Dashboard;
|
||||
use Icinga\Web\Widget\Dashboard;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Request;
|
||||
use Icinga\Web\Widget\Dashboard\Component;
|
||||
use Icinga\Web\Widget\Dashboard\Dashlet;
|
||||
|
||||
/**
|
||||
* Form to add an url a dashboard pane
|
||||
*/
|
||||
class ComponentForm extends Form
|
||||
class DashletForm extends Form
|
||||
{
|
||||
/**
|
||||
* @var Dashboard
|
||||
@ -54,7 +54,7 @@ class ComponentForm extends Form
|
||||
|
||||
$this->addElement(
|
||||
'hidden',
|
||||
'org_component',
|
||||
'org_dashlet',
|
||||
array(
|
||||
'required' => false
|
||||
)
|
||||
@ -72,7 +72,7 @@ class ComponentForm extends Form
|
||||
);
|
||||
$this->addElement(
|
||||
'text',
|
||||
'component',
|
||||
'dashlet',
|
||||
array(
|
||||
'required' => true,
|
||||
'label' => t('Dashlet Title'),
|
||||
@ -142,16 +142,16 @@ class ComponentForm extends Form
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Component $component
|
||||
* @param Dashlet $dashlet
|
||||
*/
|
||||
public function load(Component $component)
|
||||
public function load(Dashlet $dashlet)
|
||||
{
|
||||
$this->populate(array(
|
||||
'pane' => $component->getPane()->getName(),
|
||||
'org_pane' => $component->getPane()->getName(),
|
||||
'component' => $component->getTitle(),
|
||||
'org_component' => $component->getTitle(),
|
||||
'url' => $component->getUrl()
|
||||
'pane' => $dashlet->getPane()->getName(),
|
||||
'org_pane' => $dashlet->getPane()->getName(),
|
||||
'dashlet' => $dashlet->getTitle(),
|
||||
'org_dashlet' => $dashlet->getTitle(),
|
||||
'url' => $dashlet->getUrl()
|
||||
));
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ if (! $this->auth()->isAuthenticated()) {
|
||||
id="menu" data-last-update="<?= (time() - 14) ?>000" data-base-target="_main" class="container" data-icinga-url="<?=$this->href('layout/menu');?>"
|
||||
data-icinga-refresh="15"
|
||||
>
|
||||
<? if (SearchDashboard::search('dummy')->getPane('search')->hasComponents()): ?>
|
||||
<? if (SearchDashboard::search('dummy')->getPane('search')->hasDashlets()): ?>
|
||||
<form action="<?= $this->href('search') ?>" method="get" role="search">
|
||||
<input type="text" name="q" class="search autofocus" placeholder="<?= $this->translate('Search...') ?>"
|
||||
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
<p>
|
||||
<?= $this->translate('Please confirm the removal'); ?>:
|
||||
<?= $this->pane; ?>/<?= $this->component; ?>
|
||||
<?= $this->pane; ?>/<?= $this->dashlet; ?>
|
||||
</p>
|
||||
|
||||
<?= $this->form; ?>
|
@ -29,27 +29,27 @@
|
||||
</a>
|
||||
</th>
|
||||
</tr>
|
||||
<?php $components = $pane->getComponents(); ?>
|
||||
<?php if(empty($components)): ?>
|
||||
<?php $dashlets = $pane->getDashlets(); ?>
|
||||
<?php if(empty($dashlets)): ?>
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<?= $this->translate('No dashlets added to dashboard') ?>.
|
||||
</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($components as $component): ?>
|
||||
<?php if ($component->getDisabled() === true) continue; ?>
|
||||
<?php foreach ($dashlets as $dashlet): ?>
|
||||
<?php if ($dashlet->getDisabled() === true) continue; ?>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="<?= $this->href('dashboard/update-component', array('pane' => $pane->getName(), 'component' => $component->getTitle())); ?>">
|
||||
<?= $component->getTitle(); ?>
|
||||
<a href="<?= $this->href('dashboard/update-dashlet', array('pane' => $pane->getName(), 'dashlet' => $dashlet->getTitle())); ?>">
|
||||
<?= $dashlet->getTitle(); ?>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<?= $this->href($component->getUrl()); ?>"><?= $component->getUrl(); ?></a>
|
||||
<a href="<?= $this->href($dashlet->getUrl()); ?>"><?= $dashlet->getUrl(); ?></a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<?= $this->href('dashboard/remove-component', array('pane' => $pane->getName(), 'component' => $component->getTitle())); ?>">
|
||||
<a href="<?= $this->href('dashboard/remove-dashlet', array('pane' => $pane->getName(), 'dashlet' => $dashlet->getTitle())); ?>">
|
||||
<?= $this->icon('cancel'); ?>
|
||||
</a>
|
||||
</td>
|
||||
|
@ -2,7 +2,7 @@
|
||||
use Icinga\Web\Widget\SearchDashboard;
|
||||
?>
|
||||
|
||||
<? if (SearchDashboard::search('dummy')->getPane('search')->hasComponents()): ?>
|
||||
<? if (SearchDashboard::search('dummy')->getPane('search')->hasDashlets()): ?>
|
||||
<form action="<?= $this->href('search') ?>" method="get" role="search">
|
||||
<input
|
||||
type="text" name="q" class="search autofocus" placeholder="<?= $this->translate('Search...') ?>"
|
||||
|
@ -14,15 +14,15 @@ use Icinga\Exception\SystemPermissionException;
|
||||
use Icinga\File\Ini\IniWriter;
|
||||
use Icinga\User;
|
||||
use Icinga\Web\Widget\Dashboard\Pane;
|
||||
use Icinga\Web\Widget\Dashboard\Component as DashboardComponent;
|
||||
use Icinga\Web\Widget\Dashboard\Dashlet as DashboardDashlet;
|
||||
use Icinga\Web\Url;
|
||||
|
||||
/**
|
||||
* Dashboards display multiple views on a single page
|
||||
*
|
||||
* The terminology is as follows:
|
||||
* - Component: A single view showing a specific url
|
||||
* - Pane: Aggregates one or more components on one page, displays it's title as a tab
|
||||
* - Dashlet: A single view showing a specific url
|
||||
* - Pane: Aggregates one or more dashlets on one page, displays it's title as a tab
|
||||
* - Dashboard: Shows all panes
|
||||
*
|
||||
*/
|
||||
@ -98,9 +98,9 @@ class Dashboard extends AbstractWidget
|
||||
if ($pane->isUserWidget() === true) {
|
||||
$output[$pane->getName()] = $pane->toArray();
|
||||
}
|
||||
foreach ($pane->getComponents() as $component) {
|
||||
if ($component->isUserWidget() === true) {
|
||||
$output[$pane->getName() . '.' . $component->getTitle()] = $component->toArray();
|
||||
foreach ($pane->getDashlets() as $dashlet) {
|
||||
if ($dashlet->isUserWidget() === true) {
|
||||
$output[$pane->getName() . '.' . $dashlet->getTitle()] = $dashlet->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -132,7 +132,7 @@ class Dashboard extends AbstractWidget
|
||||
return false;
|
||||
}
|
||||
$panes = array();
|
||||
$components = array();
|
||||
$dashlets = array();
|
||||
foreach ($config as $key => $part) {
|
||||
if (strpos($key, '.') === false) {
|
||||
if ($this->hasPane($part->title)) {
|
||||
@ -147,34 +147,34 @@ class Dashboard extends AbstractWidget
|
||||
}
|
||||
|
||||
} else {
|
||||
list($paneName, $componentName) = explode('.', $key, 2);
|
||||
list($paneName, $dashletName) = explode('.', $key, 2);
|
||||
$part->pane = $paneName;
|
||||
$part->component = $componentName;
|
||||
$components[] = $part;
|
||||
$part->dashlet = $dashletName;
|
||||
$dashlets[] = $part;
|
||||
}
|
||||
}
|
||||
foreach ($components as $componentData) {
|
||||
foreach ($dashlets as $dashletData) {
|
||||
$pane = null;
|
||||
|
||||
if (array_key_exists($componentData->pane, $panes) === true) {
|
||||
$pane = $panes[$componentData->pane];
|
||||
} elseif (array_key_exists($componentData->pane, $this->panes) === true) {
|
||||
$pane = $this->panes[$componentData->pane];
|
||||
if (array_key_exists($dashletData->pane, $panes) === true) {
|
||||
$pane = $panes[$dashletData->pane];
|
||||
} elseif (array_key_exists($dashletData->pane, $this->panes) === true) {
|
||||
$pane = $this->panes[$dashletData->pane];
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
$component = new DashboardComponent(
|
||||
$componentData->title,
|
||||
$componentData->url,
|
||||
$dashlet = new DashboardDashlet(
|
||||
$dashletData->title,
|
||||
$dashletData->url,
|
||||
$pane
|
||||
);
|
||||
|
||||
if ((bool) $componentData->get('disabled', false) === true) {
|
||||
$component->setDisabled(true);
|
||||
if ((bool) $dashletData->get('disabled', false) === true) {
|
||||
$dashlet->setDisabled(true);
|
||||
}
|
||||
|
||||
$component->setUserWidget();
|
||||
$pane->addComponent($component);
|
||||
$dashlet->setUserWidget();
|
||||
$pane->addDashlet($dashlet);
|
||||
}
|
||||
|
||||
$this->mergePanes($panes);
|
||||
@ -202,7 +202,7 @@ class Dashboard extends AbstractWidget
|
||||
if ($this->hasPane($pane->getTitle()) === true) {
|
||||
/** @var $current Pane */
|
||||
$current = $this->panes[$pane->getName()];
|
||||
$current->addComponents($pane->getComponents());
|
||||
$current->addDashlets($pane->getDashlets());
|
||||
} else {
|
||||
$this->panes[$pane->getName()] = $pane;
|
||||
}
|
||||
|
@ -12,28 +12,28 @@ use Icinga\Data\ConfigObject;
|
||||
use Icinga\Exception\IcingaException;
|
||||
|
||||
/**
|
||||
* A dashboard pane component
|
||||
* A dashboard pane dashlet
|
||||
*
|
||||
* This is the element displaying a specific view in icinga2web
|
||||
*
|
||||
*/
|
||||
class Component extends UserWidget
|
||||
class Dashlet extends UserWidget
|
||||
{
|
||||
/**
|
||||
* The url of this Component
|
||||
* The url of this Dashlet
|
||||
*
|
||||
* @var \Icinga\Web\Url
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* The title being displayed on top of the component
|
||||
* The title being displayed on top of the dashlet
|
||||
* @var
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* The pane containing this component, needed for the 'remove button'
|
||||
* The pane containing this dashlet, needed for the 'remove button'
|
||||
* @var Pane
|
||||
*/
|
||||
private $pane;
|
||||
@ -61,11 +61,11 @@ class Component extends UserWidget
|
||||
EOD;
|
||||
|
||||
/**
|
||||
* Create a new component displaying the given url in the provided pane
|
||||
* Create a new dashlet displaying the given url in the provided pane
|
||||
*
|
||||
* @param string $title The title to use for this component
|
||||
* @param Url|string $url The url this component uses for displaying information
|
||||
* @param Pane $pane The pane this Component will be added to
|
||||
* @param string $title The title to use for this dashlet
|
||||
* @param Url|string $url The url this dashlet uses for displaying information
|
||||
* @param Pane $pane The pane this Dashlet will be added to
|
||||
*/
|
||||
public function __construct($title, $url, Pane $pane)
|
||||
{
|
||||
@ -77,14 +77,14 @@ EOD;
|
||||
$this->url = Url::fromPath($url);
|
||||
} else {
|
||||
throw new IcingaException(
|
||||
'Cannot create dashboard component "%s" without valid URL',
|
||||
'Cannot create dashboard dashlet "%s" without valid URL',
|
||||
$title
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the components title
|
||||
* Retrieve the dashlets title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@ -102,7 +102,7 @@ EOD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the components url
|
||||
* Retrieve the dashlets url
|
||||
*
|
||||
* @return Url
|
||||
*/
|
||||
@ -112,7 +112,7 @@ EOD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the components URL
|
||||
* Set the dashlets URL
|
||||
*
|
||||
* @param string|Url $url The url to use, either as an Url object or as a path
|
||||
*
|
||||
@ -149,7 +149,7 @@ EOD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this component's structure as array
|
||||
* Return this dashlet's structure as array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@ -208,8 +208,8 @@ EOD;
|
||||
{
|
||||
return sprintf(
|
||||
'<a data-base-target="main" href="%s">%s</a>',
|
||||
Url::fromPath('dashboard/remove-component', array(
|
||||
'component' => $this->getTitle(),
|
||||
Url::fromPath('dashboard/remove-dashlet', array(
|
||||
'dashlet' => $this->getTitle(),
|
||||
'pane' => $this->pane->getTitle()
|
||||
)),
|
||||
t('Remove')
|
||||
@ -217,13 +217,13 @@ EOD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a @see Component instance from the given Zend config, using the provided title
|
||||
* Create a @see Dashlet instance from the given Zend config, using the provided title
|
||||
*
|
||||
* @param $title The title for this component
|
||||
* @param $title The title for this dashlet
|
||||
* @param ConfigObject $config The configuration defining url, parameters, height, width, etc.
|
||||
* @param Pane $pane The pane this component belongs to
|
||||
* @param Pane $pane The pane this dashlet belongs to
|
||||
*
|
||||
* @return Component A newly created Component for use in the Dashboard
|
||||
* @return Dashlet A newly created Dashlet for use in the Dashboard
|
||||
*/
|
||||
public static function fromIni($title, ConfigObject $config, Pane $pane)
|
||||
{
|
||||
@ -233,14 +233,14 @@ EOD;
|
||||
$parameters = $config->toArray();
|
||||
unset($parameters['url']); // otherwise there's an url = parameter in the Url
|
||||
|
||||
$cmp = new Component($title, Url::fromPath($url, $parameters), $pane);
|
||||
$cmp = new Dashlet($title, Url::fromPath($url, $parameters), $pane);
|
||||
return $cmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Icinga\Web\Widget\Dashboard\Pane $pane
|
||||
*/
|
||||
public function setPane(Panel $pane)
|
||||
public function setPane(Pane $pane)
|
||||
{
|
||||
$this->pane = $pane;
|
||||
}
|
@ -10,7 +10,7 @@ use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
||||
/**
|
||||
* A pane, displaying different Dashboard components
|
||||
* A pane, displaying different Dashboard dashlets
|
||||
*/
|
||||
class Pane extends UserWidget
|
||||
{
|
||||
@ -30,11 +30,11 @@ class Pane extends UserWidget
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* An array of @see Components that are displayed in this pane
|
||||
* An array of @see Dashlets that are displayed in this pane
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $components = array();
|
||||
private $dashlets = array();
|
||||
|
||||
/**
|
||||
* Disabled flag of a pane
|
||||
@ -88,94 +88,94 @@ class Pane extends UserWidget
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if a component with the given title exists in this pane
|
||||
* Return true if a dashlet with the given title exists in this pane
|
||||
*
|
||||
* @param string $title The title of the component to check for existence
|
||||
* @param string $title The title of the dashlet to check for existence
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasComponent($title)
|
||||
public function hasDashlet($title)
|
||||
{
|
||||
return array_key_exists($title, $this->components);
|
||||
return array_key_exists($title, $this->dashlets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current pane has any components
|
||||
* Checks if the current pane has any dashlets
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasComponents()
|
||||
public function hasDashlets()
|
||||
{
|
||||
return ! empty($this->components);
|
||||
return ! empty($this->dashlets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a component with the given name if existing
|
||||
* Return a dashlet with the given name if existing
|
||||
*
|
||||
* @param string $title The title of the component to return
|
||||
* @param string $title The title of the dashlet to return
|
||||
*
|
||||
* @return Component The component with the given title
|
||||
* @throws ProgrammingError If the component doesn't exist
|
||||
* @return Dashlet The dashlet with the given title
|
||||
* @throws ProgrammingError If the dashlet doesn't exist
|
||||
*/
|
||||
public function getComponent($title)
|
||||
public function getDashlet($title)
|
||||
{
|
||||
if ($this->hasComponent($title)) {
|
||||
return $this->components[$title];
|
||||
if ($this->hasDashlet($title)) {
|
||||
return $this->dashlets[$title];
|
||||
}
|
||||
throw new ProgrammingError(
|
||||
'Trying to access invalid component: %s',
|
||||
'Trying to access invalid dashlet: %s',
|
||||
$title
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the component with the given title if it exists in this pane
|
||||
* Removes the dashlet with the given title if it exists in this pane
|
||||
*
|
||||
* @param string $title The pane
|
||||
* @return Pane $this
|
||||
*/
|
||||
public function removeComponent($title)
|
||||
public function removeDashlet($title)
|
||||
{
|
||||
if ($this->hasComponent($title)) {
|
||||
$component = $this->getComponent($title);
|
||||
if ($component->isUserWidget() === true) {
|
||||
unset($this->components[$title]);
|
||||
if ($this->hasDashlet($title)) {
|
||||
$dashlet = $this->getDashlet($title);
|
||||
if ($dashlet->isUserWidget() === true) {
|
||||
unset($this->dashlets[$title]);
|
||||
} else {
|
||||
$component->setDisabled(true);
|
||||
$component->setUserWidget();
|
||||
$dashlet->setDisabled(true);
|
||||
$dashlet->setUserWidget();
|
||||
}
|
||||
} else {
|
||||
throw new ProgrammingError('Component does not exist: ' . $title);
|
||||
throw new ProgrammingError('Dashlet does not exist: ' . $title);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all or a given list of components from this pane
|
||||
* Removes all or a given list of dashlets from this pane
|
||||
*
|
||||
* @param array $components Optional list of component titles
|
||||
* @param array $dashlets Optional list of dashlet titles
|
||||
* @return Pane $this
|
||||
*/
|
||||
public function removeComponents(array $components = null)
|
||||
public function removeDashlets(array $dashlets = null)
|
||||
{
|
||||
if ($components === null) {
|
||||
$this->components = array();
|
||||
if ($dashlets === null) {
|
||||
$this->dashlets = array();
|
||||
} else {
|
||||
foreach ($components as $component) {
|
||||
$this->removeComponent($component);
|
||||
foreach ($dashlets as $dashlet) {
|
||||
$this->removeDashlet($dashlet);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all components added at this pane
|
||||
* Return all dashlets added at this pane
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getComponents()
|
||||
public function getDashlets()
|
||||
{
|
||||
return $this->components;
|
||||
return $this->dashlets;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,56 +183,56 @@ class Pane extends UserWidget
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
$components = array_filter(
|
||||
$this->components,
|
||||
$dashlets = array_filter(
|
||||
$this->dashlets,
|
||||
function ($e) {
|
||||
return ! $e->getDisabled();
|
||||
}
|
||||
);
|
||||
return implode("\n", $components) . "\n";
|
||||
return implode("\n", $dashlets) . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a component to this pane, optionally creating it if $component is a string
|
||||
* Add a dashlet to this pane, optionally creating it if $dashlet is a string
|
||||
*
|
||||
* @param string|Component $component The component object or title
|
||||
* (if a new component will be created)
|
||||
* @param string|null $url An Url to be used when component is a string
|
||||
* @param string|Dashlet $dashlet The dashlet object or title
|
||||
* (if a new dashlet will be created)
|
||||
* @param string|null $url An Url to be used when dashlet is a string
|
||||
*
|
||||
* @return self
|
||||
* @throws \Icinga\Exception\ConfigurationError
|
||||
*/
|
||||
public function addComponent($component, $url = null)
|
||||
public function addDashlet($dashlet, $url = null)
|
||||
{
|
||||
if ($component instanceof Component) {
|
||||
$this->components[$component->getTitle()] = $component;
|
||||
} elseif (is_string($component) && $url !== null) {
|
||||
$this->components[$component] = new Component($component, $url, $this);
|
||||
if ($dashlet instanceof Dashlet) {
|
||||
$this->dashlets[$dashlet->getTitle()] = $dashlet;
|
||||
} elseif (is_string($dashlet) && $url !== null) {
|
||||
$this->dashlets[$dashlet] = new Dashlet($dashlet, $url, $this);
|
||||
} else {
|
||||
throw new ConfigurationError('Invalid component added: %s', $component);
|
||||
throw new ConfigurationError('Invalid dashlet added: %s', $dashlet);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new components to existing components
|
||||
* Add new dashlets to existing dashlets
|
||||
*
|
||||
* @param array $components
|
||||
* @param array $dashlets
|
||||
* @return $this
|
||||
*/
|
||||
public function addComponents(array $components)
|
||||
public function addDashlets(array $dashlets)
|
||||
{
|
||||
/* @var $component Component */
|
||||
foreach ($components as $component) {
|
||||
if (array_key_exists($component->getTitle(), $this->components)) {
|
||||
if (preg_match('/_(\d+)$/', $component->getTitle(), $m)) {
|
||||
$name = preg_replace('/_\d+$/', $m[1]++, $component->getTitle());
|
||||
/* @var $dashlet Dashlet */
|
||||
foreach ($dashlets as $dashlet) {
|
||||
if (array_key_exists($dashlet->getTitle(), $this->dashlets)) {
|
||||
if (preg_match('/_(\d+)$/', $dashlet->getTitle(), $m)) {
|
||||
$name = preg_replace('/_\d+$/', $m[1]++, $dashlet->getTitle());
|
||||
} else {
|
||||
$name = $component->getTitle() . '_2';
|
||||
$name = $dashlet->getTitle() . '_2';
|
||||
}
|
||||
$this->components[$name] = $component;
|
||||
$this->dashlets[$name] = $dashlet;
|
||||
} else {
|
||||
$this->components[$component->getTitle()] = $component;
|
||||
$this->dashlets[$dashlet->getTitle()] = $dashlet;
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,19 +240,19 @@ class Pane extends UserWidget
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a component to the current pane
|
||||
* Add a dashlet to the current pane
|
||||
*
|
||||
* @param $title
|
||||
* @param $url
|
||||
* @return Component
|
||||
* @return Dashlet
|
||||
*
|
||||
* @see addComponent()
|
||||
* @see addDashlet()
|
||||
*/
|
||||
public function add($title, $url = null)
|
||||
{
|
||||
$this->addComponent($title, $url);
|
||||
$this->addDashlet($title, $url);
|
||||
|
||||
return $this->components[$title];
|
||||
return $this->dashlets[$title];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,7 +48,7 @@ class SearchDashboard extends Dashboard
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
if (! $this->getPane(self::SEARCH_PANE)->hasComponents()) {
|
||||
if (! $this->getPane(self::SEARCH_PANE)->hasDashlets()) {
|
||||
throw new ActionError('Site not found', 404);
|
||||
}
|
||||
return parent::render();
|
||||
@ -70,8 +70,8 @@ class SearchDashboard extends Dashboard
|
||||
$this->addSearchDashletsFromModule($searchString, $module, $pane);
|
||||
}
|
||||
|
||||
if ($searchString === '' && $pane->hasComponents()) {
|
||||
$pane->removeComponents();
|
||||
if ($searchString === '' && $pane->hasDashlets()) {
|
||||
$pane->removeDashlets();
|
||||
$pane->add('Ready to search', 'search/hint');
|
||||
return;
|
||||
}
|
||||
@ -91,7 +91,7 @@ class SearchDashboard extends Dashboard
|
||||
if (! empty($searchUrls)) {
|
||||
$this->searchUrls[] = $module->getSearchUrls();
|
||||
foreach ($searchUrls as $search) {
|
||||
$pane->addComponent(
|
||||
$pane->addDashlet(
|
||||
$search->title . ': ' . $searchString,
|
||||
Url::fromPath($search->url, array('q' => $searchString))
|
||||
);
|
||||
|
@ -26,7 +26,7 @@ class DashboardAction implements Tabextension
|
||||
array(
|
||||
'icon' => 'dashboard',
|
||||
'title' => 'Add To Dashboard',
|
||||
'url' => Url::fromPath('dashboard/new-component'),
|
||||
'url' => Url::fromPath('dashboard/new-dashlet'),
|
||||
'urlParams' => array(
|
||||
'url' => rawurlencode(Url::fromRequest()->getRelativeUrl())
|
||||
)
|
||||
|
@ -24,7 +24,7 @@ class DashboardSettings implements Tabextension
|
||||
array(
|
||||
'icon' => 'img/icons/dashboard.png',
|
||||
'title' => t('Add To Dashboard'),
|
||||
'url' => Url::fromPath('dashboard/new-component')
|
||||
'url' => Url::fromPath('dashboard/new-dashboard')
|
||||
)
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user